[1759] | 1 | #include "mpi.hpp" |
---|
[2576] | 2 | #include "backtrace.hpp" |
---|
| 3 | #include "exception.hpp" |
---|
| 4 | #include "log.hpp" |
---|
[1759] | 5 | #include <string> |
---|
[2576] | 6 | #include <sstream> |
---|
[1759] | 7 | |
---|
| 8 | namespace xios |
---|
| 9 | { |
---|
[2576] | 10 | std::map<MPI_Comm,string> CCommTrack::commTrack_ ; |
---|
| 11 | void CCommTrack::registerComm(const MPI_Comm& comm) |
---|
| 12 | { |
---|
[2578] | 13 | if (comm!=MPI_COMM_NULL) |
---|
| 14 | { |
---|
| 15 | auto it = commTrack_.find(comm) ; |
---|
[2593] | 16 | if (it == commTrack_.end()) commTrack_[comm] = MemCppTrack::backTrace(3); |
---|
[2578] | 17 | else ERROR("CCommtrack::registerComm", << "Communicator already allocated : " << endl<<it->second) |
---|
| 18 | } |
---|
[2576] | 19 | } |
---|
| 20 | |
---|
| 21 | void CCommTrack::releaseComm(const MPI_Comm& comm) |
---|
| 22 | { |
---|
| 23 | auto it = commTrack_.find(comm) ; |
---|
[2584] | 24 | //if (it == commTrack_.end()) info(100)<<"WARNING : CCommtrack::releaseComm => Communicator not allocated !" << endl ; |
---|
| 25 | if (it == commTrack_.end()) { ERROR("void CCommTrack::releaseComm(const MPI_Comm& comm)",<<"Communicator not allocated !" << endl) ; } |
---|
[2576] | 26 | else commTrack_.erase(it) ; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void CCommTrack::dumpComm(void) |
---|
| 30 | { |
---|
| 31 | ostringstream ostr ; |
---|
| 32 | ostr<<" LIST of UNFREED MPI COMMUNICATORS"<<endl ; |
---|
| 33 | for(auto& it : commTrack_ ) |
---|
| 34 | { |
---|
| 35 | ostr<<"---------------------------"<<endl ; |
---|
| 36 | ostr<<" -- unfreed communicator --"<<endl ; |
---|
| 37 | ostr<<" -- backtrace --"<<endl ; |
---|
| 38 | ostr<<it.second<<endl ; |
---|
| 39 | } |
---|
| 40 | info(100)<<ostr.str() ; |
---|
| 41 | } |
---|
| 42 | |
---|
[1759] | 43 | int MPI_Bcast_string(std::string& str, int root, MPI_Comm comm) |
---|
| 44 | { |
---|
| 45 | int commRank ; |
---|
| 46 | int ret ; |
---|
| 47 | MPI_Comm_rank(comm,&commRank) ; |
---|
| 48 | int strSize ; |
---|
| 49 | if (commRank==root) strSize=str.size() ; |
---|
| 50 | MPI_Bcast(&strSize,1,MPI_INT,root,comm) ; |
---|
| 51 | |
---|
| 52 | if (commRank==root) ret=MPI_Bcast((char*)str.data(), strSize, MPI_CHAR, root, comm) ; |
---|
| 53 | else |
---|
| 54 | { |
---|
| 55 | char* tmp=new char[strSize] ; |
---|
| 56 | ret=MPI_Bcast(tmp, strSize, MPI_CHAR, root, comm) ; |
---|
| 57 | str=std::string(tmp,strSize) ; |
---|
| 58 | delete [] tmp ; |
---|
| 59 | } |
---|
| 60 | return ret ; |
---|
| 61 | } |
---|
[1984] | 62 | |
---|
[2118] | 63 | template<> |
---|
[2507] | 64 | MPI_Datatype MPI_GetType<bool>(void) { return MPI_CXX_BOOL ;} |
---|
| 65 | |
---|
| 66 | template<> |
---|
[2118] | 67 | MPI_Datatype MPI_GetType<char>(void) { return MPI_CHAR ;} |
---|
| 68 | |
---|
| 69 | template<> |
---|
| 70 | MPI_Datatype MPI_GetType<short int>(void) { return MPI_SHORT ;} |
---|
| 71 | |
---|
| 72 | template<> |
---|
| 73 | MPI_Datatype MPI_GetType<int>(void) { return MPI_INT ;} |
---|
| 74 | |
---|
| 75 | template<> |
---|
| 76 | MPI_Datatype MPI_GetType<size_t>(void) { return MPI_SIZE_T ;} |
---|
| 77 | |
---|
| 78 | template<> |
---|
| 79 | MPI_Datatype MPI_GetType<float>(void) { return MPI_FLOAT ;} |
---|
| 80 | |
---|
| 81 | template<> |
---|
| 82 | MPI_Datatype MPI_GetType<double>(void) { return MPI_DOUBLE ;} |
---|
| 83 | |
---|
| 84 | template<> |
---|
| 85 | MPI_Datatype MPI_GetType<long double>(void) { return MPI_LONG_DOUBLE ;} |
---|
| 86 | |
---|
| 87 | } |
---|