AdjoinableMPI
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nt.c
Go to the documentation of this file.
1 /*
2 ##########################################################
3 # This file is part of the AdjoinableMPI library #
4 # released under the MIT License. #
5 # The full COPYRIGHT notice can be found in the top #
6 # level directory of the AdjoinableMPI distribution. #
7 ##########################################################
8 */
9 #include <mpi.h>
10 #include "ampi/userIF/nt.h"
11 #include "ampi/adTool/support.h"
12 #include <assert.h>
13 
15 
16 int AMPI_Finalize_NT(void) {
20  return MPI_Finalize();
21 }
22 
23 int AMPI_Buffer_attach_NT(void *buffer,
24  int size) {
25  return MPI_Buffer_attach(buffer,
26  size);
27 
28 }
29 
30 int AMPI_Buffer_detach_NT(void *buffer,
31  int *size){
32  return MPI_Buffer_detach(buffer,
33  size);
34 }
35 
37  MPI_Datatype oldtype,
38  MPI_Datatype* newtype) {
39  int rc;
40  rc = MPI_Type_contiguous (count,
41  oldtype,
42  newtype);
43  assert(rc==MPI_SUCCESS);
44  MPI_Datatype type, temp_packed_type, packed_type;
45  MPI_Aint array_of_displacements[1] = {(MPI_Aint)0};
46  int s=0, is_active, dt_idx;
47  MPI_Aint p_mapsize, extent, lb;
49  dt_idx = derivedTypeIdx(oldtype);
51  if (is_active) {
52  type = MPI_DOUBLE;
53  s = sizeof(double);
54  }
55  else if (isDerivedType(dt_idx)) {
56  type = dtd->packed_types[dt_idx];
57  s = dtd->p_extents[dt_idx];
58  }
59  else {
60  type = oldtype;
61  if (oldtype==MPI_DOUBLE) s = sizeof(double);
62  else if (oldtype==MPI_INT) s = sizeof(int);
63  else if (oldtype==MPI_FLOAT) s = sizeof(float);
64  else if (oldtype==MPI_CHAR) s = sizeof(char);
65  else assert(0);
66  }
67  p_mapsize = count*s;
68  MPI_Type_get_extent(*newtype,&lb,&extent);
69  rc = MPI_Type_contiguous (count,
70  type,
71  &temp_packed_type);
72  assert(rc==MPI_SUCCESS);
73  rc = MPI_Type_create_resized (temp_packed_type,
74  0,
75  (MPI_Aint)p_mapsize,
76  &packed_type);
77  addDTypeData(dtd,
78  1,
79  &count,
80  array_of_displacements,
81  &oldtype,
82  lb,
83  extent,
84  &count,
85  array_of_displacements,
86  &type,
87  p_mapsize,
88  newtype,
89  &packed_type);
90  return rc;
91 }
92 
94  int array_of_blocklengths[],
95  MPI_Aint array_of_displacements[],
96  MPI_Datatype array_of_types[],
97  MPI_Datatype *newtype) {
98  int i, rc;
99  rc = MPI_Type_create_struct (count,
100  array_of_blocklengths,
101  array_of_displacements,
102  array_of_types,
103  newtype);
104  assert(rc==MPI_SUCCESS);
105  MPI_Datatype temp_packed_type, packed_type;
106  int array_of_p_blocklengths[count];
107  MPI_Aint array_of_p_displacements[count];
108  MPI_Datatype array_of_p_types[count], datatype;
109  int s=0, is_active, is_derived, dt_idx;
110  MPI_Aint p_mapsize=0, extent, lb;
111  derivedTypeData* dat = getDTypeData();
112  for (i=0;i<count;i++) {
113  datatype = array_of_types[i];
114  is_active = (*ourADTOOL_AMPI_FPCollection.isActiveType_fp)(datatype)==AMPI_ACTIVE;
115  dt_idx = derivedTypeIdx(datatype);
116  is_derived = isDerivedType(dt_idx);
117  array_of_p_blocklengths[i] = array_of_blocklengths[i];
118  array_of_p_displacements[i] = p_mapsize;
119  if (is_active) {
120  array_of_p_types[i] = MPI_DOUBLE;
121  s = sizeof(double);
122  }
123  else if (is_derived) {
124  array_of_p_types[i] = dat->packed_types[dt_idx];
125  s = dat->p_extents[dt_idx];
126  }
127  else {
128  array_of_p_types[i] = array_of_types[i];
129  if (array_of_types[i]==MPI_DOUBLE) s = sizeof(double);
130  else if (array_of_types[i]==MPI_INT) s = sizeof(int);
131  else if (array_of_types[i]==MPI_FLOAT) s = sizeof(float);
132  else if (array_of_types[i]==MPI_CHAR) s = sizeof(char);
133  else assert(0);
134  }
135  p_mapsize += array_of_blocklengths[i]*s;
136  }
137  MPI_Type_get_extent(*newtype,&lb,&extent);
138  rc = MPI_Type_create_struct (count,
139  array_of_p_blocklengths,
140  array_of_p_displacements,
141  array_of_p_types,
142  &temp_packed_type);
143  assert(rc==MPI_SUCCESS);
144  rc = MPI_Type_create_resized (temp_packed_type,
145  0,
146  (MPI_Aint)p_mapsize,
147  &packed_type);
148  addDTypeData(dat,
149  count,
150  array_of_blocklengths,
151  array_of_displacements,
152  array_of_types,
153  lb,
154  extent,
155  array_of_p_blocklengths,
156  array_of_p_displacements,
157  array_of_p_types,
158  p_mapsize,
159  newtype,
160  &packed_type);
161  MPI_Type_free(&temp_packed_type);
162  return rc;
163 }
164 
165 int AMPI_Type_commit_NT(MPI_Datatype *datatype) {
166  int dt_idx = derivedTypeIdx(*datatype);
167  if (isDerivedType(dt_idx)) MPI_Type_commit(&(getDTypeData()->packed_types[dt_idx]));
168  return MPI_Type_commit(datatype);
169 }
170 
171 int AMPI_Type_create_resized_NT(MPI_Datatype oldtype,
172  MPI_Aint lb,
173  MPI_Aint extent,
174  MPI_Datatype *newtype) {
175  int rc;
176  rc = MPI_Type_create_resized(oldtype,
177  lb,
178  extent,
179  newtype);
180  int dt_idx = derivedTypeIdx(oldtype);
181  if (isDerivedType(dt_idx)) {
182  derivedTypeData* dtd = getDTypeData();
183  dtd->lbs[dt_idx] = lb;
184  dtd->extents[dt_idx] = extent;
185  dtd->derived_types[dt_idx] = *newtype;
186  }
187  return rc;
188 }
189 
190 int AMPI_Op_create_NT(MPI_User_function *function,
191  int commute,
192  MPI_Op *op) {
193  int rc;
194  rc = MPI_Op_create(function,
195  commute,
196  op);
197  if (!(rc==MPI_SUCCESS)) assert(0);
198  userDefinedOpData* dat = getUOpData();
199  addUOpData(dat,
200  op,
201  function,
202  commute);
203  return rc;
204 }
205 
206 int AMPI_Type_free_NT(MPI_Datatype *datatype) {
207  int dt_idx = derivedTypeIdx(*datatype);
208  if (isDerivedType(dt_idx)) MPI_Type_free(&(getDTypeData()->packed_types[dt_idx]));
209  return MPI_Type_free(datatype);
210 }
211 
212 int AMPI_Op_free_NT(MPI_Op *op) {
213  return MPI_Op_free(op);
214 }