PLUTO
al_sz_set.c
Go to the documentation of this file.
1 /* //////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Miscellaneous functions to define the properties of the
5  distributed array by setting various parameters via the
6  isz descriptor
7 
8  \author A. Malagoli (University of Chicago)
9  \date Jul 17, 1999
10 */
11 /* //////////////////////////////////////////////////////////////////// */
12 #include "al_hidden.h" /*I "al_hidden.h" I*/
13 
14 /*
15  The SZ structure stack is defined and maintained
16  in al_szptr_.c
17  Here we include an external reference to it in
18  order to be able to make internal references to it.
19 */
20 extern SZ *sz_stack[AL_MAX_ARRAYS];
21 extern int stack_ptr[AL_MAX_ARRAYS];
22 
23 /* ********************************************************************* */
24 int AL_Set_comm(MPI_Comm comm, int isz)
25 /*!
26  * Set the communicator for a distributed array
27  *
28  * \param [in] comm MPI communicator the array is associated with
29  * \param [out] isz Integer pointer to the input array descriptor
30  *
31  * \return AL_SUCCESS if the communicator is set correctly,
32  * AL_FAILURE otherwise.
33  *********************************************************************** */
34 {
35  int myrank, nproc;
36  SZ *s;
37 
38  /*
39  Check that isz points to an allocated SZ
40  */
41  if( stack_ptr[isz] == AL_STACK_FREE ){
42  printf("AL_Set_comm: wrong SZ pointer\n");
43  return (int) AL_FAILURE;
44  }
45 
46  /*
47  Get the SZ structure isz is pointing at
48  */
49  s = sz_stack[isz];
50 
51  MPI_Comm_rank(comm, &myrank);
52  MPI_Comm_size(comm, &nproc);
53 
54  s->comm = comm;
55  s->size = nproc;
56  /*
57  Patch for the case in which this node does not
58  belong to this communicator
59  */
60  if( nproc > 0 ) {
61  s->rank = myrank;
62  } else { s->rank = MPI_UNDEFINED; }
63 
64  return (int) AL_SUCCESS;
65 }
66 
67 
68 /* ********************************************************************* */
69 int AL_Set_dimensions(int ndim, int isz)
70 /*!
71  * Set the dimensions of a distributed array
72  *
73  * \param [in] ndim Number of dimensions (1 to 5)
74  * \param [out] isz Integer pointer to the input array descriptor
75  *
76  * \return AL_SUCCESS if the dimensions are set correctly,
77  * AL_FAILURE otherwise.
78  *********************************************************************** */
79 {
80  SZ *s;
81 
82  /*
83  Check that isz points to an allocated SZ
84  */
85  if( stack_ptr[isz] == AL_STACK_FREE ){
86  printf("AL_Set_dimensions: wrong SZ pointer\n");
87  return (int) AL_FAILURE;
88  }
89 
90  /*
91  Get the SZ structure isz is pointing at
92  */
93  s = sz_stack[isz];
94 
95  s->ndim = ndim;
96 
97  return (int) AL_SUCCESS;
98 }
99 
100 /* ********************************************************************* */
101 int AL_Set_type(AL_Datatype type, int nelem, int isz)
102 /*!
103  * Set the basic data type of a distributed array. The data types are identical to the MPI datatypes, and they can be defined as AL_<type> or MPI_<type> (e.g. AL_FLOAT or MPI_FLOAT).
104  *
105  * \param [in] type Datatype (AL_Datatype or MPI_Datatype)
106  * \param [in] nelem Number of type 'type' elements in array elements
107  * \param [out] isz Integer pointer to the input array descriptor
108  *
109  * \return AL_SUCCESS if the type is set correctly,
110  * AL_FAILURE otherwise.
111  *********************************************************************** */
112 {
113  SZ *s;
114  AL_Datatype ivector;
115 
116  /*
117  Check that isz points to an allocated SZ
118  */
119  if( stack_ptr[isz] == AL_STACK_FREE ){
120  printf("AL_Set_type: wrong SZ pointer\n");
121  return (int) AL_FAILURE;
122  }
123 
124  /*
125  Get the SZ structure isz is pointing at
126  */
127  s = sz_stack[isz];
128 
129  if( nelem <= 1 ){
130  s->type = type;
131  } else {
132  MPI_Type_contiguous( nelem, type, &ivector);
133  MPI_Type_commit(&ivector);
134  s->type = ivector;
135  }
136 
137  return (int) AL_SUCCESS;
138 }
139 
140 /* ********************************************************************* */
141 int AL_Set_global_dim(int *gdims, int isz)
142 /*!
143  * Set the global dimensions of a distributed array
144  *
145  * \param [in] gdims Array of integers with global dimensions
146  * \param [out] isz Integer pointer to the input array descriptor
147  *
148  * \return AL_SUCCESS if the global dimension are set correctly,
149  * AL_FAILURE otherwise.
150  *********************************************************************** */
151 {
152  register int i;
153  int ndim;
154 
155  SZ *s;
156 
157  /*
158  Check that isz points to an allocated SZ
159  */
160  if( stack_ptr[isz] == AL_STACK_FREE ){
161  printf("AL_Set_global_dim: wrong SZ pointer\n");
162  return (int) AL_FAILURE;
163  }
164 
165  /*
166  Get the SZ structure isz is pointing at
167  */
168  s = sz_stack[isz];
169 
170  ndim = s->ndim;
171  for(i=0;i<ndim;i++){ s->arrdim[i] = gdims[i] ;}
172 
173  return (int) AL_SUCCESS;
174 }
175 
176 /* ********************************************************************* */
177 int AL_Set_local_dim(int *ldims, int isz)
178 /*!
179  * Set the local dimensions of a distributed array
180  *
181  * \param [in] ldims Array of integers with local dimensions
182  * \param [out] isz Integer pointer to the input array descriptor
183  *
184  * \return AL_SUCCESS if the local dimension are set correctly,
185  * AL_FAILURE otherwise.
186  *********************************************************************** */
187 {
188  register int i;
189  int ndim;
190  SZ *s;
191 
192  /*
193  Check that isz points to an allocated SZ
194  */
195  if( stack_ptr[isz] == AL_STACK_FREE ){
196  printf("AL_Set_local_dim: wrong SZ pointer\n");
197  return (int) AL_FAILURE;
198  }
199 
200  /*
201  Get the SZ structure isz is pointing at
202  */
203  s = sz_stack[isz];
204 
205  ndim = s->ndim;
206  for(i=0;i<ndim;i++){
207  s->larrdim[i] = ldims[i];
208  s->lbeg[i] = 0;
209  s->lend[i] = ldims[i]-1;
210  }
211 
212  return (int) AL_SUCCESS;
213 }
214 
215 /* ********************************************************************* */
216 int AL_Set_parallel_dim(int *pardims, int isz)
217 /*!
218  * Set the parallel dimensions of a distributed array
219  *
220  * \param [in] pardims Array of integers with parallel dimensions [AL_TRUE|AL_FALSE]
221  * \param [out] isz Integer pointer to the input array descriptor
222  *
223  * \return AL_SUCCESS if the parallel dimension are set correctly,
224  * AL_FAILURE otherwise.
225  *********************************************************************** */
226 {
227  register int i;
228  int ndim;
229  SZ *s;
230 
231  /*
232  Check that isz points to an allocated SZ
233  */
234  if( stack_ptr[isz] == AL_STACK_FREE ){
235  printf("AL_Set_parallel_dim: wrong SZ pointer\n");
236  return (int) AL_FAILURE;
237  }
238 
239  /*
240  Get the SZ structure isz is pointing at
241  */
242  s = sz_stack[isz];
243 
244  ndim = s->ndim;
245  for(i=0;i<ndim;i++){
246  s->isparallel[i] = pardims[i];
247  }
248 
249  return (int) AL_SUCCESS;
250 }
251 
252 /* ********************************************************************* */
253 int AL_Set_periodic_dim(int *periods, int isz)
254 /*!
255  * Set the periodic dimensions of a distributed array
256  *
257  * \param [in] periods Array of integers with periodic dimensions [AL_TRUE|AL_FALSE]
258  * \param [out] isz Integer pointer to the input array descriptor
259  *
260  * \return AL_SUCCESS if the periodic dimension are set correctly,
261  * AL_FAILURE otherwise.
262  *********************************************************************** */
263 {
264  register int i;
265  int ndim;
266  SZ *s;
267 
268  /*
269  Check that isz points to an allocated SZ
270  */
271  if( stack_ptr[isz] == AL_STACK_FREE ){
272  printf("AL_Set_periodic_dim: wrong SZ pointer\n");
273  return (int) AL_FAILURE;
274  }
275 
276  /*
277  Get the SZ structure isz is pointing at
278  */
279  s = sz_stack[isz];
280 
281  ndim = s->ndim;
282  for(i=0;i<ndim;i++){
283  if( periods[i] != AL_TRUE && periods[i] != AL_FALSE ){
284  printf("Warning: periods has illegal values in AL_Set_periodic_dim\n");
285  }
286  s->isperiodic[i] = periods[i];
287  }
288 
289  return (int) AL_SUCCESS;
290 }
291 
292 /* ********************************************************************* */
293 int AL_Set_staggered_dim(int *stagger, int isz)
294 /*!
295  * Set the staggered dimensions of a distributed array
296  *
297  * \param [in] stagger Array of integers with staggered dimensions [AL_TRUE|AL_FALSE]
298  * \param [out] isz Integer pointer to the input array descriptor
299  *
300  * \return AL_SUCCESS if the staggered dimension are set correctly,
301  * AL_FAILURE otherwise.
302  *********************************************************************** */
303 {
304  register int i;
305  int ndim;
306  SZ *s;
307 
308  /*
309  Check that isz points to an allocated SZ
310  */
311  if( stack_ptr[isz] == AL_STACK_FREE ){
312  printf("AL_Set_staggered_dim: wrong SZ pointer\n");
313  return (int) AL_FAILURE;
314  }
315 
316  /*
317  Get the SZ structure isz is pointing at
318  */
319  s = sz_stack[isz];
320 
321  ndim = s->ndim;
322  for(i=0;i<ndim;i++){
323  if( stagger[i] != AL_TRUE && stagger[i] != AL_FALSE ){
324  printf("Warning: stagger has illegal values in AL_Set_staggered_dim\n");
325  }
326  s->isstaggered[i] = stagger[i];
327  }
328 
329  return (int) AL_SUCCESS;
330 }
331 
332 /* ********************************************************************* */
333 int AL_Set_ghosts(int *ghosts, int isz)
334 /*!
335  * Set the ghost points of a distributed array
336  *
337  * \param [in] ghost Array of integers with size of ghost points
338  in each dimension
339  * \param [out] isz Integer pointer to the input array descriptor
340  *
341  * \return AL_SUCCESS if the ghost points are set correctly,
342  * AL_FAILURE otherwise.
343  *********************************************************************** */
344 {
345  register int i;
346  int ndim;
347  SZ *s;
348 
349  /*
350  Check that isz points to an allocated SZ
351  */
352  if( stack_ptr[isz] == AL_STACK_FREE ){
353  printf("AL_Set_ghosts: wrong SZ pointer\n");
354  return (int) AL_FAILURE;
355  }
356 
357  /*
358  Get the SZ structure isz is pointing at
359  */
360  s = sz_stack[isz];
361 
362  ndim = s->ndim;
363  for(i=0;i<ndim;i++){
364  s->bg[i] = ghosts[i];
365  s->eg[i] = ghosts[i];
366  }
367 
368  return (int) AL_SUCCESS;
369 }
370 
int isperiodic[AL_MAX_DIM]
Definition: al_hidden.h:80
int AL_Set_dimensions(int ndim, int isz)
Definition: al_sz_set.c:69
int isparallel[AL_MAX_DIM]
Definition: al_hidden.h:78
#define AL_Datatype
Definition: al_defs.h:22
int AL_Set_parallel_dim(int *pardims, int isz)
Definition: al_sz_set.c:216
int AL_Set_staggered_dim(int *stagger, int isz)
Definition: al_sz_set.c:293
#define AL_SUCCESS
Definition: al_codes.h:32
#define AL_TRUE
Definition: al_codes.h:28
#define AL_STACK_FREE
Definition: al_codes.h:24
int arrdim[AL_MAX_DIM]
Definition: al_hidden.h:53
int AL_Set_type(AL_Datatype type, int nelem, int isz)
Definition: al_sz_set.c:101
int AL_Set_ghosts(int *ghosts, int isz)
Definition: al_sz_set.c:333
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26
int larrdim[AL_MAX_DIM]
Definition: al_hidden.h:54
int AL_Set_comm(MPI_Comm comm, int isz)
Definition: al_sz_set.c:24
int rank
Definition: al_hidden.h:44
int bg[AL_MAX_DIM]
Definition: al_hidden.h:72
int isstaggered[AL_MAX_DIM]
Definition: al_hidden.h:82
int eg[AL_MAX_DIM]
Definition: al_hidden.h:74
int AL_Set_periodic_dim(int *periods, int isz)
Definition: al_sz_set.c:253
#define AL_FAILURE
Definition: al_codes.h:33
#define s
int size
Definition: al_hidden.h:45
int i
Definition: analysis.c:2
MPI_Comm comm
Definition: al_hidden.h:47
MPI_Datatype type
Definition: al_hidden.h:40
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
#define AL_FALSE
Definition: al_codes.h:29
int AL_Set_local_dim(int *ldims, int isz)
Definition: al_sz_set.c:177
Definition: al_hidden.h:38
Internal include file for the ArrayLib.
int lbeg[AL_MAX_DIM]
Definition: al_hidden.h:68
#define AL_MAX_ARRAYS
Definition: al_codes.h:21
int AL_Set_global_dim(int *gdims, int isz)
Definition: al_sz_set.c:141
int lend[AL_MAX_DIM]
Definition: al_hidden.h:70
int ndim
Definition: al_hidden.h:43