aboutsummaryrefslogtreecommitdiff
path: root/src/SetupPGV.c
diff options
context:
space:
mode:
authortradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2000-06-14 16:46:53 +0000
committertradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2000-06-14 16:46:53 +0000
commit63815410954f7a8cc19bfaaf9ddc5ea3a8db2463 (patch)
treeb8b953cc09358a26d8995ca1191525d6f8ffed1b /src/SetupPGV.c
parent6bbd2b0ad4481a7c4e9b2ecc32e2efc1d755cbab (diff)
Enabled PUGH to synchronize groups of arrays in one communication call
rather than doing it sequentially on individual arrays. Nothing changes for the CCTK routines overloaded by PUGH. For BAM and other thorns which don't care about groups there is now a separate interface to synchronize individual arrays. Also eliminated the restriction to synchronize 1D and 3D arrays only - now it should do arbitrary dims (not yet tested). git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@222 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/SetupPGV.c')
-rw-r--r--src/SetupPGV.c559
1 files changed, 246 insertions, 313 deletions
diff --git a/src/SetupPGV.c b/src/SetupPGV.c
index 171aa7c..d27ace0 100644
--- a/src/SetupPGV.c
+++ b/src/SetupPGV.c
@@ -69,12 +69,12 @@ pGExtras *PUGH_SetupPGExtras(int dim,
this->dim = dim;
- PUGH_SetupPGExtrasSizes (dim, perme, stagger, sh, nghosts,
- total_procs, nprocs, this_proc,this);
+ PUGH_SetupPGExtrasSizes(dim, perme, stagger, sh, nghosts,
+ total_procs, nprocs, this_proc,this);
PUGH_SetupPGExtrasOwnership(dim, perme, stagger, sh, nghosts,
- total_procs, nprocs, this_proc, this);
+ total_procs, nprocs, this_proc, this);
PUGH_SetupPGExtrasStaggering(dim, perme, stagger, sh, nghosts,
- total_procs, nprocs, this_proc, this);
+ total_procs, nprocs, this_proc, this);
}
}
@@ -124,6 +124,8 @@ void PUGH_DestroyPGExtras(pGExtras **PGExtras)
free((*PGExtras)->nghostzones);
free((*PGExtras)->nsize);
free((*PGExtras)->lnsize);
+ free((*PGExtras)->iterator);
+ free((*PGExtras)->hyper_volume);
free(*PGExtras);
*PGExtras = NULL;
@@ -552,9 +554,11 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->rnpoints = (int *) malloc(total_procs*sizeof(int));
/* Things just depending on dimension */
- this->nghostzones = (int *)malloc(dim*sizeof(int));
- this->nsize = (int *)malloc(dim*sizeof(int));
- this->lnsize = (int *)malloc(dim*sizeof(int));
+ this->nghostzones = (int *)malloc(dim*sizeof(int));
+ this->nsize = (int *)malloc(dim*sizeof(int));
+ this->lnsize = (int *)malloc(dim*sizeof(int));
+ this->iterator = (int *)malloc(dim*sizeof(int));
+ this->hyper_volume = (int *)malloc(dim*sizeof(int));
/* Check all the above succeeded and then get memory for
* arrays hanging off the above.
@@ -565,7 +569,9 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->rnpoints &&
this->nghostzones &&
this->nsize &&
- this->lnsize)
+ this->lnsize &&
+ this->iterator &&
+ this->hyper_volume)
{
this->lb[0] = (int *)malloc(total_procs *dim*sizeof(int));
this->ub[0] = (int *)malloc(total_procs *dim*sizeof(int));
@@ -607,6 +613,10 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->nsize = NULL;
free(this->lnsize);
this->lnsize = NULL;
+ free(this->iterator);
+ this->iterator = NULL;
+ free(this->hyper_volume);
+ this->hyper_volume = NULL;
}
}
else
@@ -626,6 +636,10 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->nsize = NULL;
free(this->lnsize);
this->lnsize = NULL;
+ free(this->iterator);
+ this->iterator = NULL;
+ free(this->hyper_volume);
+ this->hyper_volume = NULL;
}
@@ -635,7 +649,9 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->rnpoints &&
this->nghostzones &&
this->nsize &&
- this->lnsize)
+ this->lnsize &&
+ this->iterator &&
+ this->hyper_volume)
{
retcode = 0;
for (i = 0 ; i < PUGH_NSTAGGER; i++)
@@ -735,6 +751,10 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->nsize = NULL;
free(this->lnsize);
this->lnsize = NULL;
+ free(this->iterator);
+ this->iterator = NULL;
+ free(this->hyper_volume);
+ this->hyper_volume = NULL;
}
}
}
@@ -853,14 +873,14 @@ int PUGH_SetupPGExtrasSizes(int dim,
@@*/
int PUGH_SetupPGExtrasOwnership(int dim,
- int *perme,
- int stagger,
- int *sh,
- int *nghosts,
- int total_procs,
- int *nprocs,
- int this_proc,
- pGExtras *this)
+ int *perme,
+ int stagger,
+ int *sh,
+ int *nghosts,
+ int total_procs,
+ int *nprocs,
+ int this_proc,
+ pGExtras *this)
{
int tmp;
int dir, idir;
@@ -1180,394 +1200,307 @@ int PUGH_SetupRemoteSizes(int dim,
return 0;
}
+
/*@@
- @routine PUGH_SetupPGA
- @date Mon Nov 8 16:29:34 1999
- @author Tom Goodale
+ @routine PUGH_SetupGArrayGroupComm
+ @date Tue 06 Jun 2000
+ @author Thomas Radke
@desc
- Sets up a new pGA.
+ Sets up a communication buffer for a group of GAs.
@enddesc
@calls
@calledby
@history
@endhistory
-
@@*/
-pGA *PUGH_SetupPGA(void *parent,
- pGExtras *extras,
- pConnectivity *connectivity,
- const char *name,
- int id,
- int varsize,
- int vtype,
- int stagger)
+pComm *PUGH_SetupGArrayGroupComm(pGH *pughGH,
+ int dim,
+ int first_var,
+ int n_vars,
+ int sync_timelevel,
+ int vartype,
+ pGExtras *extras)
{
- pGA *this;
int i;
- this = (pGA *)malloc(sizeof(pGA));
+ pComm *this;
- if(this)
- {
- this->extras = extras;
- this->connectivity = connectivity;
- this->parent = parent;
- this->varsize = varsize;
- this->vtype = vtype;
- this->stagger = stagger;
- this->id = id;
- this->storage = PUGH_NOSTORAGE;
- this->commflag = PUGH_NOCOMM;
+ this = (pComm *) malloc (sizeof (pComm));
- this->name = (char *) malloc((strlen(name)+1)*sizeof(char));
- this->buffer_sz = (int *) malloc(2*extras->dim*sizeof(int));
- this->send_buffer = (void **)malloc(2*extras->dim*sizeof(void *));
- this->recv_buffer = (void **)malloc(2*extras->dim*sizeof(void *));
- this->docomm = (int *) malloc(2*extras->dim*sizeof(int));
- this->padddata = (void *) calloc(1, varsize);
- this->data = this->padddata;
-
+ if (this)
+ {
+ this->buffer_sz = (int *) malloc (2 * dim * sizeof (int));
+ this->send_buffer = (void **) malloc (2 * dim * sizeof (void *));
+ this->recv_buffer = (void **) malloc (2 * dim * sizeof (void *));
#ifdef CCTK_MPI
- this->sreq = (MPI_Request *)malloc(2*extras->dim*sizeof(MPI_Request));
- this->rreq = (MPI_Request *)malloc(2*extras->dim*sizeof(MPI_Request));
+ this->sreq = (MPI_Request *) malloc (2 * dim * sizeof (MPI_Request));
+ this->rreq = (MPI_Request *) malloc (2 * dim * sizeof (MPI_Request));
#endif
+ this->docomm = (int *) malloc (2 * dim * sizeof (int));
- if(this->name &&
- this->buffer_sz &&
+ if(this->buffer_sz &&
this->send_buffer &&
this->recv_buffer &&
- this->docomm &&
#ifdef CCTK_MPI
this->sreq &&
this->rreq &&
#endif
- this->padddata)
+ this->docomm)
{
- strcpy(this->name, name);
+ this->commflag = PUGH_NOCOMM;
+ this->first_var = first_var;
+ this->n_vars = n_vars;
+ this->sync_timelevel = sync_timelevel;
- for(i = 0; i < 2*extras->dim; i++)
+#ifdef CCTK_MPI
+ switch (vartype)
+ {
+ case CCTK_VARIABLE_CHAR:
+ this->mpi_type = PUGH_MPI_CHAR; break;
+ case CCTK_VARIABLE_INT4:
+ this->mpi_type = PUGH_MPI_INT4; break;
+ case CCTK_VARIABLE_INT:
+ this->mpi_type = PUGH_MPI_INT; break;
+ case CCTK_VARIABLE_REAL4:
+ this->mpi_type = PUGH_MPI_REAL4; break;
+ case CCTK_VARIABLE_REAL:
+ this->mpi_type = PUGH_MPI_REAL; break;
+ case CCTK_VARIABLE_COMPLEX:
+ this->mpi_type = pughGH->PUGH_mpi_complex; break;
+
+ default:
+ CCTK_WARN (1, "Unsupported variable type for PUGH communication");
+ break;
+ }
+#endif
+
+ for (i = 0; i < 2 * dim; i++)
{
this->buffer_sz[i] = 0;
this->send_buffer[i] = NULL;
this->recv_buffer[i] = NULL;
- this->docomm[i] = 0;
#ifdef CCTK_MPI
/* Null my send and receive requests */
- this->sreq[i] = MPI_REQUEST_NULL;
- this->rreq[i] = MPI_REQUEST_NULL;
+ this->sreq[i] = MPI_REQUEST_NULL;
+ this->rreq[i] = MPI_REQUEST_NULL;
#endif
+ this->docomm[i] = PUGH_NOCOMM;
}
}
else
{
- free(this->name);
- free(this->buffer_sz);
- free(this->send_buffer);
- free(this->recv_buffer);
- free(this->docomm);
- free(this->padddata);
-
+ if (this->buffer_sz)
+ {
+ free (this->buffer_sz);
+ }
+ if (this->send_buffer)
+ {
+ free (this->send_buffer);
+ }
+ if (this->recv_buffer)
+ {
+ free (this->recv_buffer);
+ }
#ifdef CCTK_MPI
- free(this->sreq);
- free(this->rreq);
+ if (this->sreq)
+ {
+ free (this->sreq);
+ }
+ if (this->rreq)
+ {
+ free (this->rreq);
+ }
#endif
- free(this);
+ if (this->docomm)
+ {
+ free (this->docomm);
+ }
+
+ free (this);
this = NULL;
}
}
+ /* Now set the hyper_volume vector in the extras structure
+ which is used to copy the ghostzones from/to the comm buffers.
+ NOTE: Sizes are already in bytes here. hyper_volume[0] is unused.
+ */
+ if(this)
+ {
+ extras->hyper_volume[0] = CCTK_VarTypeSize(vartype);
+ for (i = 1; i < extras->dim; i++)
+ {
+ extras->hyper_volume[i] = extras->hyper_volume[i-1] * extras->lnsize[i-1];
+ }
+ }
+
return this;
}
+
/*@@
- @routine PUGH_DestroyPGA
- @date Mar 12 2000
+ @routine PUGH_SetupGArrayComm
+ @date Tue 06 Jun 2000
@author Thomas Radke
@desc
- Destroys a pGA object.
+ Sets up a communication buffer for a GA.
@enddesc
@calls
@calledby
@history
@endhistory
-
@@*/
-void PUGH_DestroyPGA(pGA **GA)
+pComm *PUGH_SetupGArrayComm(pGH *pughGH,
+ int dim,
+ int var,
+ int sync_timelevel,
+ int vartype,
+ pGExtras *extras)
{
- if(GA && *GA)
- {
- if((*GA)->storage != PUGH_NOSTORAGE)
- {
- PUGH_DisableGADataStorage(*GA);
- }
- free((*GA)->name);
- free((*GA)->buffer_sz);
- free((*GA)->send_buffer);
- free((*GA)->recv_buffer);
- free((*GA)->docomm);
- free((*GA)->padddata);
-
-#ifdef CCTK_MPI
- free((*GA)->sreq);
- free((*GA)->rreq);
-#endif
- free(*GA);
- *GA = NULL;
- }
+ return PUGH_SetupGArrayGroupComm(pughGH,
+ dim,
+ var,
+ 1,
+ sync_timelevel,
+ vartype,
+ extras);
}
-int PUGH_EnablePGAStorage(pGA *GA,
- int this_proc,
- int zero_memory,
- int padding_active,
- int padding_cacheline_bits,
- int padding_size,
- int padding_address_spacing)
+
+ /*@@
+ @routine PUGH_DestroyComm
+ @date Tue 06 Jun 2000
+ @author Thomas Radke
+ @desc
+ Destroys a communication buffer.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+void PUGH_DestroyComm(pComm **comm)
{
- int retval;
- int i;
- int dir;
- int sz;
- int ldir;
- char *temp_byte;
-#if 0
- int special_pad, cache_size;
- long start;
+ free ((*comm)->buffer_sz);
+ free ((*comm)->send_buffer);
+ free ((*comm)->recv_buffer);
+#ifdef CCTK_MPI
+ free ((*comm)->sreq);
+ free ((*comm)->rreq);
#endif
+ free ((*comm)->docomm);
+ free (*comm);
- retval = 0;
- if(GA->storage == PUGH_NOSTORAGE)
- {
- /* Allocate memory for communication buffers */
- for(i = 0; i < 2*GA->extras->dim; i++)
- {
- dir = i/2;
-
- sz = GA->extras->nghostzones[dir];
- for(ldir = 0; ldir < GA->extras->dim; ldir++)
- {
- sz *= GA->extras->lnsize[ldir];
- }
-
- sz /= GA->extras->lnsize[dir];
-
- if(GA->connectivity->neighbours[this_proc][i] >= 0)
- {
- GA->buffer_sz[i] = sz;
- GA->send_buffer[i] = malloc(sz * GA->varsize);
- GA->recv_buffer[i] = malloc(sz * GA->varsize);
-
- if(!(GA->send_buffer[i]
- && GA->recv_buffer[i]))
- {
- retval = -1;
- break;
- }
- }
- else
- {
- GA->buffer_sz[i] = 0;
- GA->send_buffer[i] = NULL;
- GA->recv_buffer[i] = NULL;
- }
- }
-
- if(retval)
- {
- for(; i >=0 ; i--)
- {
- free(GA->send_buffer[i]);
- free(GA->recv_buffer[i]);
- GA->buffer_sz[i] = 0;
- }
- }
-
- /* Now assign memory for the variable itself */
- if(!retval)
- {
- if(GA->padddata)
- {
- free(GA->padddata);
- }
+ *comm = NULL;
+}
- if(!padding_active)
- {
- /* Easy case. */
- if(zero_memory)
- {
- GA->padddata = calloc(GA->extras->npoints, GA->varsize);
- }
- else
- {
- GA->padddata = malloc(GA->extras->npoints * GA->varsize);
- }
- GA->data = GA->padddata;
- }
- else
- {
+ /*@@
+ @routine PUGH_SetupGArray
+ @date Mon Nov 8 16:29:34 1999
+ @author Tom Goodale
+ @desc
+ Sets up a new pGA.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
- /* Use the Cactus Cache alignment function */
- GA->data = Util_CacheMalloc(GA->id,
- GA->extras->npoints * GA->varsize,
- &(GA->padddata));
-
- /* Zero the memory if desired. */
- if(GA->data && zero_memory)
- {
- for(temp_byte = (char *)GA->data;
- temp_byte < ((char *)GA->data)+GA->extras->npoints * GA->varsize;
- temp_byte++)
- {
- *temp_byte = 0;
- }
- }
+@@*/
+pGA *PUGH_SetupGArray(void *parent,
+ pGExtras *extras,
+ pConnectivity *connectivity,
+ pComm *groupcomm,
+ const char *name,
+ int id,
+ int varsize,
+ int vtype,
+ int stagger)
+{
+ pGA *this;
- }
- }
- }
+ this = (pGA *)malloc(sizeof(pGA));
- if (!GA->padddata)
+ if(this)
{
- CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
- "FATAL ERROR: Cannot allocate data for %s [%d]\n",
- GA->name, GA->id);
- }
-
- GA->storage = PUGH_STORAGE;
-
- return retval;
-
-}
+ this->extras = extras;
+ this->connectivity = connectivity;
+ this->comm = NULL;
+ this->groupcomm = groupcomm;
+ this->parent = parent;
+ this->varsize = varsize;
+ this->vtype = vtype;
+ this->stagger = stagger;
+ this->id = id;
-int PUGH_DisableGADataStorage(pGA *GA)
-{
- int retval;
- int i;
+ this->storage = PUGH_NOSTORAGE;
- if (GA->storage == PUGH_STORAGE)
- {
- if (GA->padddata)
+ this->name = (char *) malloc((strlen(name)+1)*sizeof(char));
+ this->padddata = (void *) calloc(1, varsize);
+ this->data = this->padddata;
+
+ if(this->name && this->padddata)
{
- free(GA->padddata);
- GA->padddata = NULL;
- GA->data = NULL;
+ strcpy(this->name, name);
}
-
- for (i = 0; i < 2*GA->extras->dim; i++)
+ else
{
- if (GA->send_buffer[i])
+ if(this->name)
{
-#ifdef CCTK_MPI
- if(GA->sreq[i] != MPI_REQUEST_NULL)
- {
- CACTUS_MPI_ERROR(MPI_Request_free(&(GA->sreq[i])));
- }
-#endif
- free(GA->send_buffer[i]);
- GA->send_buffer[i] = NULL;
+ free(this->name);
}
- }
-
- for (i = 0; i < 2*GA->extras->dim; i++)
- {
- if (GA->recv_buffer[i])
+ if(this->padddata)
{
- free(GA->recv_buffer[i]);
- GA->recv_buffer[i] = NULL;
+ free(this->padddata);
}
+ free(this);
+ this = NULL;
}
-
- GA->padddata = calloc(1, GA->varsize);
- GA->data = GA->padddata;
-
- GA->storage = PUGH_NOSTORAGE;
- retval = 0;
- }
- else
- {
- retval = 1;
}
- return retval;
+ return this;
}
-
/*@@
- @routine PUGH_GAComm
- @date Sun Jan 23 12:46:23 2000
- @author Gabrielle Allen
+ @routine PUGH_DestroyGArray
+ @date Mar 12 2000
+ @author Thomas Radke
@desc
- This sets the docomm[2*dim] array of the GA based
- on the setting of the comm flag.
+ Destroys a pGA object.
@enddesc
-@@*/
-
+ @calls
+ @calledby
+ @history
+
+ @endhistory
-void PUGH_GAComm(pGA *GA, int docomm)
+@@*/
+void PUGH_DestroyGArray(pGA **GA)
{
- int idir;
- int dim = GA->extras->dim;
-
- /* Copy docomm */
- GA->commflag = docomm;
-
- /* First set all communcation off */
- for (idir=0;idir<2*dim;idir++)
- GA->docomm[idir] = 0;
-
- if (docomm == PUGH_NOCOMM)
- {
- for (idir=0;idir<2*dim;idir++)
- GA->docomm[idir] = 0;
- }
- else if (docomm == PUGH_ALLCOMM)
- {
- for (idir=0;idir<2*dim;idir++)
- {
- GA->docomm[idir] = 1;
- }
- }
- else if (docomm == PUGH_PLUSFACESCOMM)
- {
- for (idir=0;idir<dim;idir++)
- {
- GA->docomm[2*idir+1] = 1;
- }
- }
- else if (docomm == PUGH_MINUSFACESCOMM)
+ if(GA && *GA)
{
- for (idir=0;idir<dim;idir++)
+ if((*GA)->storage != PUGH_NOSTORAGE)
{
- GA->docomm[2*idir] = 1;
+ PUGH_DisableGArrayDataStorage(*GA);
}
- }
- else
- {
- for (idir=0;idir<dim;idir++)
+ /* destroy group comm buffers only once per group */
+ if((*GA)->groupcomm && (*GA)->groupcomm->first_var == (*GA)->id)
{
- if (docomm == PUGH_COMM(idir))
- {
- GA->docomm[2*idir] = 1;
- GA->docomm[2*idir+1] = 1;
- }
+ PUGH_DestroyComm(&(*GA)->groupcomm);
}
- }
-
- /* FIXME Add back the check that you have a valid COMM model: Gab */
-
- /* Handle nsize = 1 type cases. This is only important for one
- processor MPI periodic boundaries */
-
- for (idir=0;idir<dim;idir++)
- {
- if (GA->extras->nsize[idir] == 1)
+ if((*GA)->comm)
{
- GA->docomm[2*idir] = 0;
- GA->docomm[2*idir+1] = 0;
+ PUGH_DestroyComm(&(*GA)->comm);
}
+ free((*GA)->name);
+ free((*GA)->padddata);
+
+ free(*GA);
+ *GA = NULL;
}
-
}