From 7e210c78a54fc07637800ca834aa8092ef7ff873 Mon Sep 17 00:00:00 2001 From: rhaas Date: Fri, 15 Feb 2013 18:56:39 +0000 Subject: output list of currently registerd variables when exceeding the accumulator limit Currently when a thorn tries to register more evolved/constrained/sandr variables than the respective parameters allow, MoL aborts with an error message "You have tried to register more evolved variables than the accumulator parameter MoL_Num_Evolved_Variables allows. Check that you are accumulating onto this parameter correctly." which is not terribly helpful in finding out why this is happening. git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/MoL/trunk@191 578cdeb0-5ea1-4b81-8215-5a3b8777ee0b --- src/Registration.c | 246 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 191 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/Registration.c b/src/Registration.c index 5f58d36..6fe1bfc 100644 --- a/src/Registration.c +++ b/src/Registration.c @@ -10,6 +10,11 @@ @version $Header$ @@*/ +#include +#include +#include +#include + #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" @@ -27,6 +32,7 @@ CCTK_FILEVERSION(CactusBase_MoL_Registration_c); /******************************************************************** ********************* Local Routine Prototypes ********************* ********************************************************************/ +static char *VarListToString(const int varindices[], const int nvars); /******************************************************************** ***************** Scheduled Routine Prototypes ********************* @@ -1110,10 +1116,18 @@ CCTK_INT MoL_RegisterEvolvedReal(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) if (MoLNumEvolvedVariables+1 > MoL_Num_Evolved_Vars) { - CCTK_WARN(0,"You have tried to register more evolved " + const char *evolvedvarname = CCTK_VarName(EvolvedIndex); + char *registeredvars = + VarListToString(EvolvedVariableIndex, MoLNumEvolvedVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more evolved " "variables than the accumulator parameter " "MoL_Num_Evolved_Variables allows. Check that " - "you are accumulating onto this parameter correctly"); + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of registered " + "variables is %d, they are: %s.", + evolvedvarname, MoL_Num_Evolved_Vars, registeredvars); + free(registeredvars); /* NOTREACHED */ } EvolvedVariableIndex[MoLNumEvolvedVariables] = EvolvedIndex; @@ -1299,10 +1313,18 @@ CCTK_INT MoL_RegisterEvolvedRealSlow(CCTK_INT EvolvedIndex, CCTK_INT RHSIndexSlo if (MoLNumEvolvedVariablesSlow+1 > MoL_Num_Evolved_Vars_Slow) { - CCTK_WARN(0,"You have tried to register more evolved " + const char *evolvedvarname = CCTK_VarName(EvolvedIndex); + char *registeredvars = + VarListToString(EvolvedVariableIndex, MoLNumEvolvedVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more evolved " "variables than the accumulator parameter " "MoL_Num_Evolved_Variables allows. Check that " - "you are accumulating onto this parameter correctly"); + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of registered " + "variables is %d, they are: %s.", + evolvedvarname, MoL_Num_Evolved_Vars_Slow, registeredvars); + free(registeredvars); /* NOTREACHED */ } EvolvedVariableIndexSlow[MoLNumEvolvedVariablesSlow] = EvolvedIndex; @@ -1449,11 +1471,18 @@ CCTK_INT MoL_RegisterConstrainedReal(CCTK_INT ConstrainedIndex) if (MoLNumConstrainedVariables+1 > MoL_Num_Constrained_Vars) { - CCTK_WARN(0,"You have tried to register more constrained " + const char *constrainedvarname = CCTK_VarName(ConstrainedIndex); + char *registeredvars = + VarListToString(ConstrainedVariableIndex, MoLNumConstrainedVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more constrained " "variables than the accumulator parameter " - "MoL_Num_Constrained_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + "MoL_Num_Constrained_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + constrainedvarname, MoL_Num_Constrained_Vars, registeredvars); + free(registeredvars); /* NOTREACHED */ } ConstrainedVariableIndex[MoLNumConstrainedVariables] = ConstrainedIndex; @@ -1571,10 +1600,19 @@ CCTK_INT MoL_RegisterSaveAndRestoreReal(CCTK_INT SandRIndex) if (MoLNumSandRVariables+1 > MoL_Num_SaveAndRestore_Vars) { - CCTK_WARN(0,"You have tried to register more save and restore " + const char *saveandrestorevarname = CCTK_VarName(SandRIndex); + char *registeredvars = + VarListToString(SandRVariableIndex, MoLNumSandRVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more save and restore " "variables than the accumulator parameter " - "MoL_Num_SaveAndRestore_Variables allows. Check " - "that you are accumulating onto this parameter correctly"); + "MoL_Num_SaveAndRestore_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + saveandrestorevarname, MoL_Num_SaveAndRestore_Vars, + registeredvars); + free(registeredvars); /* NOTREACHED */ } SandRVariableIndex[MoLNumSandRVariables] = SandRIndex; @@ -1852,11 +1890,18 @@ CCTK_INT MoL_RegisterEvolvedComplex(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) if (MoLNumEvolvedComplexVariables+1 > MoL_Num_ComplexEvolved_Vars) { - CCTK_WARN(0,"You have tried to register more evolved complex " + const char *evolvedvarname = CCTK_VarName(EvolvedIndex); + char *registeredvars = + VarListToString(Complexcomplex evolvedVariableIndex, MoLNumComplexcomplex evolvedVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more complex evolved " "variables than the accumulator parameter " - "MoL_Num_ComplexEvolved_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + "MoL_Num_Complexcomplex evolved_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of registered " + "variables is %d, they are: %s.", + evolvedvarname, MoL_Num_ComplexEvolved_Vars, registeredvars); + free(registeredvars); /* NOTREACHED */ } EvolvedComplexVariableIndex[MoLNumEvolvedComplexVariables] = EvolvedIndex; @@ -1975,11 +2020,19 @@ CCTK_INT MoL_RegisterConstrainedComplex(CCTK_INT ConstrainedIndex) if (MoLNumConstrainedComplexVariables+1 > MoL_Num_ComplexConstrained_Vars) { - CCTK_WARN(0,"You have tried to register more constrained " - "complex variables than the accumulator parameter " - "MoL_Num_ComplexConstrained_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + const char *constrainedvarname = CCTK_VarName(ConstrainedIndex); + char *registeredvars = + VarListToString(ComplexConstrainedVariableIndex, MoLNumComplexConstrainedVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more complex constrained " + "variables than the accumulator parameter " + "MoL_Num_ComplexConstrained_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + constrainedvarname, MoL_Num_ComplexConstrained_Vars, + registeredvars); + free(registeredvars); /* NOTREACHED */ } ConstrainedComplexVariableIndex[MoLNumConstrainedComplexVariables] = @@ -2094,11 +2147,20 @@ CCTK_INT MoL_RegisterSaveAndRestoreComplex(CCTK_INT SandRIndex) if (MoLNumSandRComplexVariables+1 > MoL_Num_ComplexSaveAndRestore_Vars) { - CCTK_WARN(0,"You have tried to register more save and restore " - "complex variables than the accumulator parameter " - "MoL_Num_ComplexSaveAndRestore_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + const char *saveandrestorevarname = CCTK_VarName(SandRIndex); + char *registeredvars = + VarListToString(ComplexSandRVariableIndex, + MoLNumComplexSandRVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more complex save and restore " + "variables than the accumulator parameter " + "MoL_Num_ComplexSaveAndRestore_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + saveandrestorevarname, MoL_Num_ComplexSaveAndRestore_Vars, + registeredvars); + free(registeredvars); /* NOTREACHED */ } SandRComplexVariableIndex[MoLNumSandRComplexVariables] = SandRIndex; @@ -2327,11 +2389,18 @@ CCTK_INT MoL_RegisterEvolvedArray(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) if (MoLNumEvolvedArrayVariables+1 > MoL_Num_ArrayEvolved_Vars) { - CCTK_WARN(0,"You have tried to register more evolved array " + const char *evolvedvarname = CCTK_VarName(EvolvedIndex); + char *registeredvars = + VarListToString(EvolvedArrayVariableIndex, MoLNumEvolvedArrayVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more evolved array " "variables than the accumulator parameter " - "MoL_Num_ArrayEvolved_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + "MoL_Num_Arrayevolved array_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of registered " + "variables is %d, they are: %s.", + evolvedvarname, MoL_Num_ArrayEvolved_Vars, registeredvars); + free(registeredvars); /* NOTREACHED */ } EvolvedArrayVariableIndex[MoLNumEvolvedArrayVariables] = EvolvedIndex; @@ -2437,11 +2506,19 @@ CCTK_INT MoL_RegisterConstrainedArray(CCTK_INT ConstrainedIndex) if (MoLNumConstrainedArrayVariables+1 > MoL_Num_ArrayConstrained_Vars) { - CCTK_WARN(0,"You have tried to register more constrained " - "array variables than the accumulator " - "parameter MoL_Num_ArrayConstrained_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + const char *constrainedvarname = CCTK_VarName(ConstrainedIndex); + char *registeredvars = + VarListToString(ConstrainedArrayVariableIndex, MoLNumConstrainedArrayVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more constrained array " + "variables than the accumulator parameter " + "MoL_Num_ArrayConstrained_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + constrainedvarname, MoL_Num_ArrayConstrained_Vars, + registeredvars); + free(registeredvars); /* NOTREACHED */ } ConstrainedArrayVariableIndex[MoLNumConstrainedArrayVariables] = @@ -2547,11 +2624,19 @@ CCTK_INT MoL_RegisterSaveAndRestoreArray(CCTK_INT SandRIndex) if (MoLNumSandRArrayVariables+1 > MoL_Num_ArraySaveAndRestore_Vars) { - CCTK_WARN(0,"You have tried to register more save and restore " - "array variables than the accumulator parameter " - "MoL_Num_ArraySaveAndRestore_Variables allows. " - "Check that you are accumulating onto " - "this parameter correctly"); + const char *saveandrestorevarname = CCTK_VarName(SandRIndex); + char *registeredvars = + VarListToString(SandRVariableIndex, MoLNumSandRArrayVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more save and restore array " + "variables than the accumulator parameter " + "MoL_Num_ArraySaveAndRestore_Variables allows. Check that " + "you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + saveandrestorevarname, MoL_Num_ArraySaveAndRestore_Vars, + registeredvars); + free(registeredvars); /* NOTREACHED */ } SandRArrayVariableIndex[MoLNumSandRArrayVariables] = SandRIndex; @@ -2785,12 +2870,20 @@ CCTK_INT MoL_RegisterEvolvedComplexArray(CCTK_INT EvolvedIndex, if (MoLNumEvolvedComplexArrayVariables+1 > MoL_Num_ComplexArrayEvolved_Vars) { - CCTK_WARN(0,"You have tried to register more " - "evolved complex array variables than the " - "accumulator parameter " - "MoL_Num_ComplexArrayEvolved_Variables allows. " - "Check that you are accumulating onto this " - "parameter correctly"); + const char *evolvedvarname = CCTK_VarName(EvolvedIndex); + char *registeredvars = + VarListToString(ComplexArrayevolved complex arrayVariableIndex, MoLNumComplexArrayevolved complex arrayVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more evolved complex array " + "variables than the accumulator parameter " + "MoL_Num_ComplexArrayevolved complex array_Variables allows. " + "Check that you are accumulating onto this parameter " + "correctly. " + "You tried to register '%s'. The maximum number of registered " + "variables is %d, they are: %s.", + evolvedvarname, MoL_Num_ComplexArrayEvolved_Vars, + registeredvars); + free(registeredvars); /* NOTREACHED */ } EvolvedComplexArrayVariableIndex[MoLNumEvolvedComplexArrayVariables] = @@ -2909,11 +3002,19 @@ CCTK_INT MoL_RegisterConstrainedComplexArray(CCTK_INT ConstrainedIndex) if (MoLNumConstrainedComplexArrayVariables+1 > MoL_Num_ComplexArrayConstrained_Vars) { - CCTK_WARN(0,"You have tried to register more constrained " - "complex array variables than the accumulator " - "parameter MoL_Num_ComplexArrayConstrained_Variables " - "allows. Check that you are accumulating onto " - "this parameter correctly"); + const char *constrainedvarname = CCTK_VarName(ConstrainedIndex); + char *registeredvars = + VarListToString(ComplexArrayConstrainedVariableIndex, MoLNumComplexArrayConstrainedVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more constrained complex array " + "variables than the accumulator parameter " + "MoL_Num_ComplexArrayConstrained_Variables allows. Check " + "that you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of registered " + "variables is %d, they are: %s.", + constrainedvarname, MoL_Num_ComplexArrayConstrained_Vars, + registeredvars) + free(registeredvars); /* NOTREACHED */ } ConstrainedComplexArrayVariableIndex[MoLNumConstrainedComplexArrayVariables] = ConstrainedIndex; @@ -3028,11 +3129,19 @@ CCTK_INT MoL_RegisterSaveAndRestoreComplexArray(CCTK_INT SandRIndex) if (MoLNumSandRComplexArrayVariables+1 > MoL_Num_ComplexArraySaveAndRestore_Vars) { - CCTK_WARN(0,"You have tried to register more save and restore " - "complex array variables than the accumulator " - "parameter MoL_Num_ComplexArraySaveAndRestore_Variables " - "allows. Check that you are accumulating onto this " - "parameter correctly"); + const char *saveandrestorevarname = CCTK_VarName(SandRIndex); + char *registeredvars = + VarListToString(SandRVariableIndex, MoLNumComplexArraySandRVariables); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have tried to register more save and restore complex " + "array variables than the accumulator parameter " + "MoL_Num_ComplexArraySaveAndRestore_Variables allows. Check " + "that you are accumulating onto this parameter correctly. " + "You tried to register '%s'. The maximum number of " + "registered variables is %d, they are: %s.", + saveandrestorevarname, + MoL_Num_ComplexArraySaveAndRestore_Vars, registeredvars); + free(registeredvars); /* NOTREACHED */ } SandRComplexArrayVariableIndex[MoLNumSandRComplexArrayVariables] = @@ -3412,3 +3521,30 @@ void CCTK_FCALL CCTK_FNAME(MoL_ChangeVarToNone)(int *ierr, /******************************************************************** ********************* Local Routines ************************* ********************************************************************/ + +static char *VarListToString(const int varindices[], const int nvars) +{ + size_t off = 0, len = 1; + char *vars = NULL; + /* count how much room we need for the full output string */ + for(int index = 0 ; index < nvars ; index++) + { + char *varname = CCTK_FullName(varindices[index]); + len += strlen(varname) + 1; /* ' ' or '\0' as separator */ + free(varname); + } + vars = malloc(len); + assert(vars != NULL); + /* construct list in buffer */ + for(int index = 0 ; index < nvars ; index++) + { + char *varname = CCTK_FullName(varindices[index]); + const size_t written = + snprintf(vars+off, len-off, "%s%s", off>0?" ":"", varname); + assert(written < len-off); + off = strlen(vars); + free(varname); + } + vars[off] = '\0'; /* close string in case we had no variables at all */ + return vars; +} -- cgit v1.2.3