/[escript]/branches/split/esysUtils/src/Esys_MPI.cpp
ViewVC logotype

Diff of /branches/split/esysUtils/src/Esys_MPI.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4746 by jfenwick, Thu Mar 13 06:23:15 2014 UTC revision 4747 by jfenwick, Thu Mar 13 22:52:45 2014 UTC
# Line 28  Line 28 
28    
29  #include <iostream> // temp for debugging  #include <iostream> // temp for debugging
30    
31    namespace esysUtils
32    {
33    JMPI makeInfo(MPI_Comm comm, bool owncom)
34    {
35        JMPI_* p=new JMPI_(comm, owncom);
36        return JMPI(p);
37    }
38    
39    
40    JMPI_::JMPI_(MPI_Comm mpicomm, bool owncom)
41        : comm(mpicomm), ownscomm(owncom)
42    {
43        msg_tag_counter = 0;
44    #ifdef ESYS_MPI
45        if (MPI_Comm_rank(comm, &rank)!=MPI_SUCCESS || MPI_Comm_size(comm, &size)!=MPI_SUCCESS)
46        {
47            Esys_setError( ESYS_MPI_ERROR, "Esys_MPIInfo_alloc : error finding comm rank/size" );
48        }
49    #else
50        rank=0;
51        size=1;
52    #endif  
53    }
54    
55    JMPI_::~JMPI_()
56    {
57    #ifdef ESYS_MPI
58        MPI_Comm_free(&comm);
59    #endif
60    }
61    
62    
63    }
64    
65    
66  /* allocate memory for an mpi_comm, and find the communicator details */  /* allocate memory for an mpi_comm, and find the communicator details */
67  Esys_MPIInfo* Esys_MPIInfo_alloc( MPI_Comm comm )  Esys_MPIInfo* Esys_MPIInfo_alloc( MPI_Comm comm )
# Line 142  bool Esys_MPIInfo_noError( Esys_MPIInfo Line 176  bool Esys_MPIInfo_noError( Esys_MPIInfo
176  }  }
177    
178  /* returns the max of inputs on all ranks -- or just sends the input back on nompi */  /* returns the max of inputs on all ranks -- or just sends the input back on nompi */
 bool esysUtils::checkResult(int& input, int& output, Esys_MPIInfo *mpi_info)  
 {  
 #ifdef ESYS_MPI  
     output=0;  
     if (MPI_Allreduce(&input, &output, 1, MPI_INT, MPI_MAX, mpi_info->comm)!=MPI_SUCCESS)  
     {  
     return false;  
     }  
     return true;  
 #else  
     output=input;  
     return true;  
 #endif  
 }  
   
 /* returns the max of inputs on all ranks -- or just sends the input back on nompi */  
179  bool esysUtils::checkResult(int& input, int& output, MPI_Comm& comm)  bool esysUtils::checkResult(int& input, int& output, MPI_Comm& comm)
180  {  {
181  #ifdef ESYS_MPI  #ifdef ESYS_MPI
# Line 196  bool esysUtils::shipString(const char* s Line 214  bool esysUtils::shipString(const char* s
214      // send -1      // send -1
215      int in=(slen?rank:-1);      int in=(slen?rank:-1);
216      int out;      int out;
 std::cerr << "My input is " << in << std::endl;      
217      if (MPI_Allreduce(&in, &out, 1, MPI_INT, MPI_MAX, comm)!=MPI_SUCCESS)      if (MPI_Allreduce(&in, &out, 1, MPI_INT, MPI_MAX, comm)!=MPI_SUCCESS)
218      {      {
219      return false;      return false;
220      }      }
 std::cerr << "My ouput is " << out << std::endl;      
221      if (out==-1)        // should not be called under these conditions, but noone had a string      if (out==-1)        // should not be called under these conditions, but noone had a string
222      {      {
223      *dest=new char[1];      *dest=new char[1];
# Line 215  std::cerr << "My ouput is " << out << st Line 231  std::cerr << "My ouput is " << out << st
231      {      {
232      return false;      return false;
233      }      }
 std::cerr << "slen=" << slen << " out=" << out << std::endl;      
234      // now broadcast that string to everyone      // now broadcast that string to everyone
235      if (rank==out)      if (rank==out)
236      {      {
# Line 229  std::cerr << "slen=" << slen << " out=" Line 244  std::cerr << "slen=" << slen << " out="
244      {      {
245          return false;          return false;
246      }      }
 std::cerr << "Post send [" << *dest << ']' << std::endl;      
247      return true;      return true;
248      }      }
249      else      else
# Line 239  std::cerr << "Post send [" << *dest << ' Line 253  std::cerr << "Post send [" << *dest << '
253      {      {
254          return false;          return false;
255      }      }
 std::cerr << "Post recv [" << *dest << ']' << std::endl;      
256      return true;      return true;
257      }      }
258  #else  #else

Legend:
Removed from v.4746  
changed lines
  Added in v.4747

  ViewVC Help
Powered by ViewVC 1.1.26