aboutsummaryrefslogtreecommitdiff
path: root/src/P2LMappings.c
diff options
context:
space:
mode:
authorgoodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364>2005-12-14 22:14:41 +0000
committergoodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364>2005-12-14 22:14:41 +0000
commit7cc7be1acf8f2519657e78a8bdee81920b1dc5f5 (patch)
tree8b9ac35a5b9ec0397b2d70af1b88ad64969a94c4 /src/P2LMappings.c
parent39c19b80c226f853d899d6e06c84733e22d780bd (diff)
Changes from Dylan Stark to allow registration of topology
routines and introducing a physical to logical processor mapping. Now it is possible to register custom topology routines if you don't like the two ones we have at the moment (the traditional one and the new one from Frank Loeffler). You can also provide routines to optimise the placement of neighbouring processes on the processors by giving a custom mapping from the numbers PUGH uses for the processors to the actual MPI processor. Please treat this registration as semi-volatile for the moment and coordinate with Dylan if you fancy using it. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@475 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/P2LMappings.c')
-rw-r--r--src/P2LMappings.c269
1 files changed, 269 insertions, 0 deletions
diff --git a/src/P2LMappings.c b/src/P2LMappings.c
new file mode 100644
index 0000000..85461fd
--- /dev/null
+++ b/src/P2LMappings.c
@@ -0,0 +1,269 @@
+ /*@@
+ @file P2LMappings.c
+ @date Sun Oct 30 17:02:58 CST 2005
+ @author Dylan Stark
+ @desc
+ Provides routines for mapping between physical and
+ logical numberings of processors.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "cctk.h"
+
+#include "pugh_Register.h"
+
+static const char *rcsid = "$Header$";
+
+CCTK_FILEVERSION(CactusPUGH_PUGH_P2L_c);
+
+
+/********************************************************************
+ ********************* Local Data Types ***********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Routine Prototypes *********************
+ ********************************************************************/
+
+static void *CreateDirectTranslation(int dim, int *nprocs, int np);
+static int DestroyDirectTranslation(void *table);
+static int DirectPhysicalToLogical(void *table, int proc);
+static int DirectLogicalToPhysical(void *table, int ijk);
+
+static void *CreateExampleTranslation(int dim, int *nprocs, int np);
+static int DestroyExampleTranslation(void *table);
+static int ExamplePhysicalToLogical(void *table, int proc);
+static int ExampleLogicalToPhysical(void *table, int ijk);
+
+/********************************************************************
+ ********************* Other Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Data *****************************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Scheduled Routines *************************
+ ********************************************************************/
+/* Fortran wrappers appear immediately after C definition of function */
+
+ /*@@
+ @routine PUGH_RegisterDefaultRoutines
+ @date Wed Dec 14 16:51:22 2005
+ @author Tom Goodale
+ @desc
+ Registers the default translation and topology generation routines.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+ @@*/
+
+int PUGH_RegisterPUGHP2LRoutines(void)
+{
+ PUGH_RegisterP2L(CreateDirectTranslation,
+ DestroyDirectTranslation,
+ DirectPhysicalToLogical,
+ DirectLogicalToPhysical,
+ "direct");
+
+ PUGH_RegisterP2L(CreateExampleTranslation,
+ DestroyExampleTranslation,
+ ExamplePhysicalToLogical,
+ ExampleLogicalToPhysical,
+ "example");
+
+ return 0;
+}
+
+/********************************************************************
+ ********************* External Routines **********************
+ ********************************************************************/
+
+
+/********************************************************************
+ ********************* Local Routines *****************************
+ ********************************************************************/
+
+ /*@@
+ @routine CreateDirectTranslation
+ @date Wed Dec 14 19:00:57 2005
+ @author Tom Goodale
+ @desc
+ Creates a dummy translation table as one isn't necessary for
+ the direct case.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+ @@*/
+void *CreateDirectTranslation(int dim, int *nprocs, int np)
+{
+ static int dummy = 1;
+ return (void *)&dummy;
+}
+
+ /*@@
+ @routine DestroyDirectTranslation
+ @date Wed Dec 14 19:00:57 2005
+ @author Tom Goodale
+ @desc
+ Routine which would destroy the translation table if there was one.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+ @@*/
+static int DestroyDirectTranslation(void *table)
+{
+ return 0;
+}
+
+ /*@@
+ @routine DirectPhysicalToLogical
+ @date Wed Dec 14 19:02:56 2005
+ @author Tom Goodale
+ @desc
+ Direct map of the physical processor number to the logical one.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+ @@*/
+static int DirectPhysicalToLogical(void *table, int proc)
+{
+ return proc;
+}
+
+ /*@@
+ @routine DirectLogicalToPhysical
+ @date Wed Dec 14 19:02:56 2005
+ @author Tom Goodale
+ @desc
+ Direct map of the logical processor number to the physical one.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+ @@*/
+static int DirectLogicalToPhysical(void *table, int ijk)
+{
+ return ijk;
+}
+
+/*@@
+ @routine CreateExampleTranslation
+ @date Sat Oct 8 22:24:53 CDT 2005
+ @author Dylan Stark
+ @desc
+ Allocates an int[2][np] array where the first
+ row maps id->ijk and the second row maps ijk->id.
+ @enddesc
+ @@*/
+void *CreateExampleTranslation(int dim, int *nprocs, int np)
+{
+ int i;
+ int **translation;
+
+ translation = (int **)malloc(2*sizeof(int *));
+ if (translation)
+ {
+ translation[0] = malloc(np*sizeof(int));
+ translation[1] = malloc(np*sizeof(int));
+
+ if (translation[0] && translation[1])
+ {
+ for (i=0; i<np; i++)
+ {
+ translation[0][i]=i;
+ translation[1][i]=i;
+ }
+ }
+ else
+ {
+ if (translation[0])
+ {
+ free(translation[0]);
+ }
+ if (translation[1])
+ {
+ free(translation[1]);
+ }
+
+ free(translation);
+ translation = NULL;
+ }
+ }
+
+ return (void *)translation;
+}
+
+/*@@
+ @routine DestroyExampleTranslation
+ @date Sat Oct 8 22:31:52 CDT 2005
+ @author Dylan Stark
+ @desc
+ Deallocate memory for the translation.
+ @enddesc
+ @@*/
+static int DestroyExampleTranslation(void *table)
+{
+ int **translation = (int **)table;
+
+ free(translation[0]);
+ free(translation[1]);
+ free(translation);
+
+ return 0;
+}
+
+
+/*@@
+ @routine ExamplePhysicalToLogical
+ @date Sat Oct 8 21:45:52 CDT 2005
+ @author Dylan Stark
+ @desc
+ Take an MPI processor number and map it to some logical index.
+ @enddesc
+ @@*/
+static int ExamplePhysicalToLogical(void *table, int proc)
+{
+ int **translation = (int **)table;
+
+ return translation[0][proc];
+}
+
+ /*@@
+ @routine LogicalToPhysical
+ @date Sat Oct 8 21:48:52 CDT 2005
+ @author Dylan Stark
+ @desc
+ Take a logical index and map it to a MPI processor number.
+ @enddesc
+@@*/
+static int ExampleLogicalToPhysical(void *table, int ijk)
+{
+ int **translation = (int **)table;
+
+ return translation[1][ijk];
+}