source: XIOS/dev/dev_ym/XIOS_COUPLING/src/mpi_tools.cpp @ 2230

Last change on this file since 2230 was 2118, checked in by jderouillat, 3 years ago

Enable GNU compilation

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#include "mpi.hpp"
2#include "mpi_tools.hpp"
3
4
5#include <string>
6
7namespace 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
29  template<>
30  MPI_Datatype MPI_GetType<char>(void) { return MPI_CHAR ;}
31
32  template<>
33  MPI_Datatype MPI_GetType<short int>(void) { return MPI_SHORT ;}
34
35  template<>
36  MPI_Datatype MPI_GetType<int>(void) { return MPI_INT ;}
37
38  template<>
39  MPI_Datatype MPI_GetType<size_t>(void) { return MPI_SIZE_T ;}
40
41  template<>
42  MPI_Datatype MPI_GetType<float>(void) { return MPI_FLOAT ;}
43
44  template<>
45  MPI_Datatype MPI_GetType<double>(void) { return MPI_DOUBLE ;}
46
47  template<>
48  MPI_Datatype MPI_GetType<long double>(void) { return MPI_LONG_DOUBLE ;}
49
50}
Note: See TracBrowser for help on using the repository browser.