COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
datatype.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #ifndef cf3_common_PE_datatype_hpp
8 #define cf3_common_PE_datatype_hpp
9 
11 
12 #include <mpi.h>
13 
14 #include <boost/type_traits/is_pod.hpp>
15 
16 #include "common/PE/types.hpp"
17 // #include "common/PE/debug.hpp" // for debugging mpi
18 
20 
33 
35 namespace cf3 {
36  namespace common {
37  namespace PE {
38 
40 
42 namespace detail {
43 template <typename T> inline Datatype get_mpi_datatype_impl(const T& ) { return nullptr; };
44 } // namespace detail
45 
47 
49 template <typename T> inline Datatype get_mpi_datatype(const T& ref_of_type)
50 {
51  if (detail::get_mpi_datatype_impl(ref_of_type)!=nullptr) return detail::get_mpi_datatype_impl<T>(ref_of_type);
52  static Datatype type(nullptr);
53  if (type==nullptr){
54  //PEProcessSortedExecute(-1,CFinfo << "Registering type of size " << sizeof(T) << CFendl;);
55  //if (!boost::is_pod<T>::value) throw NotSupported(FromHere(),"Non-POD (plain old datatype) is not supported by parallel environment communications.");
56  MPI_CHECK_RESULT(MPI_Type_contiguous,(sizeof(T), MPI_BYTE, &type));
57  MPI_CHECK_RESULT(MPI_Type_commit,(&type));
58  }
59  return type;
60 }
61 
62 template <typename T> inline Datatype get_mpi_datatype()
63 {
64  static Datatype type(nullptr);
65  if (type==nullptr){
66  //PEProcessSortedExecute(-1,CFinfo << "Registering type of size " << sizeof(T) << CFendl;);
67  //if (!boost::is_pod<T>::value) throw NotSupported(FromHere(),"Non-POD (plain old datatype) is not supported by parallel environment communications.");
68  MPI_CHECK_RESULT(MPI_Type_contiguous,(sizeof(T), MPI_BYTE, &type));
69  MPI_CHECK_RESULT(MPI_Type_commit,(&type));
70  }
71  return type;
72 }
73 
75 
77 
79 namespace detail {
80  template<> inline Datatype get_mpi_datatype_impl <char> (const char& ) { return MPI_CHAR; };
81  template<> inline Datatype get_mpi_datatype_impl <unsigned char> (const unsigned char& ) { return MPI_UNSIGNED_CHAR; };
82  template<> inline Datatype get_mpi_datatype_impl <short> (const short& ) { return MPI_SHORT; };
83  template<> inline Datatype get_mpi_datatype_impl <unsigned short> (const unsigned short& ) { return MPI_UNSIGNED_SHORT; };
84  template<> inline Datatype get_mpi_datatype_impl <int> (const int& ) { return MPI_INT; };
85  template<> inline Datatype get_mpi_datatype_impl <unsigned int> (const unsigned int& ) { return MPI_UNSIGNED; }; // there is no MPI_UNSIGNED_INT
86  template<> inline Datatype get_mpi_datatype_impl <long> (const long& ) { return MPI_LONG; };
87  template<> inline Datatype get_mpi_datatype_impl <unsigned long> (const unsigned long& ) { return MPI_UNSIGNED_LONG; };
88  template<> inline Datatype get_mpi_datatype_impl <long long> (const long long& ) { return MPI_LONG_LONG; };
89  template<> inline Datatype get_mpi_datatype_impl <unsigned long long> (const unsigned long long& ) { return MPI_UNSIGNED_LONG_LONG; };
90  template<> inline Datatype get_mpi_datatype_impl <float> (const float&) { return MPI_FLOAT; };
91  template<> inline Datatype get_mpi_datatype_impl <double> (const double& ) { return MPI_DOUBLE; };
92  template<> inline Datatype get_mpi_datatype_impl <long double> (const long double& ) { return MPI_LONG_DOUBLE; };
93 } // namespace detail
94 
95 
97 
99 
100  } // namespace PE
101  } // namespace common
102 } // namespace cf3
103 
105 
106 #endif // cf3_common_PE_datatype_hpp
Datatype get_mpi_datatype_impl< unsigned long >(const unsigned long &)
Definition: datatype.hpp:87
Datatype get_mpi_datatype_impl< unsigned short >(const unsigned short &)
Definition: datatype.hpp:83
MPI_Datatype Datatype
datatype
Definition: types.hpp:47
Datatype get_mpi_datatype(const T &ref_of_type)
ACCESS AND REGISTRATION MECHANISM.
Definition: datatype.hpp:49
Datatype get_mpi_datatype_impl< unsigned int >(const unsigned int &)
Definition: datatype.hpp:85
Datatype get_mpi_datatype_impl< char >(const char &)
Definition: datatype.hpp:80
Datatype get_mpi_datatype_impl< int >(const int &)
Definition: datatype.hpp:84
Datatype get_mpi_datatype_impl< float >(const float &)
Definition: datatype.hpp:90
Datatype get_mpi_datatype_impl< long long >(const long long &)
Definition: datatype.hpp:88
Datatype get_mpi_datatype_impl(const T &)
Definition: datatype.hpp:43
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Datatype get_mpi_datatype_impl< long double >(const long double &)
Definition: datatype.hpp:92
Datatype get_mpi_datatype_impl< long >(const long &)
Definition: datatype.hpp:86
Datatype get_mpi_datatype_impl< unsigned char >(const unsigned char &)
Definition: datatype.hpp:81
#define MPI_CHECK_RESULT(MPIFunc, Args)
Macro for checking return values of any mpi calls and throws exception on error.
Definition: types.hpp:20
Datatype get_mpi_datatype_impl< short >(const short &)
Definition: datatype.hpp:82
Datatype get_mpi_datatype_impl< unsigned long long >(const unsigned long long &)
Definition: datatype.hpp:89
Datatype get_mpi_datatype_impl< double >(const double &)
Definition: datatype.hpp:91
Send comments to:
COOLFluiD Web Admin