File output error using MPI
<p>I have an MPI program running on the Xeon Phi Coprocessor with the MPIICC compiler.  </p>

<p>My code runs fine until I finalize MPI and try to print my results to a file. </p>

<hr>

<p>I'll start by describing the finalization: </p>

<pre><code>MPI_Win_free(&amp;win);
MPI_Finalize();


// After finalizing, all print statements in this area of 
// the code print for all MPI nodes (even though they have 
// been finalized)
printf("testing\n");

return 0;
}
</code></pre>

<p>The final <code>printf</code> statement prints for all MPI nodes, even though they have been finalized.  </p>

<hr>

<p>So, ok, strange behavior--I don't care.  I put an if statement such that the results only print if the rank is equal to 0: </p>

<pre><code>if (rank == 0) {...}
</code></pre>

<p>This works, even after finalization.  Next, I change my print statements over to file write statements: </p>

<pre><code>...
MPI_Finalize();

if (rank == 0){
    FILE *file = fopen("output.txt","w"); 
    fclose(file);
}

return 0;

}
</code></pre>

<p>And I get a segmentation fault.  I cannot figure out what is going on.  I have looked around, tried everything... not really sure what is happening, or even what could be going wrong.  I should have all the requisite permissions. </p>

<hr>

<p>An added note: if I do not close the file, I don't get a segmentation fault (or print to it). </p>

<p>This seems to fail generally.</p>