Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is nothing wrong with MPI_Barrier().</p> <p>As <a href="https://stackoverflow.com/questions/5182045/openmpi-mpi-barrier-problems/5183614#5183614">Jens mentioned</a>, the reason why you are not seeing the output you expected is because stdout is buffered on each processes. There is no guarantee that prints from multiple processes will be displayed on the calling process in order. (If stdout from each process is be transferred to the main process for printing in real time, that will lead to lots of unnecessary communication!)</p> <p>If you want to convince yourself that the barrier works, you could try writing to a file instead. Having multiple processes writing to a single file may lead to extra complications, so you could have each proc writing to one file, then after the barrier, swap the files they write to. For example:</p> <pre><code> Proc-0 Proc-1 | | f0.write(..) f1.write(...) | | x ~~ barrier ~~ x | | f1.write(..) f0.write(...) | | END END </code></pre> <p>Sample implementation:</p> <pre><code>#include "mpi.h" #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(int argc, char **argv) { char filename[20]; int rank, size; FILE *fp; MPI_Init(&amp;argc, &amp;argv); MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank); MPI_Comm_size(MPI_COMM_WORLD, &amp;size); if (rank &lt; 2) { /* proc 0 and 1 only */ sprintf(filename, "file_%d.out", rank); fp = fopen(filename, "w"); fprintf(fp, "P%d: before Barrier\n", rank); fclose(fp); } MPI_Barrier(MPI_COMM_WORLD); if (rank &lt; 2) { /* proc 0 and 1 only */ sprintf(filename, "file_%d.out", (rank==0)?1:0 ); fp = fopen(filename, "a"); fprintf(fp, "P%d: after Barrier\n", rank); fclose(fp); } MPI_Finalize(); return 0; } </code></pre> <p>After running the code, you should get the following results:</p> <pre><code>[me@home]$ cat file_0.out P0: before Barrier P1: after Barrier [me@home]$ cat file_1.out P1: before Barrier P0: after Barrier </code></pre> <p>For all files, the "after Barrier" statements will always appear later.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload