ESyS-Particle  4.0.1
gettype.hpp
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 //=== PAIR ====
14 template<typename T1,typename T2>
15 MPI_Datatype SGetType::operator()(const pair<T1,T2>& P)
16 {
18  MPI_Aint addr_first,addr_second;
19  MPI_Aint disp[2];
20  MPI_Datatype type[2];
21  int blocklen[2]={1,1};
22 
23  MPI_Address((void*)&P.first,&addr_first);
24  MPI_Address((void*)&P.second,&addr_second);
25  disp[0]=MPI_Aint(0);
26  disp[1]=addr_second-addr_first;
27  type[0]=GetType(P.first);
28  type[1]=GetType(P.second);
29  MPI_Type_struct(2,blocklen,disp,type,&tml_pair<T1,T2>::type);
30  MPI_Type_commit(&tml_pair<T1,T2>::type);
32  }
33  return tml_pair<T1,T2>::type;
34 }
35 
36 // === TRIPLET===
37 template<typename T1, typename T2, typename T3>
38 MPI_Datatype SGetType::operator()(const esys::lsm::triplet<T1,T2,T3> &PP)
39 {
42  MPI_Aint addr[3];
43  MPI_Aint disp[3];
44  MPI_Datatype type[3];
45  int blocklen[3]={1,1,1};
46 
47  MPI_Address(static_cast<void *>(&(P.template get<0>())), &(addr[0]));
48  MPI_Address(static_cast<void *>(&(P.template get<1>())), &(addr[1]));
49  MPI_Address(static_cast<void *>(&(P.template get<2>())), &(addr[2]));
50  disp[0]=MPI_Aint(0);
51  disp[1]=addr[1]-addr[0];
52  disp[2]=addr[2]-addr[0];
53  type[0]=GetType(P.template get<0>());
54  type[1]=GetType(P.template get<1>());
55  type[2]=GetType(P.template get<2>());
56  MPI_Type_struct(3,blocklen,disp,type,&tml_trip<T1,T2,T3>::type);
57  MPI_Type_commit(&tml_trip<T1,T2,T3>::type);
59  }
61 }
62 
63 //=== QUAD ===
64 template<typename T1, typename T2, typename T3, typename T4>
65 MPI_Datatype SGetType::operator()(const esys::lsm::quadtuple<T1,T2,T3,T4> &PP)
66 {
69  MPI_Aint addr[4];
70  MPI_Aint disp[4];
71  MPI_Datatype type[4];
72  int blocklen[4]={1,1,1,1};
73 
74  MPI_Address(static_cast<void *>(&(P.template get<0>())), &(addr[0]));
75  MPI_Address(static_cast<void *>(&(P.template get<1>())), &(addr[1]));
76  MPI_Address(static_cast<void *>(&(P.template get<2>())), &(addr[2]));
77  MPI_Address(static_cast<void *>(&(P.template get<3>())), &(addr[3]));
78  disp[0]=MPI_Aint(0);
79  disp[1]=addr[1]-addr[0];
80  disp[2]=addr[2]-addr[0];
81  disp[3]=addr[3]-addr[0];
82  type[0]=GetType(P.template get<0>());
83  type[1]=GetType(P.template get<1>());
84  type[2]=GetType(P.template get<2>());
85  type[3]=GetType(P.template get<3>());
86  MPI_Type_struct(4,blocklen,disp,type,&tml_quad<T1,T2,T3,T4>::type);
87  MPI_Type_commit(&tml_quad<T1,T2,T3,T4>::type);
89  }
91 }
92 
93 //=== QUINT ===
94 template<typename T1, typename T2, typename T3, typename T4, typename T5>
95 MPI_Datatype SGetType::operator()(const esys::lsm::quintuple<T1,T2,T3,T4,T5> &PP)
96 {
99  MPI_Aint addr[5];
100  MPI_Aint disp[5];
101  MPI_Datatype type[5];
102  int blocklen[5]={1,1,1,1,1};
103 
104  MPI_Address(static_cast<void *>(&(P.template get<0>())), &(addr[0]));
105  MPI_Address(static_cast<void *>(&(P.template get<1>())), &(addr[1]));
106  MPI_Address(static_cast<void *>(&(P.template get<2>())), &(addr[2]));
107  MPI_Address(static_cast<void *>(&(P.template get<3>())), &(addr[3]));
108  MPI_Address(static_cast<void *>(&(P.template get<4>())), &(addr[4]));
109  disp[0]=MPI_Aint(0);
110  disp[1]=addr[1]-addr[0];
111  disp[2]=addr[2]-addr[0];
112  disp[3]=addr[3]-addr[0];
113  disp[4]=addr[4]-addr[0];
114  type[0]=GetType(P.template get<0>());
115  type[1]=GetType(P.template get<1>());
116  type[2]=GetType(P.template get<2>());
117  type[3]=GetType(P.template get<3>());
118  type[4]=GetType(P.template get<4>());
119  MPI_Type_struct(5,blocklen,disp,type,&tml_quin<T1,T2,T3,T4,T5>::type);
120  MPI_Type_commit(&tml_quin<T1,T2,T3,T4,T5>::type);
122  }
124 }