PLUTO
al_alloc.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief ArrayLib allocation routine
5 
6  ArrayLib allocation routine
7 
8  \authors A. Malagoli (University of Chicago)
9 
10  \date Jul 17, 1999
11 */
12 /* ///////////////////////////////////////////////////////////////////// */
13 #include "al_hidden.h" /*I "al_hidden.h" I*/
14 
15 /*
16  The SZ structure stack is defined and maintained
17  in al_szptr_.c
18  Here we include an external reference to it in
19  order to be able to make internal references to it.
20 */
21 extern SZ *sz_stack[AL_MAX_ARRAYS];
22 extern int stack_ptr[AL_MAX_ARRAYS];
23 
24 /* ********************************************************************* */
25 void *AL_Allocate_array(int sz_ptr)
26 /*!
27  * Allocate the local buffer for a distributed array
28  *
29  * \param [in] sz_ptr pointer to SZ array (integer)
30  *********************************************************************** */
31 {
32  char *a;
33  int myrank, nproc;
34  int size;
35  long int buffsize;
36  MPI_Comm comm;
37  SZ *s;
38 
39 
40 
41  /* DIAGNOSTICS
42  Check that sz_ptr points to an allocated SZ
43  */
44  if( stack_ptr[sz_ptr] == AL_STACK_FREE){
45  printf("AL_Allocate_array: wrong SZ pointer\n");
46  }
47 
48  s = sz_stack[sz_ptr];
49 
50  myrank = s->rank;
51  nproc = s->size;
52  comm = s->comm;
53 
54  buffsize = s->buffsize;
55 
56  MPI_Type_size(s->type, &size);
57 
58  if( !(a = (char *)AL_CALLOC_((int) buffsize,size)) ){
59  printf("[%d] AL_Allocate_array: allocation error\n",myrank);
60  return 0;
61  }
62 
63  /* DIAGNOSTICS */
64 #ifdef DEBUG
65  printf("AL_Allocate_array: allocated %ld bytes\n",buffsize*size);
66 #endif
67 
68  return (void *)a;
69 }
70 
71 
static double a
Definition: init.c:135
#define AL_CALLOC_(nelem, size)
Definition: al_defs.h:34
#define AL_STACK_FREE
Definition: al_codes.h:24
int rank
Definition: al_hidden.h:44
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26
#define s
int size
Definition: al_hidden.h:45
MPI_Comm comm
Definition: al_hidden.h:47
long int buffsize
Definition: al_hidden.h:52
MPI_Datatype type
Definition: al_hidden.h:40
void * AL_Allocate_array(int sz_ptr)
Definition: al_alloc.c:25
Definition: al_hidden.h:38
Internal include file for the ArrayLib.
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
#define AL_MAX_ARRAYS
Definition: al_codes.h:21