summaryrefslogtreecommitdiff
path: root/src/comm
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-12-10 14:02:40 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-12-10 14:02:40 +0000
commit2f00a0478ae6154c734856935eb9091dc072c5e6 (patch)
tree6ae99ba0ecfe548544902454c58c1333fa148810 /src/comm
parent33016dc9a563ad8715c74579cd65f1a5ebc1a240 (diff)
Corrected return codes for CCTK_Reduce() and CCTK_ReduceArray():
0 - successful -1 - wrong argument(s) Fixed BR#185 by that. git-svn-id: http://svn.cactuscode.org/flesh/trunk@1189 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/comm')
-rw-r--r--src/comm/Reduction.c124
1 files changed, 63 insertions, 61 deletions
diff --git a/src/comm/Reduction.c b/src/comm/Reduction.c
index 45c86e44..c38e863c 100644
--- a/src/comm/Reduction.c
+++ b/src/comm/Reduction.c
@@ -197,43 +197,41 @@ int CCTK_Reduce( cGH *GH,
int num_in_fields,
... )
{
-
va_list indices;
int i;
- int *in_fields = malloc(num_in_fields*sizeof(int));
- void (*function)(REDUCTION_OPERATOR_REGISTER_ARGLIST)=NULL;
+ int *in_fields;
+ void (*function)(REDUCTION_OPERATOR_REGISTER_ARGLIST);
- /* Get the pointer to the reduction operator */
+ /* Get the pointer to the reduction operator */
if (operation_handle < 0)
-
+ {
CCTK_WARN(3,"Invalid handle passed to CCTK_Reduce");
+ return (-1);
+ }
- else
- {
- function = (void (*)(REDUCTION_OPERATOR_REGISTER_ARGLIST))
+ function = (void (*)(REDUCTION_OPERATOR_REGISTER_ARGLIST))
Util_GetHandledData(ReductionOperators,operation_handle);
- if (function)
- {
-
- /* Fill in the array of variable indices from the variable argument list */
- va_start(indices, num_in_fields);
- for (i=0; i<num_in_fields; i++)
- in_fields[i] = va_arg(indices,int);
- va_end(indices);
-
- function(GH,proc,num_out_vals,type_out_vals,out_vals,num_in_fields,in_fields);
-
- if (in_fields) free(in_fields);
-
- }
- else
- CCTK_WARN(3,"Reduction operation is not registered and cannot be called");
+ if (! function)
+ {
+ CCTK_WARN(3,"Reduction operation is not registered and cannot be called");
+ return (-1);
}
-
- return 1;
-
+
+ /* Fill in the array of variable indices from the variable argument list */
+ in_fields = malloc(num_in_fields*sizeof(int));
+ va_start(indices, num_in_fields);
+ for (i=0; i<num_in_fields; i++)
+ in_fields[i] = va_arg(indices,int);
+ va_end(indices);
+
+ function (GH, proc, num_out_vals, type_out_vals, out_vals,
+ num_in_fields, in_fields);
+
+ free(in_fields);
+
+ return (0);
}
void FMODIFIER FORTRAN_NAME(CCTK_Reduce)(int *fortranreturn,
@@ -248,41 +246,42 @@ void FMODIFIER FORTRAN_NAME(CCTK_Reduce)(int *fortranreturn,
{
va_list indices;
int i;
- int *in_fields = malloc(*num_in_fields*sizeof(int));
- void (*function)(REDUCTION_OPERATOR_REGISTER_ARGLIST)=NULL;
+ int *in_fields;
+ void (*function)(REDUCTION_OPERATOR_REGISTER_ARGLIST);
- /* Get the pointer to the reduction operator */
+ /* initialize return code to indicate an error */
+ *fortranreturn = -1;
if (*operation_handle < 0)
-
+ {
CCTK_WARN(3,"Invalid handle passed to CCTK_Reduce");
+ return;
+ }
- else
- {
- function = (void (*)(REDUCTION_OPERATOR_REGISTER_ARGLIST))
+ /* Get the pointer to the reduction operator */
+ function = (void (*)(REDUCTION_OPERATOR_REGISTER_ARGLIST))
Util_GetHandledData(ReductionOperators,*operation_handle);
- if (function)
- {
-
- /* Fill in the array of variable indices from the variable argument list */
- va_start(indices, num_in_fields);
- for (i=0; i<*num_in_fields; i++)
- in_fields[i] = *va_arg(indices,int *);
- va_end(indices);
-
- function(GH,*proc,*num_out_vals,*type_out_vals,out_vals,*num_in_fields,in_fields);
-
- if (in_fields) free(in_fields);
-
- }
- else
- CCTK_WARN(3,"Reduction operation is not registered and cannot be called");
+ if (! function)
+ {
+ CCTK_WARN(3,"Reduction operation is not registered and cannot be called");
+ return;
}
+
+ /* Fill in the array of variable indices from the variable argument list */
+ in_fields = malloc (*num_in_fields * sizeof (int));
+ va_start(indices, num_in_fields);
+ for (i=0; i<*num_in_fields; i++)
+ in_fields[i] = *va_arg(indices,int *);
+ va_end(indices);
+
+ function (GH, *proc, *num_out_vals, *type_out_vals, out_vals,
+ *num_in_fields,in_fields);
+
+ free(in_fields);
- *fortranreturn= 1;
-
+ *fortranreturn = 0;
}
@@ -480,7 +479,7 @@ int CCTK_ReduceArray( cGH *GH,
if (operation_handle < 0)
{
CCTK_WARN(3,"Invalid handle passed to CCTK_ReduceArray");
- return (1);
+ return (-1);
}
function = (void (*)(REDUCTION_ARRAY_OPERATOR_REGISTER_ARGLIST))
@@ -490,7 +489,7 @@ int CCTK_ReduceArray( cGH *GH,
{
CCTK_WARN(3, "Array reduction operation is not registered "
"and cannot be called");
- return (1);
+ return (-1);
}
/* allocate memory for dims and input array pointers */
@@ -509,13 +508,14 @@ int CCTK_ReduceArray( cGH *GH,
va_end(indices);
- function (GH, proc, num_dims, dims, num_in_arrays, in_arrays, type_in_arrays,
+ function (GH, proc, num_dims, dims,
+ num_in_arrays, in_arrays, type_in_arrays,
num_out_vals, out_vals, type_out_vals);
free (in_arrays);
free (dims);
- return 0;
+ return (0);
}
void FMODIFIER FORTRAN_NAME(CCTK_ReduceArray)(int *fortran_return,
@@ -535,10 +535,11 @@ void FMODIFIER FORTRAN_NAME(CCTK_ReduceArray)(int *fortran_return,
int i;
int *dims;
void **in_arrays;
- void (*function)(REDUCTION_ARRAY_OPERATOR_REGISTER_ARGLIST)=NULL;
+ void (*function)(REDUCTION_ARRAY_OPERATOR_REGISTER_ARGLIST);
- *fortran_return = 1;
+ /* initialize return code to indicate an error */
+ *fortran_return = -1;
/* Get the pointer to the reduction operator */
if (*operation_handle < 0)
@@ -573,12 +574,13 @@ void FMODIFIER FORTRAN_NAME(CCTK_ReduceArray)(int *fortran_return,
va_end (varargs);
- function (GH, *proc, *num_dims, dims, *num_in_arrays, in_arrays,
- *type_in_arrays, *num_out_vals, out_vals, *type_out_vals);
+ function (GH, *proc, *num_dims, dims,
+ *num_in_arrays, in_arrays, *type_in_arrays,
+ *num_out_vals, out_vals, *type_out_vals);
free (in_arrays);
free (dims);
-
+
*fortran_return = 0;
}