1 | |
---|
2 | |
---|
3 | #include "mpiP.h" |
---|
4 | |
---|
5 | |
---|
6 | /****************************************************************************/ |
---|
7 | |
---|
8 | static int initialized=0; |
---|
9 | |
---|
10 | |
---|
11 | /****************************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | /* |
---|
15 | * INIT/FINALIZE |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | FC_FUNC( mpi_init_fort , MPI_INIT_FORT) |
---|
22 | (int *f_MPI_COMM_WORLD, |
---|
23 | int *f_MPI_ANY_SOURCE, int *f_MPI_ANY_TAG, |
---|
24 | int *f_MPI_PROC_NULL, int *f_MPI_ROOT, |
---|
25 | int *f_MPI_COMM_NULL, int *f_MPI_REQUEST_NULL, |
---|
26 | int *f_MPI_GROUP_NULL, int *f_MPI_GROUP_EMPTY, |
---|
27 | int *f_MPI_UNDEFINED, |
---|
28 | int *f_MPI_MAX_ERROR_STRING, |
---|
29 | int *f_MPI_MAX_PROCESSOR_NAME, |
---|
30 | int *f_MPI_STATUS_SIZE, |
---|
31 | int *f_MPI_SOURCE, int *f_MPI_TAG, int *f_MPI_ERROR, |
---|
32 | int *f_status, |
---|
33 | int *fsource, int *ftag, int *ferror, |
---|
34 | int *f_MPI_INTEGER, void *fint1, void *fint2, |
---|
35 | int *f_MPI_LOGICAL, void *flog1, void *flog2, |
---|
36 | int *f_MPI_REAL, void *freal1, void *freal2, |
---|
37 | int *f_MPI_DOUBLE_PRECISION, |
---|
38 | void *fdub1, void *fdub2, |
---|
39 | int *f_MPI_COMPLEX, void *fcomp1, void *fcomp2, |
---|
40 | int *ierror) |
---|
41 | { |
---|
42 | int err; |
---|
43 | int size; |
---|
44 | int offset; |
---|
45 | |
---|
46 | *ierror=MPI_Init(NULL,NULL); |
---|
47 | |
---|
48 | err=0; |
---|
49 | |
---|
50 | /* |
---|
51 | * These 3 macros compare things from mpif.h (as passed in by the f_ |
---|
52 | * arguments) to the values in C (from #including mpi.h). |
---|
53 | * |
---|
54 | * Unfortunately, this kind of thing is done most easily in a nasty |
---|
55 | * looking macto. |
---|
56 | * |
---|
57 | */ |
---|
58 | |
---|
59 | |
---|
60 | /* |
---|
61 | * verify_eq |
---|
62 | * compare value of constants in C and fortran |
---|
63 | * i.e. compare *f_<name> to <name> |
---|
64 | */ |
---|
65 | |
---|
66 | #define verify_eq(name) \ |
---|
67 | if (*f_##name != name) \ |
---|
68 | { fprintf(stderr,"mpi-serial: mpi_init_fort: %s not consistant " \ |
---|
69 | "between mpif.h (%d) and mpi.h (%d)\n",\ |
---|
70 | #name,*f_##name,name); \ |
---|
71 | err=1; } |
---|
72 | |
---|
73 | #define verify_eq_warn(name) \ |
---|
74 | if (*f_##name != name) \ |
---|
75 | { fprintf(stderr,"mpi-serial: mpi_init_fort: warning: %s not consistant " \ |
---|
76 | "between mpif.h (%d) and mpi.h (%d)\n",\ |
---|
77 | #name,*f_##name,name); \ |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | /* |
---|
82 | * verify_size |
---|
83 | * verify that the type name in fortran has the correct |
---|
84 | * value (i.e. the size of that data type). |
---|
85 | * Determine size by subtracting the pointer values of two |
---|
86 | * consecutive array locations. |
---|
87 | */ |
---|
88 | |
---|
89 | #define verify_size(name,p1,p2) \ |
---|
90 | if ( (size=((char *)(p2) - (char *)(p1))) != *f_##name ) \ |
---|
91 | { fprintf(stderr,"mpi-serial: mpi_init_fort: mpif.h %s (%d) " \ |
---|
92 | "does not match actual fortran size (%d)\n", \ |
---|
93 | #name,*f_##name,size); \ |
---|
94 | err=1; } |
---|
95 | |
---|
96 | /* |
---|
97 | * verify_field |
---|
98 | * check the struct member offsets for MPI_Status vs. the |
---|
99 | * fortan integer array offsets. E.g. the location of |
---|
100 | * status->MPI_SOURCE should be the same as STATUS(MPI_SOURCE) |
---|
101 | */ |
---|
102 | |
---|
103 | #define verify_field(name) \ |
---|
104 | { offset= (char *)&((MPI_Status *)f_status)->name - (char *)f_status; \ |
---|
105 | if ( offset != (*f_##name-1)*sizeof(int) ) \ |
---|
106 | { fprintf(stderr,"mpi-serial: mpi_init_fort: mpif.h %s (%d) (%d bytes) " \ |
---|
107 | "is inconsistant w/offset in MPI_Status (%d bytes)\n", \ |
---|
108 | #name,*f_##name,(*f_##name-1)*sizeof(int),offset); \ |
---|
109 | err=1; }} |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | verify_eq(MPI_COMM_WORLD); |
---|
114 | verify_eq(MPI_ANY_SOURCE); |
---|
115 | verify_eq(MPI_ANY_TAG); |
---|
116 | verify_eq(MPI_PROC_NULL); |
---|
117 | verify_eq(MPI_ROOT); |
---|
118 | verify_eq(MPI_COMM_NULL); |
---|
119 | verify_eq(MPI_REQUEST_NULL); |
---|
120 | verify_eq(MPI_GROUP_NULL); |
---|
121 | verify_eq(MPI_GROUP_EMPTY); |
---|
122 | verify_eq(MPI_UNDEFINED); |
---|
123 | verify_eq(MPI_MAX_ERROR_STRING); |
---|
124 | verify_eq(MPI_MAX_PROCESSOR_NAME); |
---|
125 | |
---|
126 | verify_eq(MPI_STATUS_SIZE); |
---|
127 | verify_field(MPI_SOURCE); |
---|
128 | verify_field(MPI_TAG); |
---|
129 | verify_field(MPI_ERROR); |
---|
130 | |
---|
131 | verify_eq(MPI_INTEGER); |
---|
132 | verify_size(MPI_INTEGER,fint1,fint2); |
---|
133 | |
---|
134 | verify_size(MPI_LOGICAL,flog1,flog2); |
---|
135 | |
---|
136 | verify_eq_warn(MPI_REAL); |
---|
137 | verify_size(MPI_REAL,freal1,freal2); |
---|
138 | |
---|
139 | verify_eq(MPI_DOUBLE_PRECISION); |
---|
140 | verify_size(MPI_DOUBLE_PRECISION,fdub1,fdub2); |
---|
141 | |
---|
142 | verify_size(MPI_COMPLEX,fcomp1,fcomp2); |
---|
143 | |
---|
144 | if (err) |
---|
145 | abort(); |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | int MPI_Init(int *argc, char **argv[]) |
---|
151 | { |
---|
152 | MPI_Comm my_comm_world; |
---|
153 | |
---|
154 | if (sizeof(MPI_Aint) < sizeof(void *)) |
---|
155 | { |
---|
156 | fprintf(stderr, "mpi-serial: MPI_Init: " |
---|
157 | "MPI_Aint is not large enough for void *\n"); |
---|
158 | abort(); |
---|
159 | } |
---|
160 | |
---|
161 | my_comm_world=mpi_comm_new(); |
---|
162 | |
---|
163 | if (my_comm_world != MPI_COMM_WORLD) |
---|
164 | { |
---|
165 | fprintf(stderr,"MPI_Init: conflicting MPI_COMM_WORLD\n"); |
---|
166 | abort(); |
---|
167 | } |
---|
168 | |
---|
169 | initialized=1; |
---|
170 | return(MPI_SUCCESS); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | /*********/ |
---|
175 | |
---|
176 | |
---|
177 | FC_FUNC( mpi_finalize, MPI_FINALIZE )(int *ierror) |
---|
178 | { |
---|
179 | *ierror=MPI_Finalize(); |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | /* |
---|
184 | * MPI_Finalize() |
---|
185 | * |
---|
186 | * this library doesn't support re-initializing MPI, so |
---|
187 | * the finalize will just leave everythign as it is... |
---|
188 | * |
---|
189 | */ |
---|
190 | |
---|
191 | |
---|
192 | int MPI_Finalize(void) |
---|
193 | { |
---|
194 | initialized=0; |
---|
195 | |
---|
196 | mpi_destroy_handles(); |
---|
197 | |
---|
198 | return(MPI_SUCCESS); |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | /*********/ |
---|
203 | |
---|
204 | |
---|
205 | FC_FUNC( mpi_abort , MPI_ABORT )(int *comm, int *errorcode, int *ierror) |
---|
206 | { |
---|
207 | *ierror=MPI_Abort( *comm, *errorcode); |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | int MPI_Abort(MPI_Comm comm, int errorcode) |
---|
213 | { |
---|
214 | fprintf(stderr,"MPI_Abort: error code = %d\n",errorcode); |
---|
215 | exit(errorcode); |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | /*********/ |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | FC_FUNC( mpi_error_string , MPI_ERROR_STRING) |
---|
224 | (int *errorcode, char *string, |
---|
225 | int *resultlen, int *ierror) |
---|
226 | { |
---|
227 | *ierror=MPI_Error_string(*errorcode, string, resultlen); |
---|
228 | } |
---|
229 | |
---|
230 | |
---|
231 | int MPI_Error_string(int errorcode, char *string, int *resultlen) |
---|
232 | { |
---|
233 | sprintf(string,"MPI Error: code %d\n",errorcode); |
---|
234 | *resultlen=strlen(string); |
---|
235 | |
---|
236 | return(MPI_SUCCESS); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | /*********/ |
---|
241 | |
---|
242 | |
---|
243 | FC_FUNC( mpi_get_processor_name , MPI_GET_PROCESSOR_NAME ) |
---|
244 | (char *name, int *resultlen, int *ierror) |
---|
245 | { |
---|
246 | *ierror=MPI_Get_processor_name(name,resultlen); |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | int MPI_Get_processor_name(char *name, int *resultlen) |
---|
251 | { |
---|
252 | int ret; |
---|
253 | |
---|
254 | ret=gethostname(name,MPI_MAX_PROCESSOR_NAME); |
---|
255 | |
---|
256 | if (ret!=0) |
---|
257 | strncpy(name,"unknown host name",MPI_MAX_PROCESSOR_NAME); |
---|
258 | |
---|
259 | |
---|
260 | name[MPI_MAX_PROCESSOR_NAME-1]='\0'; /* make sure NULL terminated */ |
---|
261 | *resultlen=strlen(name); |
---|
262 | |
---|
263 | return(MPI_SUCCESS); |
---|
264 | } |
---|
265 | |
---|
266 | |
---|
267 | /*********/ |
---|
268 | |
---|
269 | |
---|
270 | FC_FUNC( mpi_initialized , MPI_INITIALIZED )(int *flag, int *ierror) |
---|
271 | { |
---|
272 | *ierror=MPI_Initialized(flag); |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | int MPI_Initialized(int *flag) |
---|
277 | { |
---|
278 | *flag= initialized; |
---|
279 | |
---|
280 | return(MPI_SUCCESS); |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | |
---|