00001
00002
00003
00004
00012 #ifndef __TEMPLATE_MPITYPE_H__
00013 #define __TEMPLATE_MPITYPE_H__
00014 #include <utility>
00015
00016 template<class A>
00017 class template_mpitype {
00018 public:
00019 static const MPI_Datatype type() { return A::mpitype; }
00020 };
00021
00022 template<>
00023 class template_mpitype<char> {
00024 public:
00025 static const MPI_Datatype type() { return MPI_CHAR; }
00026 };
00027
00028 template<>
00029 class template_mpitype<short> {
00030 public:
00031 static const MPI_Datatype type( ) { return MPI_SHORT; }
00032 };
00033
00034 template<>
00035 class template_mpitype<int> {
00036 public:
00037 static const MPI_Datatype type() { return MPI_INT; }
00038 };
00039
00040 template<>
00041 class template_mpitype<float> {
00042 public:
00043 static const MPI_Datatype type() { return MPI_FLOAT; }
00044 };
00045
00046 template<>
00047 class template_mpitype<double> {
00048 public:
00049 static const MPI_Datatype type() { return MPI_DOUBLE; }
00050 };
00051
00052 template<>
00053 class template_mpitype<unsigned int> {
00054 public:
00055 static const MPI_Datatype type() { return MPI_UNSIGNED; }
00056 };
00057
00058 template<typename A, typename B>
00059 class template_mpitype< std::pair<A, B> > {
00060 public:
00061 static const MPI_Datatype type()
00062 {
00063 std::pair<A, B> temp;
00064 int blength_list[2] = {1, 1};
00065 MPI_Datatype datatype_list[2] = {template_mpitype<A>::type(),
00066 template_mpitype<B>::type()};
00067 MPI_Aint displacement_list[2];
00068 MPI_Aint start_address, address;
00069 MPI_Address(&temp, &start_address);
00070
00071 MPI_Address(&temp.first, &address);
00072 displacement_list[0] = address - start_address;
00073
00074 MPI_Address(&temp.second, &address);
00075 displacement_list[1] = address - start_address;
00076
00077 MPI_Datatype newtype;
00078 MPI_Type_struct(2, blength_list, displacement_list,
00079 datatype_list, &newtype);
00080 MPI_Type_commit(&newtype);
00081
00082 return newtype;
00083 }
00084 };
00085
00086 #endif // __TEMPLATE_MPITYPE_H__