title: writing to text file in MPI
body: <p>I'm trying to write to text file with MPI but the file is not created.
  I need only to write at the master (rank = 0), but nothing works.
  It only working when I running the program in console (and save corrupt element)  and not in Mpich2 and
  I attached the code.
  Thanks for helping.</p>
  
  <pre><code>  /* -*- Mode: C; c-basic-offset:4 ; -*- */
  /*
   *  (C) 2001 by Argonne National Laboratory.
   *      See COPYRIGHT in top-level directory.
   */
  
  /* This is an interactive version of cpi */
  #include &lt;mpi.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  int main(int argc,char *argv[])
  {
  
      int  namelen, numprocs, rank;
      char processor_name[MPI_MAX_PROCESSOR_NAME];
      MPI_Init(&amp;argc,&amp;argv);
      MPI_Comm_rank(MPI_COMM_WORLD,&amp;rank);
      MPI_Comm_size(MPI_COMM_WORLD,&amp;numprocs);    
      MPI_Get_processor_name(processor_name,&amp;namelen);
      MPI_Status status;
      FILE* f = fopen("test.txt","wb+");
  
      if (rank == 0) {
          for (int i=0; i &lt; 5; i++){
              fprintf(f,"%d \n",i);
          }
          fclose(f);
      }
      else {
          // do nothing
      }
  
  
      MPI_Finalize();
      return 0;
  }
  </code></pre>