Actual source code: example2.edp
 1 /*******************************************************
 2  *  This file is part of the FreeFEM tutorial made by  *
 3  *      Pierre Jolivet <pierre@joliv.et>               *
 4  *                                                     *
 5  *  See https://joliv.et/FreeFem-tutorial for more     *
 6  *                                                     *
 7  *   Description: basic usage of MPI in a script       *
 8  *******************************************************/
  
10 assert(mpisize > 2);
 
12 for(int i = 0; i < mpisize; ++i) {
13     mpiBarrier(mpiCommWorld);
14     if(i == mpirank)
15         cout << mpirank << "/" << mpisize << endl;
16     mpiBarrier(mpiCommWorld);
17 }
 
19 mesh Th;
20 if(mpiRank(mpiCommWorld) == 1) {
21     Th = square(10, 10);
22 }
23 broadcast(processor(1), Th);
24 if(mpirank == 0)
25     plot(Th, wait = 1);
26 int myInt = mpirank + 1;
27 int reducedInt;
28 mpiAllReduce(myInt, reducedInt, mpiCommWorld, mpiSUM);
29 assert(reducedInt == ((mpisize + 1) * mpisize) / 2);
 
31 mpiRequest rq;
32 if(mpirank == 0)
33     Isend(processor(2, rq), Th);
34 else if(mpirank == 2)
35     Irecv(processor(0, rq), Th);
 
37 if(mpirank != 1)
38     mpiWait(rq);
39 mpiBarrier(mpiCommWorld);
40 if(mpirank == 2)
41     cout << Th.nt << endl;