]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/ParaMEDMEM/Test/test_MPI_Access_Probe.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / ParaMEDMEM / Test / test_MPI_Access_Probe.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include <string>
20 #include <vector>
21 #include <map>
22 #include <iostream>
23 #include <mpi.h>
24
25 #include "MPIAccessTest.hxx"
26 #include <cppunit/TestAssert.h>
27
28 //#include "CommInterface.hxx"
29 //#include "ProcessorGroup.hxx"
30 //#include "MPIProcessorGroup.hxx"
31 #include "MPIAccess.hxx"
32
33 // use this define to enable lines, execution of which leads to Segmentation Fault
34 #define ENABLE_FAULTS
35
36 // use this define to enable CPPUNIT asserts and fails, showing bugs
37 #define ENABLE_FORCED_FAILURES
38
39 using namespace std;
40 using namespace ParaMEDMEM;
41
42 void MPIAccessTest::test_MPI_Access_Probe() {
43
44   cout << "test_MPI_Access_Probe" << endl ;
45
46 //  MPI_Init(&argc, &argv) ; 
47
48   int size ;
49   int myrank ;
50   MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51   MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
52
53   if ( size < 2 ) {
54     cout << "test_MPI_Access_Probe must be runned with 2 procs" << endl ;
55     CPPUNIT_FAIL("test_MPI_Access_Probe must be runned with 2 procs") ;
56   }
57
58   cout << "test_MPI_Access_Probe" << myrank << endl ;
59
60   ParaMEDMEM::CommInterface interface ;
61
62   ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
63
64   ParaMEDMEM::MPIAccess mpi_access( group ) ;
65
66   if ( myrank >= 2 ) {
67     mpi_access.barrier() ;
68     delete group ;
69     return ;
70   }
71
72   int target = 1 - myrank ;
73   int RequestId[10] ;
74   int sts ;
75   int i ;
76   for ( i = 0 ; i < 10 ; i++ ) {
77      if ( myrank == 0 ) {
78        sts = mpi_access.send(&i,1,MPI_INT,target, RequestId[i]) ;
79        cout << "test" << myrank << " Send RequestId " << RequestId[i]
80             << endl ;
81      }
82      else {
83        int source, tag, outcount ;
84        MPI_Datatype datatype ;
85        sts = mpi_access.probe(target, source, tag, datatype, outcount ) ;
86        cout << "test" << myrank << " Probe target " << target << " source " << source
87             << " tag " << tag << " outcount " << outcount << endl ;
88        int recvbuf ;
89        sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
90                              &outcount) ;
91        if ( (outcount != 1) | (recvbuf != i) ) {
92          ostringstream strstream ;
93          strstream << "==========================================================="
94                    << "test" << myrank << " outcount " << outcount
95                    << " recvbuf " << recvbuf << " KO"
96                    << "==========================================================="
97                    << endl ;
98          cout << strstream.str() << endl ;
99          CPPUNIT_FAIL( strstream.str() ) ;
100        }
101      }
102      char msgerr[MPI_MAX_ERROR_STRING] ;
103      int lenerr ;
104      mpi_access.errorString(sts, msgerr, &lenerr) ;
105      cout << "test" << myrank << " lenerr " << lenerr << " "
106           << msgerr << endl ;
107
108      if ( sts != MPI_SUCCESS ) {
109        ostringstream strstream ;
110        strstream << "==========================================================="
111                  << "test" << myrank << " KO"
112                  << "==========================================================="
113                  << endl ;
114        cout << strstream.str() << endl ;
115        CPPUNIT_FAIL( strstream.str() ) ;
116      }
117      mpi_access.check() ;
118   }
119   int flag ;
120   mpi_access.testAll(10,RequestId,flag) ;
121   if ( !flag ) {
122     ostringstream strstream ;
123     strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
124     cout << strstream.str() << endl ;
125     CPPUNIT_FAIL( strstream.str() ) ;
126   }
127   mpi_access.waitAll(10,RequestId) ;
128   mpi_access.check() ;
129
130   mpi_access.barrier() ;
131
132   delete group ;
133
134 //  MPI_Finalize();
135
136   cout << "test" << myrank << " OK" << endl ;
137
138   return ;
139 }
140
141
142
143