diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/IO/CactusDefaultIO.c | 39 | ||||
-rw-r--r-- | src/IO/Overload.c | 75 | ||||
-rw-r--r-- | src/IO/RegisterIOFunction.c | 124 | ||||
-rw-r--r-- | src/IO/make.code.defn | 3 | ||||
-rw-r--r-- | src/comm/CactusDefaultComm.c | 29 | ||||
-rw-r--r-- | src/comm/Overload.c | 82 | ||||
-rw-r--r-- | src/comm/RegisterCommFunction.c | 169 | ||||
-rw-r--r-- | src/comm/make.code.defn | 2 | ||||
-rw-r--r-- | src/include/CactusCommFunctions.h | 16 | ||||
-rw-r--r-- | src/include/CactusMainFunctions.h | 8 | ||||
-rw-r--r-- | src/include/CommOverloadables.h | 70 | ||||
-rw-r--r-- | src/include/IOOverloadables.h | 29 | ||||
-rw-r--r-- | src/include/MainOverloadables.h | 28 | ||||
-rw-r--r-- | src/include/OverloadMacros.h | 72 | ||||
-rw-r--r-- | src/include/flesh.h | 6 | ||||
-rw-r--r-- | src/main/CactusDefaultInitialise.c | 2 | ||||
-rw-r--r-- | src/main/Overload.c | 83 | ||||
-rw-r--r-- | src/main/RegisterMainFunction.c | 123 | ||||
-rw-r--r-- | src/main/flesh.cc | 7 | ||||
-rw-r--r-- | src/main/make.code.defn | 5 |
20 files changed, 460 insertions, 512 deletions
diff --git a/src/IO/CactusDefaultIO.c b/src/IO/CactusDefaultIO.c deleted file mode 100644 index aa9b85cd..00000000 --- a/src/IO/CactusDefaultIO.c +++ /dev/null @@ -1,39 +0,0 @@ - /*@@ - @file CactusDefaultIO.c - @date Tue Sep 29 12:45:04 1998 - @author Tom Goodale - @desc - Default cactus IO routine. - @enddesc - @@*/ - - -#include <stdio.h> -#include <stdlib.h> - -#include "flesh.h" -#include "CactusIODefaults.h" - -static char *rcsid = "$Id$"; - - -int CactusDefaultOutput1D(cGH *GH, cGF *GF) -{ - printf("I'm in the default 1d output routine\n"); - - return 0; -} - -int CactusDefaultOutput2D(cGH *GH, cGF *GF) -{ - printf("I'm in the default 2d output routine\n"); - - return 0; -} - -int CactusDefaultOutput3D(cGH *GH, cGF *GF) -{ - printf("I'm in the default 3d output routine\n"); - - return 0; -} diff --git a/src/IO/Overload.c b/src/IO/Overload.c new file mode 100644 index 00000000..f22a8583 --- /dev/null +++ b/src/IO/Overload.c @@ -0,0 +1,75 @@ + /*@@ + @file Overload.c + @date Thu Feb 4 09:47:23 1999 + @author Tom Goodale + @desc + Contains routines to overload the IO functions. + Uses the overload macros to make sure of consistency and + to save typing ! + @enddesc + @@*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "flesh.h" +#include "OverloadMacros.h" + +static char *rcsid="$Header$"; + +/* Define the prototypes for the dummy functions. */ +#define OVERLOADABLE(name) OVERLOADABLE_DUMMYPROTOTYPE(name) + +#include "IOOverloadables.h" + +#undef OVERLOADABLE(name) + +/* Create the overloadable function variables and the + * functions allowing the variables to be set. + */ +#define OVERLOADABLE(name) OVERLOADABLE_FUNCTION(name) + +#include "IOOverloadables.h" + +#undef OVERLOADABLE(name) + + /*@@ + @routine SetupIOFunctions + @date Thu Feb 4 09:58:29 1999 + @author Tom Goodale + @desc + Set any IO function which hasn't been overloaded to the default. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int SetupIOFunctions(void) +{ + +#define OVERLOADABLE(name) OVERLOADABLE_CHECK(name) + + /* Deal seperately with the SetupGH routine */ +#define CCTK_DummySetupGH CactusDefaultSetupGH + +#include "IOOverloadables.h" + + /* Reset the #define to prevent complications. */ +#undef CCTK_DummySetupGH + +#undef OVERLOADABLE(name) + + return 0; +} + +/* Create the dummy functions. */ +#define OVERLOADABLE(name) OVERLOADABLE_DUMMY(name) + +#include "IOOverloadables.h" + +#undef OVERLOADABLE(name) + diff --git a/src/IO/RegisterIOFunction.c b/src/IO/RegisterIOFunction.c deleted file mode 100644 index 634cff32..00000000 --- a/src/IO/RegisterIOFunction.c +++ /dev/null @@ -1,124 +0,0 @@ - /*@@ - @file RegisterIOFunction.c - @date Tue Sep 29 10:38:41 1998 - @author Tom Goodale - @desc - Routines to register the main routines. - @enddesc - @@*/ - -#include <stdio.h> -#include <stdlib.h> - -#include "flesh.h" -#include "RegisterKeyedFunction.h" -#include "CactusIODefaults.h" - -static char *rcsid = "$Id$"; - - -/* Definitions of how many functions */ -#define CACTUS_IO_MIN 0 -#define CACTUS_IO_MAX 2 - -/* The functions. */ - -int (*Output1D)(cGH *, cGF *); - -int (*Output2D)(cGH *, cGF *); - -int (*Output3D)(cGH *, cGF *); - -/* Array of functions */ - -static void (**functions)() = NULL; - - - /*@@ - @routine RegisterIOFunction - @date Tue Sep 29 14:11:07 1998 - @author Tom Goodale - @desc - Registers a function for use by the cactus IO. - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ -int RegisterIOFunction(int key, int (*func)(cGH *, cGF *)) -{ - int return_code; - - /* Allocate memory for the array of functions. */ - if(!functions) functions = CreateKeyedFunctionArray(CACTUS_IO_MAX - CACTUS_IO_MIN+1); - - /* Check if all is well. */ - if(!functions) - { - fprintf(stderr, "Memory allocation error at line %d in file %s\n", __LINE__, __FILE__); - exit(1); - } - else - { - /* Register the function. */ - return_code = RegisterKeyedFunction(functions, - CACTUS_IO_MIN, - CACTUS_IO_MAX, - key, - (void (*)())func); - }; - - return return_code; -} - - - /*@@ - @routine SetupIOFunctions - @date Tue Sep 29 14:19:51 1998 - @author Tom Goodale - @desc - Assigns the correct names to the registered functions. - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ -int SetupIOFunctions(void) -{ - - if(functions&&functions[0]) - { - Output1D = (int (*)(cGH *, cGF *))functions[0]; - } - else - { - Output1D = CactusDefaultOutput1D; - } - - if(functions&&functions[0]) - { - Output2D = (int (*)(cGH *, cGF *))functions[1]; - } - else - { - Output2D = CactusDefaultOutput1D; - } - - if(functions&&functions[0]) - { - Output3D = (int (*)(cGH *, cGF *))functions[2]; - } - else - { - Output3D = CactusDefaultOutput1D; - } - - - return 0; -} diff --git a/src/IO/make.code.defn b/src/IO/make.code.defn index ca36d274..99bf2f41 100644 --- a/src/IO/make.code.defn +++ b/src/IO/make.code.defn @@ -1,4 +1,3 @@ SRCS=\ -CactusDefaultIO.c\ -RegisterIOFunction.c\ +Overload.c diff --git a/src/comm/CactusDefaultComm.c b/src/comm/CactusDefaultComm.c index f4d166e0..e7f96ffd 100644 --- a/src/comm/CactusDefaultComm.c +++ b/src/comm/CactusDefaultComm.c @@ -99,33 +99,4 @@ cGH *CactusDefaultSetupGH(tFleshConfig *config, int convergence_level) return thisGH; } -int CactusDefaultSyncAllFuncs(cGH *GH) -{ - printf("I'm at line %d of file %s\n", __LINE__, __FILE__); -} - -int CactusDefaultSyncGroupFuncs(cGH *GH, const char *group) -{ - printf("I'm at line %d of file %s\n", __LINE__, __FILE__); -} - -int CactusDefaultSyncOneFunc(cGH *GH, int GF) -{ - printf("I'm at line %d of file %s\n", __LINE__, __FILE__); -} - -int CactusDefaultParallelInit(tFleshConfig *config) -{ - printf("I'm at line %d of file %s\n", __LINE__, __FILE__); -} - -int CactusDefaultParallelFinalise(tFleshConfig *config) -{ - printf("I'm at line %d of file %s\n", __LINE__, __FILE__); -} - -int CactusDefaultReduce(cGH *GH, int GF, int operation, void *result) -{ - printf("I'm at line %d of file %s\n", __LINE__, __FILE__); -} diff --git a/src/comm/Overload.c b/src/comm/Overload.c new file mode 100644 index 00000000..fc509e3c --- /dev/null +++ b/src/comm/Overload.c @@ -0,0 +1,82 @@ + /*@@ + @file Overload.c + @date Wed Feb 3 23:27:18 1999 + @author Tom Goodale + @desc + Contains routines to overload the communication functions. + Uses the overload macros to make sure of consistency and + to save typing ! + @enddesc + @@*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "flesh.h" +#include "OverloadMacros.h" + +static char *rcsid="$Header$"; + +/* Define the prototypes for the dummy functions. */ +#define OVERLOADABLE(name) OVERLOADABLE_DUMMYPROTOTYPE(name) + + /* Deal seperately with the SetupGH routine */ +#define CCTK_DummySetupGH CactusDefaultSetupGH + +#include "CommOverloadables.h" + + /* Reset the #define to prevent complications. */ +#undef CCTK_DummySetupGH + +#undef OVERLOADABLE(name) + +/* Create the overloadable function variables and the + * functions allowing the variables to be set. + */ +#define OVERLOADABLE(name) OVERLOADABLE_FUNCTION(name) + +#include "CommOverloadables.h" + +#undef OVERLOADABLE(name) + + + /*@@ + @routine SetupCommFunctions(void) + @date Thu Feb 4 08:21:26 1999 + @author Tom Goodale + @desc + Set any comm function which hasn't been overloaded to the default. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int SetupCommFunctions(void) +{ + +#define OVERLOADABLE(name) OVERLOADABLE_CHECK(name) + + /* Deal seperately with the SetupGH routine */ +#define CCTK_DummySetupGH CactusDefaultSetupGH + +#include "CommOverloadables.h" + + /* Reset the #define to prevent complications. */ +#undef CCTK_DummySetupGH + +#undef OVERLOADABLE(name) + + return 0; +} + +/* Create the dummy functions. */ +#define OVERLOADABLE(name) OVERLOADABLE_DUMMY(name) + +#include "CommOverloadables.h" + +#undef OVERLOADABLE(name) + diff --git a/src/comm/RegisterCommFunction.c b/src/comm/RegisterCommFunction.c deleted file mode 100644 index 51f099de..00000000 --- a/src/comm/RegisterCommFunction.c +++ /dev/null @@ -1,169 +0,0 @@ - /*@@ - @file RegisterCommFunctions.c - @date Tue Sep 29 10:38:41 1998 - @author Tom Goodale - @desc - Routines to register the main routines. - @enddesc - @@*/ - -#include <stdio.h> -#include <stdlib.h> - -#include "flesh.h" -#include "RegisterKeyedFunction.h" -#include "CactusCommFunctions.h" -#include "CactusCommDefaults.h" - -static char *rcsid = "$Id$"; - - -/* Definitions of how many functions */ -#define CACTUS_COMM_MIN 0 -#define CACTUS_COMM_MAX 7 - -/* The functions. */ - -cGH * (*SetupGH)(tFleshConfig *, int); -int (*SetupGF)(cGH *, cGF *); - -int (*SyncAllFuncs)(cGH *); -int (*SyncGroupFuncs)(cGH *, const char *group); -int (*SyncOneFunc)(cGH*, int ); - -int (*ParallelInit)(tFleshConfig *); -int (*ParallelFinalise)(tFleshConfig *); - -int (*Reduce)(cGH *, int , int operation, void *result); - - -/* Array of functions */ - -static void (**functions)() = NULL; - - - /*@@ - @routine RegisterCommFunction - @date Tue Sep 29 14:11:07 1998 - @author Tom Goodale - @desc - Registers a function for use by the cactus communication layer. - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ -int RegisterCommFunction(int key, int (*func)()) -{ - int return_code; - - /* Allocate memory for the array of functions. */ - if(!functions) functions = CreateKeyedFunctionArray(CACTUS_COMM_MAX - CACTUS_COMM_MIN+1); - - /* Check if all is well. */ - if(!functions) - { - fprintf(stderr, "Memory allocation error at line %d in file %s\n", __LINE__, __FILE__); - exit(1); - } - else - { - /* Register the function. */ - return_code = RegisterKeyedFunction(functions, - CACTUS_COMM_MIN, - CACTUS_COMM_MAX, - key, - (void (*)())func); - }; - - return return_code; -} - - - /*@@ - @routine SetupCommFunctions - @date Tue Sep 29 14:19:51 1998 - @author Tom Goodale - @desc - Assigns the correct names to the registered functions. - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ -int SetupCommFunctions(void) -{ - - if(functions&&functions[0]) - { - SetupGH = (cGH * (*)(tFleshConfig *, int))functions[0]; - } - else - { - SetupGH = CactusDefaultSetupGH; - } - - if(functions&&functions[0]) - { - SyncAllFuncs = (int (*)(cGH *))functions[0]; - } - else - { - SyncAllFuncs = CactusDefaultSyncAllFuncs; - } - - if(functions&&functions[0]) - { - SyncGroupFuncs = (int (*)(cGH *, const char *group))functions[0]; - } - else - { - SyncGroupFuncs = CactusDefaultSyncGroupFuncs; - } - - if(functions&&functions[0]) - { - SyncOneFunc = (int (*)(cGH*, int ))functions[0]; - } - else - { - SyncOneFunc = CactusDefaultSyncOneFunc; - } - - - if(functions&&functions[0]) - { - ParallelInit = (int (*)(tFleshConfig *))functions[0]; - } - else - { - ParallelInit = CactusDefaultParallelInit; - } - - if(functions&&functions[0]) - { - ParallelFinalise = (int (*)(tFleshConfig *))functions[0]; - } - else - { - ParallelFinalise = CactusDefaultParallelFinalise; - } - - - if(functions&&functions[0]) - { - Reduce = (int (*)(cGH *, int , int operation, void *result))functions[0]; - } - else - { - Reduce = CactusDefaultReduce; - } - - return 0; -} diff --git a/src/comm/make.code.defn b/src/comm/make.code.defn index 094b4e70..c0fd8505 100644 --- a/src/comm/make.code.defn +++ b/src/comm/make.code.defn @@ -1,5 +1,5 @@ SRCS=\ CactusDefaultComm.c\ GHExtensions.c\ -RegisterCommFunction.c\ +Overload.c diff --git a/src/include/CactusCommFunctions.h b/src/include/CactusCommFunctions.h index 329fa9f8..3cabbfd3 100644 --- a/src/include/CactusCommFunctions.h +++ b/src/include/CactusCommFunctions.h @@ -12,23 +12,21 @@ #ifndef _CACTUSCOMMFUNCTIONS_H_ #define _CACTUSCOMMFUNCTIONS_H_ +#include <stdarg.h> + +#include "OverloadMacros.h" + #ifdef _cplusplus extern "C" { #endif /* The functions. */ -extern cGH * (*SetupGH)(tFleshConfig *, int); -extern int (*SetupGF)(cGH *, cGF *); - -extern int (*SyncAllFuncs)(cGH *); -extern int (*SyncGroupFuncs)(cGH *, const char *group); -extern int (*SyncOneFunc)(cGH*, int ); +#define OVERLOADABLE(name) OVERLOADABLE_PROTOTYPE(name) -extern int (*ParallelInit)(tFleshConfig *); -extern int (*ParallelFinalise)(tFleshConfig *); +#include "CommOverloadables.h" -extern int (*Reduce)(cGH *, int , int operation, void *result); +#undef OVERLOADABLE(name) #ifdef _cplusplus } diff --git a/src/include/CactusMainFunctions.h b/src/include/CactusMainFunctions.h index 690c0984..de215593 100644 --- a/src/include/CactusMainFunctions.h +++ b/src/include/CactusMainFunctions.h @@ -10,17 +10,19 @@ #ifndef _CACTUSMAINFUNCTIONS_H_ #define _CACTUSMAINFUNCTIONS_H_ +#include "OverloadMacros.h" + /* Function prototypes */ #ifdef __cplusplus extern "C" { #endif -extern int (*Initialise)(tFleshConfig *); +#define OVERLOADABLE(name) OVERLOADABLE_PROTOTYPE(name) -extern int (*Evolve)(tFleshConfig *); +#include "MainOverloadables.h" -extern int (*Shutdown)(tFleshConfig *); +#undef OVERLOADABLE(name) #ifdef __cplusplus } diff --git a/src/include/CommOverloadables.h b/src/include/CommOverloadables.h new file mode 100644 index 00000000..7b6ead2d --- /dev/null +++ b/src/include/CommOverloadables.h @@ -0,0 +1,70 @@ + /*@@ + @header CommOverloadables.h + @date Thu Feb 4 08:11:41 1999 + @author Tom Goodale + @desc + The overloadable functions for the comm layer. + See OverloadMacros.h to see how to use these. + @enddesc + @version $Header$ + @@*/ + +#ifdef ARGUMENTS +#undef ARGUMENTS +#endif + +#ifdef RETURN_TYPE +#undef RETURN_TYPE +#endif + +#define RETURN_TYPE int +#define ARGUMENTS cGH *GH, const char *group +OVERLOADABLE(SyncGroup) + +OVERLOADABLE(EnableGroupStorage) +OVERLOADABLE(DisableGroupStorage) + +OVERLOADABLE(EnableGroupComm) +OVERLOADABLE(DisableGroupComm) + +#undef ARGUMENTS +#define ARGUMENTS cGH *GH +OVERLOADABLE(Barrier) + +#undef ARGUMENTS +#define ARGUMENTS cGH *GH, \ + const char *operation, \ + int n_infields, \ + int n_outfields, \ + int out_type, \ + void **outarray, \ + ... + +OVERLOADABLE(Reduce) + +#undef ARGUMENTS +#define ARGUMENTS cGH *GH, \ + const char *operation, \ + int n_coords, \ + int n_infields, \ + int n_outfields, \ + int n_points, \ + int type, \ + ... + +OVERLOADABLE(Interp) + +#undef ARGUMENTS +#define ARGUMENTS cGH *GH +OVERLOADABLE(ParallelInit) +OVERLOADABLE(Exit) +OVERLOADABLE(Abort) + +#undef ARGUMENTS +#define ARGUMENTS tFleshConfig *config, int convergence_level +#undef RETURN_TYPE +#define RETURN_TYPE cGH * +OVERLOADABLE(SetupGH) + +#undef ARGUMENTS +#undef RETURN_TYPE diff --git a/src/include/IOOverloadables.h b/src/include/IOOverloadables.h new file mode 100644 index 00000000..1fd09782 --- /dev/null +++ b/src/include/IOOverloadables.h @@ -0,0 +1,29 @@ + /*@@ + @header IOOverloadables.h + @date Thu Feb 4 09:59:34 1999 + @author Tom Goodale + @desc + The overloadable functions for the IO layer. + See OverloadMacros.h to see how to use these. + @enddesc + @version $Header$ + @@*/ + +#ifdef ARGUMENTS +#undef ARGUMENTS +#endif + +#ifdef RETURN_TYPE +#undef RETURN_TYPE +#endif + +#define RETURN_TYPE int +#define ARGUMENTS cGH *GH +OVERLOADABLE(OutputGH) + +#undef ARGUMENTS +#define ARGUMENTS cGH *GH, const char *group +OVERLOADABLE(OutputGroup) + +#undef ARGUMENTS +#undef RETURN_TYPE diff --git a/src/include/MainOverloadables.h b/src/include/MainOverloadables.h new file mode 100644 index 00000000..1848947c --- /dev/null +++ b/src/include/MainOverloadables.h @@ -0,0 +1,28 @@ + /*@@ + @header MainOverloadables.h + @date Thu Feb 4 08:58:52 1999 + @author Tom Goodale + @desc + The overloadable functions for the main layer. + See OverloadMacros.h to see how to use these. + @enddesc + @version $Header$ + @@*/ + +#ifdef ARGUMENTS +#undef ARGUMENTS +#endif + +#ifdef RETURN_TYPE +#undef RETURN_TYPE +#endif + +#define RETURN_TYPE int +#define ARGUMENTS tFleshConfig * + +OVERLOADABLE(Initialise) +OVERLOADABLE(Evolve) +OVERLOADABLE(Shutdown) + +#undef ARGUMENTS +#undef RETURN_TYPE diff --git a/src/include/OverloadMacros.h b/src/include/OverloadMacros.h new file mode 100644 index 00000000..55018866 --- /dev/null +++ b/src/include/OverloadMacros.h @@ -0,0 +1,72 @@ + /*@@ + @header OverloadMacros.h + @date Thu Feb 4 08:02:29 1999 + @author Tom Goodale + @desc + Macros used for the overload functions + @enddesc + @version $Header$ + @@*/ + +#ifndef _OVERLOADMACROS_H_ +#define _OVERLOADMACROS_H_ + +/* These are a load of macros used to make overloadable functions. + * + * Basically define ARGUMENTS with the arguments of the function, + * and RETURN_TYPE as the return type + * then put lines of the form OVERLOADABLE(function) + * in a header file. + * Defining OVERLOADABLE(name) as OVERLOADABLE_<macro>(name) + * and then including the header will create functions, prototypes + * dummy functions or some checking code as required. + */ + +/* This macro defines a global variable with the name of the function + * and a function which allows people to set its value. + */ +#define OVERLOADABLE_FUNCTION(name) \ +RETURN_TYPE (*CCTK_##name)(ARGUMENTS) = NULL; \ +int CCTK_Overload##name(RETURN_TYPE (*func)(ARGUMENTS)) \ +{ \ + int return_code; \ + if(CCTK_##name) \ + { \ + CCTK_##name = func; \ + return_code = 1; \ + } \ + else \ + { \ + fprintf(stderr, \ + "Warning: Attempted to overload function %s twice\n",\ + #name); \ + return_code = 0; \ + } \ + \ + return return_code; \ +} + +/* This macro creates an extern declaration for an overloadable function */ +#define OVERLOADABLE_PROTOTYPE(name) \ +extern RETURN_TYPE (*CCTK_##name)(ARGUMENTS); + +/* This macro defines a dummy function */ +#define OVERLOADABLE_DUMMY(name) \ +RETURN_TYPE CCTK_Dummy##name(ARGUMENTS) \ +{ \ + fprintf(stderr, "Dummy %s called.\n", #name); \ + return 0; \ +} + +/* This macro defines the prototype for a dummy function. */ +#define OVERLOADABLE_DUMMYPROTOTYPE(name) \ +RETURN_TYPE CCTK_Dummy##name(ARGUMENTS); + +/* This macro defines a check line which will set the overloadable + * function to be the dummy if it hasn't been set. + */ +#define OVERLOADABLE_CHECK(name) \ + if(!CCTK_##name) CCTK_##name = CCTK_Dummy##name; + + +#endif diff --git a/src/include/flesh.h b/src/include/flesh.h index cdad508c..8a160d78 100644 --- a/src/include/flesh.h +++ b/src/include/flesh.h @@ -114,12 +114,6 @@ int InitialiseCactus(int *, char ***, tFleshConfig *); int CCTK_SetParameter(const char *parameter, const char *value); -extern int (*Initialise)(tFleshConfig *); - -extern int (*Evolve)(tFleshConfig *); - -extern int (*Shutdown)(tFleshConfig *); - int ShutdownCactus(tFleshConfig *); int ProcessCommandLine(int *argc, char ***argv, tFleshConfig *ConfigData); diff --git a/src/main/CactusDefaultInitialise.c b/src/main/CactusDefaultInitialise.c index 5f223cfe..0ef962b3 100644 --- a/src/main/CactusDefaultInitialise.c +++ b/src/main/CactusDefaultInitialise.c @@ -45,7 +45,7 @@ int CactusDefaultInitialise(tFleshConfig *config) CactusResetTimer(config->timer[ELLIPTIC]); convergence_level = 0; - while((GH = SetupGH(config, convergence_level))) + while((GH = CCTK_SetupGH(config, convergence_level))) { CCTK_AddGH(config, convergence_level, GH); diff --git a/src/main/Overload.c b/src/main/Overload.c new file mode 100644 index 00000000..a6b7e50f --- /dev/null +++ b/src/main/Overload.c @@ -0,0 +1,83 @@ + /*@@ + @file Overload.c + @date Thu Feb 4 09:01:18 1999 + @author Tom Goodale + @desc + Contains routines to overload the main functions. + Uses the overload macros to make sure of consistency and + to save typing ! + @enddesc + @@*/ + +#include <stdio.h> +#include <stdlib.h> + +#include "flesh.h" +#include "OverloadMacros.h" + +static char *rcsid="$Header$"; + +/* Define the prototypes for the dummy functions. */ +#define OVERLOADABLE(name) OVERLOADABLE_DUMMYPROTOTYPE(name) + + /* These ones actually have defaults. */ +#define CCTK_DummyInitialise CactusDefaultInitialise +#define CCTK_DummyEvolve CactusDefaultEvolve +#define CCTK_DummyShutdown CactusDefaultShutdown + +#include "MainOverloadables.h" + + /* Reset the #define to prevent complications. */ +#undef CCTK_DummyInitialise +#undef CCTK_DummyEvolve +#undef CCTK_DummyShutdown + +#undef OVERLOADABLE(name) + + +/* Create the overloadable function variables and the + * functions allowing the variables to be set. + */ +#define OVERLOADABLE(name) OVERLOADABLE_FUNCTION(name) + +#include "MainOverloadables.h" + +#undef OVERLOADABLE(name) + + /*@@ + @routine SetupMainFunctions + @date Thu Feb 4 09:02:49 1999 + @author Tom Goodale + @desc + Set any main function which hasn't been overloaded to the default. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int SetupMainFunctions(void) +{ + +#define OVERLOADABLE(name) OVERLOADABLE_CHECK(name) + + /* These ones actually have defaults. */ +#define CCTK_DummyInitialise CactusDefaultInitialise +#define CCTK_DummyEvolve CactusDefaultEvolve +#define CCTK_DummyShutdown CactusDefaultShutdown + +#include "MainOverloadables.h" + + /* Reset the #define to prevent complications. */ +#undef CCTK_DummyInitialise +#undef CCTK_DummyEvolve +#undef CCTK_DummyShutdown + +#undef OVERLOADABLE(name) + + return 0; +} + + diff --git a/src/main/RegisterMainFunction.c b/src/main/RegisterMainFunction.c deleted file mode 100644 index f086a584..00000000 --- a/src/main/RegisterMainFunction.c +++ /dev/null @@ -1,123 +0,0 @@ - /*@@ - @file RegisterMainFunctions.c - @date Tue Sep 29 10:38:41 1998 - @author Tom Goodale - @desc - Routines to register the main routines. - @enddesc - @@*/ - -#include <stdio.h> -#include <stdlib.h> - -#include "flesh.h" -#include "RegisterKeyedFunction.h" -#include "CactusMainDefaults.h" - -static char *rcsid = "$Id$"; - - -/* Definitions of how many functions */ -#define CACTUS_MAIN_MIN 0 -#define CACTUS_MAIN_MAX 2 - -/* The functions. */ - -int (*Initialise)(tFleshConfig *); - -int (*Evolve)(tFleshConfig *); - -int (*Shutdown)(tFleshConfig *); - -/* Array of functions */ - -static void (**functions)() = NULL; - - - /*@@ - @routine RegisterMainFunction - @date Tue Sep 29 14:11:07 1998 - @author Tom Goodale - @desc - Registers a function for use by the cactus flesh. - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ -int RegisterMainFunction(int key, int (*func)(tFleshConfig *)) -{ - int return_code; - - /* Allocate memory for the array of functions. */ - if(!functions) functions = CreateKeyedFunctionArray(CACTUS_MAIN_MAX - CACTUS_MAIN_MIN+1); - - /* Check if all is well. */ - if(!functions) - { - fprintf(stderr, "Memory allocation error at line %d in file %s\n", __LINE__, __FILE__); - exit(1); - } - else - { - /* Register the function. */ - return_code = RegisterKeyedFunction(functions, - CACTUS_MAIN_MIN, - CACTUS_MAIN_MAX, - key, - (void (*)())func); - }; - - return return_code; -} - - - /*@@ - @routine SetupMainFunctions - @date Tue Sep 29 14:19:51 1998 - @author Tom Goodale - @desc - Assigns the correct names to the registered functions. - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ -int SetupMainFunctions(void) -{ - - if(functions&&functions[0]) - { - Initialise = (int (*)(tFleshConfig *))functions[0]; - } - else - { - Initialise = CactusDefaultInitialise; - } - - if(functions&&functions[1]) - { - Evolve = (int (*)(tFleshConfig *))functions[1]; - } - else - { - Evolve = CactusDefaultEvolve; - } - - if(functions&&functions[2]) - { - Shutdown = (int (*)(tFleshConfig *))functions[2]; - } - else - { - Shutdown = CactusDefaultShutdown; - } - - return 0; -} diff --git a/src/main/flesh.cc b/src/main/flesh.cc index c6943494..e80a43d1 100644 --- a/src/main/flesh.cc +++ b/src/main/flesh.cc @@ -9,6 +9,7 @@ #include <stdio.h> #include "flesh.h" +#include "CactusMainFunctions.h" static char *rcsid = "$Id$"; @@ -53,15 +54,15 @@ int main(int argc, char **argv) /* This is a (c-linkage) routine which has been registered by a thorn. */ - Initialise(&ConfigData); + CCTK_Initialise(&ConfigData); /* This is a (c-linkage) routine which has been registered by a thorn. */ - Evolve(&ConfigData); + CCTK_Evolve(&ConfigData); /* This is a (c-linkage) routine which has been registered by a thorn. */ - Shutdown(&ConfigData); + CCTK_Shutdown(&ConfigData); /* Shut down any cactus specific stuff. */ diff --git a/src/main/make.code.defn b/src/main/make.code.defn index 7e85d542..1a73c8ca 100644 --- a/src/main/make.code.defn +++ b/src/main/make.code.defn @@ -13,7 +13,6 @@ InitialiseDataStructures.c\ ProcessCommandLine.c\ ProcessParameterDatabase.c\ RecordImplementation.c\ -RegisterMainFunction.c\ RegisterThorn.c\ SetParams.c\ ShutdownCactus.c\ @@ -22,6 +21,6 @@ flesh.cc\ Groups.c\ Variables.c\ Dummies.c\ -rfrInterface.c - +rfrInterface.c\ +Overload.c |