summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>2002-04-04 09:16:35 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>2002-04-04 09:16:35 +0000
commit4573c9f1baf5dc4f6118283cca4560a4ce6945a4 (patch)
tree268459e9ab32bde6b3aa68a457e5b674ca5f5585 /src
parente022eb9ef2b9936c980387c4fa984b053db1b72a (diff)
Two new overloadable routines
CCTK_GroupStorageIncrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status) CCTK_GroupStorageDecrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status) These should increase or decrease the number of timelevels with storage enabled to the number specified in the timelevels array for each group in the groups array. The status array is optional, and if not NULL should contain the previous number of timelevels enabled for that group. A timelevel value of -1 implies enable/disable all timelevels for that group. The Increase function should never decrease the amount of storage, and the Decrease one never increase it, so it is possible to use Enable to ensure a certain minimum number of timelevels are available without problem, and to pass the status return from Enable in as the timelevel array of Decrease to restore the previous state of the system. The defaults for these functions currently call the old Enable and Disable GroupStorage routines if they have been overloaded, similarly the defaults for the old routines have been changed to call the new routines if they are overloaded, passing -1 as the timelevel value. The old routines will disappear eventually once all drivers are converted to the new routines. Tom git-svn-id: http://svn.cactuscode.org/flesh/trunk@2693 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r--src/comm/CactusDefaultComm.c373
-rw-r--r--src/comm/OverloadComm.c23
-rw-r--r--src/include/CommOverloadables.h10
3 files changed, 403 insertions, 3 deletions
diff --git a/src/comm/CactusDefaultComm.c b/src/comm/CactusDefaultComm.c
index d295af49..56cedfdc 100644
--- a/src/comm/CactusDefaultComm.c
+++ b/src/comm/CactusDefaultComm.c
@@ -5,7 +5,7 @@
@desc
Default communication routines.
@enddesc
- @version $Id$
+ @version $Header$
@@*/
@@ -15,11 +15,15 @@
#include "cctk_Flesh.h"
#include "cctk_Groups.h"
#include "cctk_Constants.h"
-#include "CactusMainDefaults.h"
+#include "cctk_Comm.h"
+#include "cctk_WarnLevel.h"
+
#include "cctki_GHExtensions.h"
#include "cctk_ParamCheck.h"
+#include "CactusMainDefaults.h"
+
#ifdef CCTK_MPI
#include "mpi.h"
#endif
@@ -73,6 +77,11 @@ int CactusDefaultExit(cGH *GH, int retval);
int CactusDefaultAbort(cGH *GH, int retval);
int CactusDefaultBarrier(const cGH *GH);
+int CactusDefaultEnableGroupStorage(cGH *GH, const char *group);
+int CactusDefaultDisableGroupStorage(cGH *GH, const char *group);
+int CactusDefaultGroupStorageIncrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status);
+int CactusDefaultGroupStorageDecrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status);
+
/*@@
@routine CactusDefaultSetupGH
@@ -425,3 +434,363 @@ int CactusDefaultBarrier (const cGH *GH)
return (0);
}
+
+ /*@@
+ @routine CactusDefaultEnableGroupStorage
+ @date Wed Apr 3 17:01:22 2002
+ @author Tom Goodale
+ @desc
+ Default enable group storage routine.
+ The enable group storage routine should allocate memory
+ for a group and return the previous status of that memory.
+ This default checks for the presence of the newer
+ GroupStorageIncrease function, and if that is not available
+ it flags an error.
+ If it is available it makes a call to it, passing -1 as the timelevel
+ argument, which is supposed to mean enable all timelevels, i.e.
+ preserving this obsolete behaviour.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio inout
+ @vcomment
+ A driver should replace the appropriate GV pointers on this
+ structure when they change the storage state of a GV.
+ @endvar
+ @var group
+ @vdesc Group to allocate storage for
+ @vtype const char *
+ @vio in
+ @vcomment
+ This should be a valid group name.
+ @endvar
+
+ @returntype int
+ @returndesc
+ 0 if the group previously had no storage
+ 1 if the group previously had storage
+ @endreturndesc
+ @@*/
+int CactusDefaultEnableGroupStorage(cGH *GH, const char *group)
+{
+ int retval;
+
+ /* Has the increase group storage routine been overloaded ? */
+ if(CCTK_GroupStorageIncrease != CactusDefaultGroupStorageIncrease)
+ {
+ int groups[1];
+ int timelevels[1];
+ int status[1];
+
+ groups[0] = CCTK_GroupIndex(group);
+ timelevels[0] = -1;
+
+ CCTK_GroupStorageIncrease(GH, 1, groups, timelevels, status);
+ retval = status[0];
+ }
+ else
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "No driver thorn activated to provide storage for variables");
+ retval = -1;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine CactusDefaultDisableGroupStorage
+ @date Wed Apr 3 17:01:22 2002
+ @author Tom Goodale
+ @desc
+ Default disable group storage routine.
+ The disable group storage routine should deallocate memory
+ for a group and return the previous status of that memory.
+ This default checks for the presence of the newer
+ GroupStorageDecrease function, and if that is not available
+ it flags an error.
+ If it is available it makes a call to it, passing -1 as the timelevel
+ argument, which is supposed to mean disable all timelevels, i.e.
+ preserving this obsolete behaviour.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio inout
+ @vcomment
+ A driver should replace the appropriate GV pointers on this
+ structure when they change the storage state of a GV.
+ @endvar
+ @var group
+ @vdesc Group to deallocate storage for
+ @vtype const char *
+ @vio in
+ @vcomment
+ This should be a valid group name.
+ @endvar
+
+ @returntype int
+ @returndesc
+ 0 if the group previously had no storage
+ 1 if the group previously had storage
+ @endreturndesc
+ @@*/
+int CactusDefaultDisableGroupStorage(cGH *GH, const char *group)
+{
+ int retval;
+
+ /* Has the decrease group storage routine been overloaded ? */
+ if(CCTK_GroupStorageDecrease != CactusDefaultGroupStorageDecrease)
+ {
+ int groups[1];
+ int timelevels[1];
+ int status[1];
+
+ groups[0] = CCTK_GroupIndex(group);
+ timelevels[0] = -1;
+
+ CCTK_GroupStorageDecrease(GH, 1, groups, timelevels, status);
+ retval = status[0];
+ }
+ else
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "No driver thorn activated to provide storage for variables");
+ retval = -1;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine CactusDefaultGroupStorageIncrease
+ @date Wed Apr 3 17:01:22 2002
+ @author Tom Goodale
+ @desc
+ Default increase group storage routine.
+ The increase group storage routine should increase the allocated memory
+ to the specified number of timelevels of each listed group, returning the
+ previous number of timelevels enable for that group in the status array,
+ if that is not NULL. It should never decrease the number of timelevels enabled,
+ i.e. if it is asked to enable less timelevels than are already enable it should
+ not change the storage for that group.
+
+ This default checks for the presence of the older
+ EnableGroupStorage function, and if that is not available it flags an error.
+ If it is available it makes a call to it, and puts its return value in the status
+ flag for the group.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio inout
+ @vcomment
+ A driver should replace the appropriate GV pointers on this
+ structure when they change the storage state of a GV.
+ @endvar
+ @var n_groups
+ @vdesc Number of groups in group array
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var groups
+ @vdesc Groups to allocate storage for
+ @vtype const int *
+ @vio in
+ @vcomment
+ This should be a list of group indices. -1 is treated as a flag to ignore this entry.
+ @endvar
+ @var timelevels
+ @vdesc Number of timelevels to allocate storage for for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ This array should have n_groups elements.
+ @endvar
+ @var status
+ @vdesc Optional return array to contain previous state of storage for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ If this array is not NULL, it will, on return, contain the number of timelevels which
+ were previously allocated storage for each group.
+ @endvar
+
+ @returntype int
+ @returndesc
+ The total number of timelevels with storage enabled for all groups queried or
+ modified.
+ @endreturndesc
+ @@*/
+int CactusDefaultGroupStorageIncrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status)
+{
+ int retval;
+
+ /* Has the normal group storage been overloaded ? */
+ if(CCTK_EnableGroupStorage != CactusDefaultEnableGroupStorage)
+ {
+ int i;
+ char *groupname;
+ int value;
+
+ retval = 0;
+
+ for(i=0; i < n_groups; i++)
+ {
+ if(groups[i] > -1)
+ {
+ groupname = CCTK_GroupName(groups[i]);
+ value = CCTK_EnableGroupStorage(GH, groupname);
+ retval += value;
+ if(status)
+ {
+ status[i] = value;
+ }
+ }
+ }
+ }
+ else
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "No driver thorn activated to provide storage for variables");
+ retval = -1;
+ }
+
+ /* Avoid a warning about timelevels being unused. */
+ timelevels = timelevels;
+
+ return retval;
+}
+
+ /*@@
+ @routine CactusDefaultGroupStorageDecrease
+ @date Wed Apr 3 17:01:22 2002
+ @author Tom Goodale
+ @desc
+ Default decrease group storage routine.
+ The decrease group storage routine should decrease the memory allocated
+ to the specified number of timelevels for each listed group, returning the
+ previous number of timelevels enable for that group in the status array,
+ if that is not NULL. It should never increase the number of timelevels enabled,
+ i.e. if it is asked to reduce to more timelevels than are enable it should
+ not change the storage for that group.
+
+ This default checks for the presence of the older
+ EnableGroupStorage function, and if that is not available it flags an error.
+ If it is available it makes a call to it, and puts its return value in the status
+ flag for the group.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio inout
+ @vcomment
+ A driver should replace the appropriate GV pointers on this
+ structure when they change the storage state of a GV.
+ @endvar
+ @var n_groups
+ @vdesc Number of groups in group array
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var groups
+ @vdesc Groups to reduce storage for
+ @vtype const int *
+ @vio in
+ @vcomment
+ This should be a list of group indices. -1 is treated as a flag to ignore this entry.
+ @endvar
+ @var timelevels
+ @vdesc Number of timelevels to reduce storage for for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ This array should have n_groups elements.
+ @endvar
+ @var status
+ @vdesc Optional return array to contain previous state of storage for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ If this array is not NULL, it will, on return, contain the number of timelevels which
+ were previously allocated storage for each group.
+ @endvar
+
+ @returntype int
+ @returndesc
+ The total number of timelevels with storage enabled for all groups queried or
+ modified.
+ @endreturndesc
+ @@*/
+int CactusDefaultGroupStorageDecrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status)
+{
+ int retval;
+
+ /* Has the normal group storage been overloaded ? */
+ if(CCTK_DisableGroupStorage != CactusDefaultDisableGroupStorage)
+ {
+ int i;
+ char *groupname;
+ int value;
+
+ retval = 0;
+ for(i=0; i < n_groups; i++)
+ {
+ /* Bogus entries in group array are marked with -1.*/
+ if(groups[i] > -1)
+ {
+ /* Since the old enable and disable group storage just returned true or false
+ * and did all timelevels, only disable storage if timelevels is 0.
+ */
+ if(timelevels[i] == 0)
+ {
+ groupname = CCTK_GroupName(groups[i]);
+ value = CCTK_DisableGroupStorage(GH, groupname);
+ }
+ else
+ {
+ value = 0;
+ }
+ retval += value;
+ if(status)
+ {
+ status[i] = value;
+ }
+ }
+ }
+ }
+ else
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "No driver thorn activated to provide storage for variables");
+ retval = -1;
+ }
+
+ return retval;
+}
+
diff --git a/src/comm/OverloadComm.c b/src/comm/OverloadComm.c
index 40b3a46a..90aca73c 100644
--- a/src/comm/OverloadComm.c
+++ b/src/comm/OverloadComm.c
@@ -7,7 +7,7 @@
Uses the overload macros to make sure of consistency and
to save typing !
@enddesc
- @version $Id$
+ @version $Header$
@@*/
#include <stdio.h>
@@ -34,6 +34,12 @@ CCTK_FILEVERSION(comm_OverloadComm_c)
#define CCTKi_DummynProcs CactusDefaultnProcs
#define CCTKi_DummySetupGH CactusDefaultSetupGH
+ /* Need to do some stuff to make sure old routines still work. */
+#define CCTKi_DummyEnableGroupStorage CactusDefaultEnableGroupStorage
+#define CCTKi_DummyDisableGroupStorage CactusDefaultDisableGroupStorage
+#define CCTKi_DummyGroupStorageIncrease CactusDefaultGroupStorageIncrease
+#define CCTKi_DummyGroupStorageDecrease CactusDefaultGroupStorageDecrease
+
#include "CommOverloadables.h"
/* Reset the #define to prevent complications. */
@@ -44,6 +50,11 @@ CCTK_FILEVERSION(comm_OverloadComm_c)
#undef CCTKi_DummyExit
#undef CCTKi_DummyAbort
+#undef CCTKi_DummyEnableGroupStorage
+#undef CCTKi_DummyDisableGroupStorage
+#undef CCTKi_DummyGroupStorageIncrease
+#undef CCTKi_DummyGroupStorageDecrease
+
#undef OVERLOADABLE
/* Create the overloadable function variables and the
@@ -83,6 +94,11 @@ int CCTKi_SetupCommFunctions(void)
#define CCTKi_DummynProcs CactusDefaultnProcs
#define CCTKi_DummySetupGH CactusDefaultSetupGH
+#define CCTKi_DummyEnableGroupStorage CactusDefaultEnableGroupStorage
+#define CCTKi_DummyDisableGroupStorage CactusDefaultDisableGroupStorage
+#define CCTKi_DummyGroupStorageIncrease CactusDefaultGroupStorageIncrease
+#define CCTKi_DummyGroupStorageDecrease CactusDefaultGroupStorageDecrease
+
#include "CommOverloadables.h"
/* Reset the #define to prevent complications. */
@@ -93,6 +109,11 @@ int CCTKi_SetupCommFunctions(void)
#undef CCTKi_DummynProcs
#undef CCTKi_DummySetupGH
+#undef CCTKi_DummyEnableGroupStorage
+#undef CCTKi_DummyDisableGroupStorage
+#undef CCTKi_DummyGroupStorageIncrease
+#undef CCTKi_DummyGroupStorageDecrease
+
#undef OVERLOADABLE
return 0;
diff --git a/src/include/CommOverloadables.h b/src/include/CommOverloadables.h
index b59a05b7..dbf23797 100644
--- a/src/include/CommOverloadables.h
+++ b/src/include/CommOverloadables.h
@@ -110,6 +110,16 @@ OVERLOADABLE(GroupDynamicData)
#undef USE_ARGUMENTS
#undef RETURN_TYPE
+#define RETURN_TYPE int
+#define ARGUMENTS cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status
+#define USE_ARGUMENTS GH = GH; n_groups=n_groups; groups = groups; timelevels = timelevels; status = status;
+OVERLOADABLE(GroupStorageIncrease)
+OVERLOADABLE(GroupStorageDecrease)
+
+#undef ARGUMENTS
+#undef USE_ARGUMENTS
+#undef RETURN_TYPE
+
#undef OVERLOADABLE_CALL
#undef OVERLOADABLE_PREFIX
#undef OVERLOADABLE_DUMMY_PREFIX