Last change
on this file since 2142 was
1759,
checked in by ymipsl, 5 years ago
|
Add some tools for MPI communication
- find MPI_SIZE_T type equivalent to size_t integer
- Add MPI_Bcast for string
YM
|
-
Property svn:eol-style set to
native
-
Property svn:executable set to
*
|
File size:
622 bytes
|
Rev | Line | |
---|
[1759] | 1 | #include "mpi.hpp" |
---|
| 2 | #include "mpi_tools.hpp" |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | #include <string> |
---|
| 6 | |
---|
| 7 | namespace xios |
---|
| 8 | { |
---|
| 9 | int MPI_Bcast_string(std::string& str, int root, MPI_Comm comm) |
---|
| 10 | { |
---|
| 11 | int commRank ; |
---|
| 12 | int ret ; |
---|
| 13 | MPI_Comm_rank(comm,&commRank) ; |
---|
| 14 | int strSize ; |
---|
| 15 | if (commRank==root) strSize=str.size() ; |
---|
| 16 | MPI_Bcast(&strSize,1,MPI_INT,root,comm) ; |
---|
| 17 | |
---|
| 18 | if (commRank==root) ret=MPI_Bcast((char*)str.data(), strSize, MPI_CHAR, root, comm) ; |
---|
| 19 | else |
---|
| 20 | { |
---|
| 21 | char* tmp=new char[strSize] ; |
---|
| 22 | ret=MPI_Bcast(tmp, strSize, MPI_CHAR, root, comm) ; |
---|
| 23 | str=std::string(tmp,strSize) ; |
---|
| 24 | delete [] tmp ; |
---|
| 25 | } |
---|
| 26 | return ret ; |
---|
| 27 | } |
---|
| 28 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.