PLUTO
al_szptr_.c File Reference

Miscellaneous of internal routines to convert sz pointers to integer pointers. More...

#include "al_hidden.h"
Include dependency graph for al_szptr_.c:

Go to the source code of this file.

Functions

int AL_Init_stack_ ()
 
int AL_Allocate_sz_ ()
 
int AL_Deallocate_sz_ (int sz_ptr)
 
int AL_Valid_ptr (int sz_ptr)
 

Variables

SZsz_stack [AL_MAX_ARRAYS]
 
int stack_ptr [AL_MAX_ARRAYS]
 
static int stack_top
 
static int stack_used
 

Detailed Description

Miscellaneous of internal routines to convert sz pointers to integer pointers.

Author
A. Malagoli (University of Chicago)
Date
Jul 17, 1999

Definition in file al_szptr_.c.

Function Documentation

int AL_Allocate_sz_ ( )

Return an integer pointer to an SZ stack entry.

Definition at line 58 of file al_szptr_.c.

62 {
63  register int i;
64  int sz_ptr; /* The returned pointer to the SZ array */
65 
66  sz_ptr = -1;
67 
68  /*
69  First, search the stack for the first
70  available pointer
71  */
72  for( i=0; i<AL_MAX_ARRAYS; i++){
73  if( stack_ptr[i] == AL_STACK_FREE ){
74  sz_ptr = i;
76  break;
77  }
78  }
79 
80  /*
81  If the allocation did not fail, then proceed to
82  allocate a SZ structure
83  */
84  if( sz_ptr != -1 ){
85  if( !(sz_stack[i] = (SZ *)malloc(sizeof(SZ))) ){
86  printf("AL_Allocate_sz_: Failed to allocate SZ\n");
87  }
88  }
89 
90  /*
91  If we were successful, then set sz.compiled to AL_FALSE,
92  indicating the need for intialization.
93  */
94  sz_stack[sz_ptr]->compiled = AL_FALSE;
95 
96  return sz_ptr;
97 
98 }
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26
#define AL_STACK_FREE
Definition: al_codes.h:24
#define AL_STACK_USED
Definition: al_codes.h:25
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
int i
Definition: analysis.c:2
#define AL_FALSE
Definition: al_codes.h:29
Definition: al_hidden.h:38
int compiled
Definition: al_hidden.h:39
#define AL_MAX_ARRAYS
Definition: al_codes.h:21

Here is the caller graph for this function:

int AL_Deallocate_sz_ ( int  sz_ptr)

Deallocate an integer pointer to an SZ stack entry.

Parameters
[in]sz_ptrInteger pointer to an entry in the SZ stack

Definition at line 102 of file al_szptr_.c.

108 {
109  register int i;
110  int ndim;
111  SZ *s;
112 
113  if(sz_ptr<0) return AL_SUCCESS;
114  if(stack_ptr[sz_ptr] == AL_STACK_FREE) return AL_SUCCESS;
115 
116  s = sz_stack[sz_ptr];
117  ndim = s->ndim;
118 
119  /*
120  Free the MPI data types
121  */
122  if( s->compiled == AL_TRUE ){
123  for( i=0; i<ndim; i++){
124  MPI_Type_free(&(s->strided[i]));
125  MPI_Type_free(&(s->type_lr[i]));
126  MPI_Type_free(&(s->type_rl[i]));
127  MPI_Comm_free(&(s->oned_comm[i]));
128  }
129 
130  MPI_Type_free(&(s->gsubarr));
131  MPI_Type_free(&(s->lsubarr));
132  MPI_Comm_free(&(s->cart_comm));
133  }
134 
135  if( (s->begs != NULL) ) free(s->begs);
136 
137  /*
138  Begin by dellocating the SZ structure
139  */
140  free(sz_stack[sz_ptr]);
141 
142  /*
143  Now we can reset the integer pointer
144  */
145  stack_ptr[sz_ptr] = AL_STACK_FREE;
146  return (int) AL_SUCCESS;
147 }
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26
#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 * begs
Definition: al_hidden.h:63
MPI_Datatype gsubarr
Definition: al_hidden.h:110
MPI_Comm oned_comm[AL_MAX_DIM]
Definition: al_hidden.h:50
MPI_Comm cart_comm
Definition: al_hidden.h:49
MPI_Datatype type_rl[AL_MAX_DIM]
Definition: al_hidden.h:106
MPI_Datatype lsubarr
Definition: al_hidden.h:111
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
MPI_Datatype strided[AL_MAX_DIM]
Definition: al_hidden.h:97
#define s
int i
Definition: analysis.c:2
Definition: al_hidden.h:38
int compiled
Definition: al_hidden.h:39
MPI_Datatype type_lr[AL_MAX_DIM]
Definition: al_hidden.h:104
int ndim
Definition: al_hidden.h:43

Here is the caller graph for this function:

int AL_Init_stack_ ( )

Initialize the stack of SZ pointers This routine is called internally by AL_Init.

Definition at line 33 of file al_szptr_.c.

38 {
39  register int i;
40  int myrank;
41 
42  stack_top = 0;
43  stack_used = 0;
44 
45  for( i=0; i<AL_MAX_ARRAYS;i++){ stack_ptr[i] = AL_STACK_FREE ;}
46 
47  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
48 
49 #ifdef DEBUG
50  printf("AL_Init_stack_: SZ stack initialized\n");
51 #endif
52 
53  return 0;
54 }
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26
#define AL_STACK_FREE
Definition: al_codes.h:24
static int stack_used
Definition: al_szptr_.c:30
static int stack_top
Definition: al_szptr_.c:29
int i
Definition: analysis.c:2
#define AL_MAX_ARRAYS
Definition: al_codes.h:21

Here is the caller graph for this function:

int AL_Valid_ptr ( int  sz_ptr)

Return AL_TRUE if the input pointer points to an allocated distributed array. Return AL_FALSE otherwise.

Parameters
[in]sz_ptrInteger pointer to an entry in the SZ stack

Definition at line 150 of file al_szptr_.c.

158 {
159  if(stack_ptr[sz_ptr]!=AL_STACK_USED ) return AL_FALSE;
160  return sz_stack[sz_ptr]->compiled;
161 }
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26
#define AL_STACK_USED
Definition: al_codes.h:25
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
#define AL_FALSE
Definition: al_codes.h:29
int compiled
Definition: al_hidden.h:39

Variable Documentation

int stack_ptr[AL_MAX_ARRAYS]

Definition at line 26 of file al_szptr_.c.

int stack_top
static

Definition at line 29 of file al_szptr_.c.

int stack_used
static

Definition at line 30 of file al_szptr_.c.

SZ* sz_stack[AL_MAX_ARRAYS]

Definition at line 18 of file al_szptr_.c.