//NBPROC 4 load "msh3" include "test.idp" if (!mpirank) cout << functionDEFINITION << "Isend and I recv" << endl; real t; cout << "MPI rank = " << mpirank << endl; if( mpirank==0) { cout << typeDEFINITION << "int" << endl; t = mpiWtime(); processor(1) << 123456; t = mpiWtime() - t; cout << timeELAPSED << t << endl; } else if (mpirank==1) { int k; processor(0) >> k; test(k == 123456); } { mpiRequest rq; if (mpirank == 0) { cout << typeDEFINITION << "real" << endl; t = mpiWtime() - t; Isend(processor(1,rq),16.); mpiWait(rq); t = mpiWtime() - t; cout << timeELAPSED << t << endl; } else if (mpirank == 1) { real k; t = mpiWtime() - t; Irecv(processor(0,rq),k); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(k == 16); } } { matrix A; mpiRequest rq; if (mpirank == 0) { cout << typeDEFINITION << "matrix" << endl; A = [[1, 2], [3, 4]]; t = mpiWtime(); Isend(processor(1, rq), A); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { matrix k; t = mpiWtime(); Irecv(processor(0,rq), k); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(k(0, 0) == 1); test(k(0, 1) == 2); test(k(1, 0) == 3); test(k(1, 1) == 4); } } complex toSendComplex; mpiRequest rq; if (mpirank == 0) { cout << typeDEFINITION << "complex" << endl; toSendComplex = 4 + 2i; t = mpiWtime(); Isend(processor(1, rq), toSendComplex); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendComplex); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(toSendComplex == 4 + 2i); } int[int] toSendArrayInt(3); if (mpirank == 0) { cout << typeDEFINITION << "int[int]" << endl; toSendArrayInt = [1, 2, 3]; t = mpiWtime(); Isend(processor(1, rq), toSendArrayInt); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendArrayInt); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(toSendArrayInt[0] == 1); test(toSendArrayInt[1] == 2); test(toSendArrayInt[2] == 3);} real[int] toSendArrayRealInt(3); if (mpirank == 0) { cout << typeDEFINITION << "real[int]" << endl; toSendArrayRealInt = [4.2, 4.3, 4.4]; t = mpiWtime(); Isend(processor(1, rq), toSendArrayRealInt); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendArrayRealInt); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(toSendArrayRealInt[0] == 4.2); test(toSendArrayRealInt[1] == 4.3); test(toSendArrayRealInt[2] == 4.4); } complex[int] toSendArrayComplexInt(3); if (mpirank == 0) { cout << typeDEFINITION << "complex[int]" << endl; toSendArrayComplexInt = [4 + 2i, 4 + 3i, 4 + 4i]; t = mpiWtime(); Isend(processor(1, rq), toSendArrayComplexInt); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendArrayComplexInt); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(toSendArrayComplexInt[0] == 4 + 2i); test(toSendArrayComplexInt[1] == 4 + 3i); test(toSendArrayComplexInt[2] == 4 + 4i); } mesh toSendMesh; if (mpirank == 0) { cout << typeDEFINITION << "mesh" << endl; toSendMesh = square(5, 5); t = mpiWtime(); Isend(processor(1, rq), toSendMesh); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendMesh); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); mesh Th = square(5, 5); test(toSendMesh.nv == Th.nv); } mesh3 toSendMesh3; if (mpirank == 0) { cout << typeDEFINITION << "mesh3" << endl; toSendMesh3 = cube(5, 5, 5); t = mpiWtime(); Isend(processor(1, rq), toSendMesh3); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendMesh3); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); mesh3 Th3 = cube(5, 5, 5); test(toSendMesh3.nv == Th3.nv); } matrix A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; matrix toSendMatrix; if (mpirank == 0) { cout << typeDEFINITION << "matrix" << endl; toSendMatrix = A; t = mpiWtime(); Isend(processor(1, rq), toSendMatrix); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); } else if (mpirank == 1) { t = mpiWtime(); Irecv(processor(0, rq), toSendMatrix); t = mpiWtime() - t; cout << timeELAPSED << t << endl; mpiWait(rq); test(toSendMatrix(0, 0) == A(0, 0)); test(toSendMatrix(0, 1) == A(0, 1)); test(toSendMatrix(0, 2) == A(0, 2)); test(toSendMatrix(1, 0) == A(1, 0)); test(toSendMatrix(1, 1) == A(1, 1)); test(toSendMatrix(1, 2) == A(1, 2)); test(toSendMatrix(2, 0) == A(2, 0)); test(toSendMatrix(2, 1) == A(2, 1)); test(toSendMatrix(2, 2) == A(2, 2)); }