Actual source code: mpi.c
1: /*
2: This provides a few of the MPI-uni functions that cannot be implemented
3: with C macros
4: */
5: #include include/mpiuni/mpi.h
7: #if defined (MPIUNI_USE_STDCALL)
8: #define MPIUNI_STDCALL __stdcall
9: #else
10: #define MPIUNI_STDCALL
11: #endif
13: #if defined(PETSC_HAVE_STDLIB_H)
14: #include <stdlib.h>
15: #endif
17: #define MPI_SUCCESS 0
18: #define MPI_FAILURE 1
19: void *MPIUNI_TMP = 0;
20: int MPIUNI_DATASIZE[5] = { sizeof(int),sizeof(float),sizeof(double),2*sizeof(double),sizeof(char)};
21: /*
22: With MPI Uni there is only one communicator, which is called 1.
23: */
24: #define MAX_ATTR 128
26: typedef struct {
27: void *extra_state;
28: void *attribute_val;
29: int active;
30: MPI_Delete_function *del;
31: } MPI_Attr;
33: static MPI_Attr attr[MAX_ATTR];
34: static int num_attr = 1,mpi_tag_ub = 100000000;
36: /*
37: To avoid problems with prototypes to the system memcpy() it is duplicated here
38: */
39: int MPIUNI_Memcpy(void *a,const void* b,int n) {
40: int i;
41: char *aa= (char*)a;
42: char *bb= (char*)b;
44: for (i=0; i<n; i++) aa[i] = bb[i];
45: return 0;
46: }
48: /*
49: Used to set the built-in MPI_TAG_UB attribute
50: */
51: static int Keyval_setup(void)
52: {
53: attr[0].active = 1;
54: attr[0].attribute_val = &mpi_tag_ub;
55: return 0;
56: }
58: /*
59: These functions are mapped to the Petsc_ name by ./mpi.h
60: */
61: int Petsc_MPI_Keyval_create(MPI_Copy_function *copy_fn,MPI_Delete_function *delete_fn,int *keyval,void *extra_state)
62: {
63: if (num_attr >= MAX_ATTR) MPI_Abort(MPI_COMM_WORLD,1);
65: attr[num_attr].extra_state = extra_state;
66: attr[num_attr].del = delete_fn;
67: *keyval = num_attr++;
68: return 0;
69: }
71: int Petsc_MPI_Keyval_free(int *keyval)
72: {
73: attr[*keyval].active = 0;
74: return MPI_SUCCESS;
75: }
77: int Petsc_MPI_Attr_put(MPI_Comm comm,int keyval,void *attribute_val)
78: {
79: attr[keyval].active = 1;
80: attr[keyval].attribute_val = attribute_val;
81: return MPI_SUCCESS;
82: }
83:
84: int Petsc_MPI_Attr_delete(MPI_Comm comm,int keyval)
85: {
86: if (attr[keyval].active && attr[keyval].del) {
87: (*(attr[keyval].del))(comm,keyval,attr[keyval].attribute_val,attr[keyval].extra_state);
88: }
89: attr[keyval].active = 0;
90: attr[keyval].attribute_val = 0;
91: return MPI_SUCCESS;
92: }
94: int Petsc_MPI_Attr_get(MPI_Comm comm,int keyval,void *attribute_val,int *flag)
95: {
96: if (!keyval) Keyval_setup();
97: *flag = attr[keyval].active;
98: *(int **)attribute_val = (int*)attr[keyval].attribute_val;
99: return MPI_SUCCESS;
100: }
102: static int dups = 0;
103: int Petsc_MPI_Comm_dup(MPI_Comm comm,MPI_Comm *out)
104: {
105: *out = comm;
106: dups++;
107: return 0;
108: }
110: int Petsc_MPI_Comm_free(MPI_Comm *comm)
111: {
112: int i;
114: if (--dups) return MPI_SUCCESS;
115: for (i=0; i<num_attr; i++) {
116: if (attr[i].active && attr[i].del) {
117: (*attr[i].del)(*comm,i,attr[i].attribute_val,attr[i].extra_state);
118: }
119: attr[i].active = 0;
120: }
121: return MPI_SUCCESS;
122: }
124: /* --------------------------------------------------------------------------*/
126: int Petsc_MPI_Abort(MPI_Comm comm,int errorcode)
127: {
128: abort();
129: return MPI_SUCCESS;
130: }
132: static int MPI_was_initialized = 0;
134: int Petsc_MPI_Initialized(int *flag)
135: {
136: *flag = MPI_was_initialized;
137: return 0;
138: }
140: int Petsc_MPI_Finalize(void)
141: {
142: MPI_was_initialized = 0;
143: return 0;
144: }
146: /* ------------------- Fortran versions of several routines ------------------ */
148: #if defined(__cplusplus)
150: #endif
152: /******mpi_init*******/
153: void MPIUNI_STDCALL mpi_init(int *ierr)
154: {
155: MPI_was_initialized = 1;
156: *MPI_SUCCESS;
157: }
159: void MPIUNI_STDCALL mpi_init_(int *ierr)
160: {
161: MPI_was_initialized = 1;
162: *MPI_SUCCESS;
163: }
165: void MPIUNI_STDCALL mpi_init__(int *ierr)
166: {
167: MPI_was_initialized = 1;
168: *MPI_SUCCESS;
169: }
171: void MPIUNI_STDCALL MPI_INIT(int *ierr)
172: {
173: MPI_was_initialized = 1;
174: *MPI_SUCCESS;
175: }
177: /******mpi_finalize*******/
178: void MPIUNI_STDCALL mpi_finalize(int *ierr)
179: {
180: *MPI_SUCCESS;
181: }
183: void MPIUNI_STDCALL mpi_finalize_(int *ierr)
184: {
185: *MPI_SUCCESS;
186: }
188: void MPIUNI_STDCALL mpi_finalize__(int *ierr)
189: {
190: *MPI_SUCCESS;
191: }
193: void MPIUNI_STDCALL MPI_FINALIZE(int *ierr)
194: {
195: *MPI_SUCCESS;
196: }
198: /******mpi_comm_size*******/
199: void MPIUNI_STDCALL mpi_comm_size(MPI_Comm *comm,int *size,int *ierr)
200: {
201: *size = 1;
202: *0;
203: }
205: void MPIUNI_STDCALL mpi_comm_size_(MPI_Comm *comm,int *size,int *ierr)
206: {
207: *size = 1;
208: *0;
209: }
211: void MPIUNI_STDCALL mpi_comm_size__(MPI_Comm *comm,int *size,int *ierr)
212: {
213: *size = 1;
214: *0;
215: }
217: void MPIUNI_STDCALL MPI_COMM_SIZE(MPI_Comm *comm,int *size,int *ierr)
218: {
219: *size = 1;
220: *0;
221: }
223: /******mpi_comm_rank*******/
224: void MPIUNI_STDCALL mpi_comm_rank(MPI_Comm *comm,int *rank,int *ierr)
225: {
226: *rank=0;
227: *ierr=MPI_SUCCESS;
228: }
230: void MPIUNI_STDCALL mpi_comm_rank_(MPI_Comm *comm,int *rank,int *ierr)
231: {
232: *rank=0;
233: *ierr=MPI_SUCCESS;
234: }
236: void MPIUNI_STDCALL mpi_comm_rank__(MPI_Comm *comm,int *rank,int *ierr)
237: {
238: *rank=0;
239: *ierr=MPI_SUCCESS;
240: }
242: void MPIUNI_STDCALL MPI_COMM_RANK(MPI_Comm *comm,int *rank,int *ierr)
243: {
244: *rank=0;
245: *ierr=MPI_SUCCESS;
246: }
248: /*******mpi_abort******/
249: void MPIUNI_STDCALL mpi_abort(MPI_Comm *comm,int *errorcode,int *ierr)
250: {
251: abort();
252: *MPI_SUCCESS;
253: }
255: void MPIUNI_STDCALL mpi_abort_(MPI_Comm *comm,int *errorcode,int *ierr)
256: {
257: abort();
258: *MPI_SUCCESS;
259: }
261: void MPIUNI_STDCALL mpi_abort__(MPI_Comm *comm,int *errorcode,int *ierr)
262: {
263: abort();
264: *MPI_SUCCESS;
265: }
267: void MPIUNI_STDCALL MPI_ABORT(MPI_Comm *comm,int *errorcode,int *ierr)
268: {
269: abort();
270: *MPI_SUCCESS;
271: }
272: /*******mpi_allreduce******/
273: void MPIUNI_STDCALL mpi_allreduce(void *sendbuf,void *recvbuf,int *count,int *datatype,int *op,int *comm,int *ierr)
274: {
275: MPIUNI_Memcpy(recvbuf,sendbuf,(*count)*MPIUNI_DATASIZE[*datatype]);
276: *MPI_SUCCESS;
277: }
278: void MPIUNI_STDCALL mpi_allreduce_(void *sendbuf,void *recvbuf,int *count,int *datatype,int *op,int *comm,int *ierr)
279: {
280: MPIUNI_Memcpy(recvbuf,sendbuf,(*count)*MPIUNI_DATASIZE[*datatype]);
281: *MPI_SUCCESS;
282: }
283: void MPIUNI_STDCALL mpi_allreduce__(void *sendbuf,void *recvbuf,int *count,int *datatype,int *op,int *comm,int *ierr)
284: {
285: MPIUNI_Memcpy(recvbuf,sendbuf,(*count)*MPIUNI_DATASIZE[*datatype]);
286: *MPI_SUCCESS;
287: }
288: void MPIUNI_STDCALL MPI_ALLREDUCE(void *sendbuf,void *recvbuf,int *count,int *datatype,int *op,int *comm,int *ierr)
289: {
290: MPIUNI_Memcpy(recvbuf,sendbuf,(*count)*MPIUNI_DATASIZE[*datatype]);
291: *MPI_SUCCESS;
292: }
295: #if defined(__cplusplus)
296: }
297: #endif