MPICommHandle.h

Go to the documentation of this file.
00001 #ifndef MPICOMMHANDLE_H_
00002 #define MPICOMMHANDLE_H_
00003 
00004 #include "mpi.h"
00005 
00006 #include <vector>
00007 
00008 using std::vector;
00009 
00010  class MPICommHandle {
00011 public:
00012 
00013         MPICommHandle()
00014         {
00015                 comm =  MPI::COMM_WORLD;
00016         }
00017 
00018     MPICommHandle(MPICommHandle & base_comm, const vector<unsigned> &ranks)
00019         {
00020                 MPI::Group grp = base_comm.comm.Get_group();
00021                 int * rank_arr = new int[ranks.size()];
00022                 for (int i = 0; i < (int)ranks.size(); ++i)
00023                         rank_arr[i] = (int)ranks[i];             
00024                 MPI::Group subgrp = grp.Incl(ranks.size(), rank_arr);
00025                 comm = base_comm.comm.Create(subgrp);           
00026                 delete [] rank_arr;
00027         }       
00028         
00029         int mpi_rank()
00030         {
00031                 return comm.Get_rank(); 
00032         }
00033         
00034         int mpi_size() 
00035         {
00036                 return comm.Get_size();
00037         }
00038         
00039         static MPICommHandle WORLD;
00040         
00041         
00042 protected:
00043         MPI::Intracomm & getComm()
00044         {
00045                 return comm;    
00046         }                                                               
00047 
00048         MPI::Intracomm comm;
00049 };
00050 
00051 
00052 
00053 #endif /*MPICOMMHANDLE_H_*/

Generated on Wed Jul 9 16:34:37 2008 for PCSIM by  doxygen 1.5.5