summaryrefslogtreecommitdiff
path: root/src/comm/RegisterCommFunction.c
blob: 51f099dee5c9ab58f899a5efbd242a7f9ea29249 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 /*@@
   @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;
}