forked from jeffhammond/foMPI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfompi_fortran.c
630 lines (420 loc) · 25.1 KB
/
fompi_fortran.c
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
// Copyright (c) 2012 The Trustees of University of Illinois. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string.h>
#include "fompi.h"
// this should really be dome by autoconf but I don't have the time right now
#define F77_FUNC_(name,NAME) name ## _
/* some helper functions */
static inline void insert_free_elem( int index, fortran_free_mem_t **list_head ) {
fortran_free_mem_t *entry;
entry = _foMPI_ALLOC( sizeof(fortran_free_mem_t) );
entry->index = index;
entry->next = *list_head;
*list_head = entry;
}
static inline int get_winidx() {
// if we don't have a window table yet ... allocate it
int winidx;
int i;
if(glob_info.Fortran_Windows == NULL) {
winidx=0;
glob_info.Fortran_Windows = (foMPI_Win*)_foMPI_ALLOC(sizeof(foMPI_Win) * glob_info.Fortran_win_sz);
for (i=glob_info.Fortran_win_sz-1; i>0; i--) {
insert_free_elem( i, &(glob_info.Fortran_free_win) );
}
} else {
winidx = get_free_elem( &(glob_info.Fortran_free_win) );
if(winidx == -1) {
winidx = glob_info.Fortran_win_sz;
glob_info.Fortran_win_sz += 100;
glob_info.Fortran_Windows = realloc( glob_info.Fortran_Windows, glob_info.Fortran_win_sz * sizeof(foMPI_Win) );
for (i = glob_info.Fortran_win_sz-1; i>winidx /* old Fortran_win_sz value */; i--) {
insert_free_elem( i, &(glob_info.Fortran_free_win) );
}
}
}
return winidx;
}
static inline int get_reqidx() {
// if we don't have a request table yet ... allocate it
int reqidx;
int i;
if(glob_info.Fortran_Requests == NULL) {
reqidx = 0;
glob_info.Fortran_Requests = (foMPI_Request*)_foMPI_ALLOC(sizeof(foMPI_Request)*glob_info.Fortran_req_sz);
for (i=glob_info.Fortran_req_sz-1; i>0; i--) {
insert_free_elem( i, &(glob_info.Fortran_free_req) );
}
} else {
reqidx = get_free_elem( &(glob_info.Fortran_free_req) );
if(reqidx == -1) {
reqidx = glob_info.Fortran_req_sz;
glob_info.Fortran_req_sz += 100;
glob_info.Fortran_Requests = realloc( glob_info.Fortran_Requests, glob_info.Fortran_req_sz * sizeof(foMPI_Request) );
for (i = glob_info.Fortran_req_sz-1; i>reqidx /* old Fortran_req_sz value */; i--) {
insert_free_elem( i, &(glob_info.Fortran_free_req) );
}
}
}
return reqidx;
}
/* now for the real Fortran binding code */
/* TODO: remove after MPI bug on test machine is fixed */
void F77_FUNC_(fompi_get_address,FOMPI_GET_ADDRESS)(void *location, MPI_Aint *address, int *ierr);
void F77_FUNC_(fompi_get_address,FOMPI_GET_ADDRESS)(void *location, MPI_Aint *address, int *ierr) {
*ierr = MPI_Get_address( location, address );
}
//=============================================================================
//============================ Window Creation ================================
//=============================================================================
void F77_FUNC_(fompi_win_create,FOMPI_WIN_CREATE)(void *base, MPI_Aint *size, int *disp_unit, int *info, int *comm, int *win, int *ierr);
void F77_FUNC_(fompi_win_create,FOMPI_WIN_CREATE)(void *base, MPI_Aint *size, int *disp_unit, int *info, int *icomm, int *win, int *ierr) {
*win = get_winidx();
MPI_Comm comm;
comm = MPI_Comm_f2c(*icomm);
MPI_Info c_info = MPI_Info_f2c( *info );
// this is also very suboptimal
*ierr = foMPI_Win_create(base, *size, *disp_unit, c_info, comm, &glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_win_allocate,FOMPI_WIN_ALLOCATE)(MPI_Aint *size, int *disp_unit, int *info, int *comm, MPI_Aint *baseptr, int *win, int *ierr);
void F77_FUNC_(fompi_win_allocate,FOMPI_WIN_ALLOCATE)(MPI_Aint *size, int *disp_unit, int *info, int *comm, MPI_Aint *baseptr, int *win, int *ierr) {
*win = get_winidx();
void* ptr;
MPI_Info c_info = MPI_Info_f2c( *info );
MPI_Comm c_comm = MPI_Comm_f2c( *comm );
*ierr = foMPI_Win_allocate( *size, *disp_unit, c_info, c_comm, &ptr, &(glob_info.Fortran_Windows[*win]));
*baseptr = (MPI_Aint) ptr;
}
void F77_FUNC_(fompi_win_allocate_cptr,FOMPI_WIN_ALLOCATE_CPTR)(MPI_Aint *size, int *disp_unit, int *info, int *comm, void **baseptr, int *win, int *ierr);
void F77_FUNC_(fompi_win_allocate_cptr,FOMPI_WIN_ALLOCATE_CPTR)(MPI_Aint *size, int *disp_unit, int *info, int *comm, void **baseptr, int *win, int *ierr) {
*win = get_winidx();
MPI_Info c_info = MPI_Info_f2c( *info );
MPI_Comm c_comm = MPI_Comm_f2c( *comm );
*ierr = foMPI_Win_allocate( *size, *disp_unit, c_info, c_comm, baseptr, &(glob_info.Fortran_Windows[*win]));
}
void F77_FUNC_(fompi_win_create_dynamic,FOMPI_WIN_CREATE_DYNAMIC)(int *info, int *comm, int *win, int *ierr);
void F77_FUNC_(fompi_win_create_dynamic,FOMPI_WIN_CREATE_DYNAMIC)(int *info, int *icomm, int *win, int *ierr) {
*win = get_winidx();
MPI_Comm comm;
comm = MPI_Comm_f2c(*icomm);
MPI_Info c_info = MPI_Info_f2c( *info );
// this is also very suboptimal
*ierr = foMPI_Win_create_dynamic(c_info, comm, &(glob_info.Fortran_Windows[*win]));
}
void F77_FUNC_(fompi_win_free,FOMPI_WIN_FREE)(int *win, int *ierr);
void F77_FUNC_(fompi_win_free,FOMPI_WIN_FREE)(int *win, int *ierr) {
*ierr = foMPI_Win_free(&glob_info.Fortran_Windows[*win]);
// Fortran_Windows[*win] = foMPI_WIN_NULL; already done by foMPI_Win_free
insert_free_elem( *win, &(glob_info.Fortran_free_win) );
*win = -1; // constant fompi_win_null in fortran
}
void F77_FUNC_(fompi_win_attach,FOMPI_WIN_ATTACH)(int *win, void *base, MPI_Aint *size, int *ierr);
void F77_FUNC_(fompi_win_attach,FOMPI_WIN_ATTACH)(int *win, void *base, MPI_Aint *size, int *ierr) {
*ierr = foMPI_Win_attach( glob_info.Fortran_Windows[*win], base, *size );
}
void F77_FUNC_(fompi_win_detach,FOMPI_WIN_DETACH)(int *win, void *base, int *ierr);
void F77_FUNC_(fompi_win_detach,FOMPI_WIN_DETACH)(int *win, void *base, int *ierr) {
*ierr = foMPI_Win_detach( glob_info.Fortran_Windows[*win], base );
}
//=============================================================================
//========================== Global Synchronization ===========================
//=============================================================================
void F77_FUNC_(fompi_win_fence,FOMPI_WIN_FENCE)(int *assert, int *win, int *ierr);
void F77_FUNC_(fompi_win_fence,FOMPI_WIN_FENCE)(int *assert, int *win, int *ierr) {
*ierr = foMPI_Win_fence(*assert, glob_info.Fortran_Windows[*win]);
}
//=============================================================================
//==================== General Active Target Synchronization ==================
//=============================================================================
void F77_FUNC_(fompi_win_start,FOMPI_WIN_START)(int *group, int *assert, int *win, int *ierr);
void F77_FUNC_(fompi_win_start,FOMPI_WIN_START)(int *group, int *assert, int *win, int *ierr) {
MPI_Group c_group = MPI_Group_f2c( *group );
*ierr = foMPI_Win_start( c_group, *assert, glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_complete,FOMPI_WIN_COMPLETE)(int *win, int *ierr);
void F77_FUNC_(fompi_win_complete,FOMPI_WIN_COMPLETE)(int *win, int *ierr) {
*ierr = foMPI_Win_complete( glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_post,FOMPI_WIN_POST)(int* group, int *assert, int *win, int *ierr);
void F77_FUNC_(fompi_win_post,FOMPI_WIN_POST)(int* group, int *assert, int *win, int *ierr) {
MPI_Group c_group = MPI_Group_f2c( *group );
*ierr = foMPI_Win_post( c_group, *assert, glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_wait,FOMPI_WIN_WAIT)(int *win, int *ierr);
void F77_FUNC_(fompi_win_wait,FOMPI_WIN_WAIT)(int *win, int *ierr) {
*ierr = foMPI_Win_wait( glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_test,FOMPI_WIN_TEST)(int *win, int *flag, int *ierr);
void F77_FUNC_(fompi_win_test,FOMPI_WIN_TEST)(int *win, int *flag, int *ierr) {
*ierr = foMPI_Win_test( glob_info.Fortran_Windows[*win], flag );
}
//=============================================================================
//======================= Passive Target Synchronization ======================
//=============================================================================
void F77_FUNC_(fompi_win_lock,FOMPI_WIN_LOCK)(int *type, int *rank, int *assert, int *win, int *ierr);
void F77_FUNC_(fompi_win_lock,FOMPI_WIN_LOCK)(int *type, int *rank, int *assert, int *win, int *ierr) {
*ierr = foMPI_Win_lock(*type, *rank, *assert, glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_win_unlock,FOMPI_WIN_UNLOCK)(int *rank, int *win, int *ierr);
void F77_FUNC_(fompi_win_unlock,FOMPI_WIN_UNLOCK)(int *rank, int *win, int *ierr) {
*ierr = foMPI_Win_unlock(*rank, glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_win_lock_all,FOMPI_WIN_LOCK_ALL)(int *assert, int *win, int *ierr);
void F77_FUNC_(fompi_win_lock_all,FOMPI_WIN_LOCK_ALL)(int *assert, int *win, int *ierr) {
*ierr = foMPI_Win_lock_all( *assert, glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_unlock_all,FOMPI_WIN_UNLOCK_ALL)(int *win, int *ierr);
void F77_FUNC_(fompi_win_unlock_all,FOMPI_WIN_UNLOCK_ALL)(int *win, int *ierr) {
*ierr = foMPI_Win_unlock_all( glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_flush,FOMPI_WIN_FLUSH)( int *rank, int *win, int *ierr );
void F77_FUNC_(fompi_win_flush,FOMPI_WIN_FLUSH)( int *rank, int *win, int *ierr ) {
*ierr = foMPI_Win_flush( *rank, glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_flush_all,FOMPI_WIN_FLUSH_ALL)( int *win, int *ierr );
void F77_FUNC_(fompi_win_flush_all,FOMPI_WIN_FLUSH_ALL)( int *win, int *ierr ) {
*ierr = foMPI_Win_flush_all( glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_flush_local,FOMPI_WIN_FLUSH_LOCAL)( int *rank, int *win, int *ierr );
void F77_FUNC_(fompi_win_flush_local,FOMPI_WIN_FLUSH_LOCAL)( int *rank, int *win, int *ierr ) {
*ierr = foMPI_Win_flush_local( *rank, glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_flush_local_all,FOMPI_WIN_FLUSH_LOCAL_ALL)( int *win, int *ierr );
void F77_FUNC_(fompi_win_flush_local_all,FOMPI_WIN_FLUSH_LOCAL_ALL)( int *win, int *ierr ) {
*ierr = foMPI_Win_flush_local_all( glob_info.Fortran_Windows[*win] );
}
void F77_FUNC_(fompi_win_sync,FOMPI_WIN_SYNC)( int *win, int *ierr );
void F77_FUNC_(fompi_win_sync,FOMPI_WIN_SYNC)( int *win, int *ierr ) {
*ierr = foMPI_Win_sync( glob_info.Fortran_Windows[*win] );
}
//=============================================================================
//======================= Bulk Completed Communication ========================
//=============================================================================
void F77_FUNC_(fompi_put,FOMPI_PUT)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *ierr);
void F77_FUNC_(fompi_put,FOMPI_PUT)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *ierr){
MPI_Datatype otype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
ttype = MPI_Type_f2c(*target_datatype);
*ierr = foMPI_Put(origin_addr, *origin_count, otype, *target_rank, *target_disp, *target_count, ttype, glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_get,FOMPI_GET)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *ierr);
void F77_FUNC_(fompi_get,FOMPI_GET)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *ierr){
MPI_Datatype otype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
ttype = MPI_Type_f2c(*target_datatype);
*ierr = foMPI_Get(origin_addr, *origin_count, otype, *target_rank, *target_disp, *target_count, ttype, glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_accumulate,FOMPI_ACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank,
MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *ierr);
void F77_FUNC_(fompi_accumulate,FOMPI_ACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank,
MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *ierr){
MPI_Datatype otype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
ttype = MPI_Type_f2c(*target_datatype);
foMPI_Op mop;
mop = *op;//MPI_Op_f2c(*op); not for now, since we use foMPI prefix operators
*ierr = foMPI_Accumulate(origin_addr, *origin_count, otype, *target_rank, *target_disp, *target_count, ttype, mop, glob_info.Fortran_Windows[*win]);
foMPI_Win_flush(*target_rank, glob_info.Fortran_Windows[*win]); /* TODO: Why is this here? */
}
void F77_FUNC_(fompi_get_accumulate,FOMPI_GET_ACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, void *result_addr, int *result_count, int *result_datatype,
int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *ierr);
void F77_FUNC_(fompi_get_accumulate,FOMPI_GET_ACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, void *result_addr, int *result_count, int *result_datatype,
int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *ierr) {
MPI_Datatype otype, rtype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
rtype = MPI_Type_f2c(*result_datatype);
ttype = MPI_Type_f2c(*target_datatype);
foMPI_Op mop;
mop = *op;//MPI_Op_f2c(*op); not for now, since we use foMPI prefix operators
*ierr = foMPI_Get_accumulate(origin_addr, *origin_count, otype, result_addr, *result_count, rtype, *target_rank, *target_disp, *target_count, ttype, mop, glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_compare_and_swap,FOMPI_COMPARE_AND_SWAP)(void *origin_addr, void *compare_addr, void *result_addr, int *datatype, int *target_rank, MPI_Aint *target_disp, int *win, int *ierr);
void F77_FUNC_(fompi_compare_and_swap,FOMPI_COMPARE_AND_SWAP)(void *origin_addr, void *compare_addr, void *result_addr, int *datatype, int *target_rank, MPI_Aint *target_disp, int *win, int *ierr) {
MPI_Datatype dtype;
dtype = MPI_Type_f2c(*datatype);
*ierr = foMPI_Compare_and_swap(origin_addr, compare_addr, result_addr, dtype, *target_rank, *target_disp, glob_info.Fortran_Windows[*win]);
}
void F77_FUNC_(fompi_fetch_and_op,FOMPI_FETCH_AND_OP)(void *origin_addr, void *result_addr, int *datatype, int *target_rank, MPI_Aint *target_disp, int *op, int *win, int *ierr);
void F77_FUNC_(fompi_fetch_and_op,FOMPI_FETCH_AND_OP)(void *origin_addr, void *result_addr, int *datatype, int *target_rank, MPI_Aint *target_disp, int *op, int *win, int *ierr) {
MPI_Datatype dtype;
dtype = MPI_Type_f2c(*datatype);
foMPI_Op mop;
mop = *op;//MPI_Op_f2c(*op); not for now, since we use foMPI prefix operators
*ierr = foMPI_Fetch_and_op(origin_addr, result_addr, dtype, *target_rank, *target_disp, mop, glob_info.Fortran_Windows[*win]);
}
//=============================================================================
//======================= Request Based Communication =========================
//=============================================================================
void F77_FUNC_(fompi_rput,FOMPI_RPUT)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *request, int *ierr);
void F77_FUNC_(fompi_rput,FOMPI_RPUT)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *request, int *ierr){
MPI_Datatype otype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
ttype = MPI_Type_f2c(*target_datatype);
*request = get_reqidx();
*ierr = foMPI_Rput(origin_addr, *origin_count, otype, *target_rank, *target_disp, *target_count, ttype, glob_info.Fortran_Windows[*win], &glob_info.Fortran_Requests[*request]);
}
void F77_FUNC_(fompi_rget,FOMPI_RGET)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *request, int *ierr);
void F77_FUNC_(fompi_rget,FOMPI_RGET)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *win, int *request, int *ierr){
MPI_Datatype otype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
ttype = MPI_Type_f2c(*target_datatype);
*request = get_reqidx();
*ierr = foMPI_Rget(origin_addr, *origin_count, otype, *target_rank, *target_disp, *target_count, ttype, glob_info.Fortran_Windows[*win], &glob_info.Fortran_Requests[*request]);
}
void F77_FUNC_(fompi_raccumulate,FOMPI_RACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank,
MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *request, int *ierr);
void F77_FUNC_(fompi_raccumulate,FOMPI_RACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, int *target_rank,
MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *request, int *ierr){
MPI_Datatype otype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
ttype = MPI_Type_f2c(*target_datatype);
foMPI_Op mop;
mop = *op;//MPI_Op_f2c(*op); not for now, since we use foMPI prefix operators
*request = get_reqidx();
*ierr = foMPI_Raccumulate(origin_addr, *origin_count, otype, *target_rank, *target_disp, *target_count, ttype, mop, glob_info.Fortran_Windows[*win], &glob_info.Fortran_Requests[*request]);
}
void F77_FUNC_(fompi_rget_accumulate,FOMPI_RGET_ACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, void *result_addr, int *result_count, int *result_datatype,
int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *request, int *ierr);
void F77_FUNC_(fompi_rget_accumulate,FOMPI_RGET_ACCUMULATE)(void *origin_addr, int *origin_count, int *origin_datatype, void *result_addr, int *result_count, int *result_datatype,
int *target_rank, MPI_Aint *target_disp, int *target_count, int *target_datatype, int *op, int *win, int *request, int *ierr) {
MPI_Datatype otype, rtype, ttype;
otype = MPI_Type_f2c(*origin_datatype);
rtype = MPI_Type_f2c(*result_datatype);
ttype = MPI_Type_f2c(*target_datatype);
foMPI_Op mop;
mop = *op;//MPI_Op_f2c(*op); not for now, since we use foMPI prefix operators
*request = get_reqidx();
*ierr = foMPI_Rget_accumulate(origin_addr, *origin_count, otype, result_addr, *result_count, rtype, *target_rank, *target_disp, *target_count, ttype, mop, glob_info.Fortran_Windows[*win], &glob_info.Fortran_Requests[*request]);
}
//=============================================================================
//============================= Window Attributes =============================
//=============================================================================
void F77_FUNC_(fompi_win_get_group, FOMPI_WIN_GET_GROUP)( int *win, int *group, int *ierr );
void F77_FUNC_(fompi_win_get_group, FOMPI_WIN_GET_GROUP)( int *win, int *group, int *ierr ) {
MPI_Group c_group;
*ierr = foMPI_Win_get_group( glob_info.Fortran_Windows[*win], &c_group );
*group = MPI_Group_c2f( c_group );
MPI_Group_free( &c_group );
}
void F77_FUNC_(fompi_win_set_name,FOMPI_WIN_SET_NAME)(int *win, char *win_name, int *ierr, int len);
void F77_FUNC_(fompi_win_set_name,FOMPI_WIN_SET_NAME)(int *win, char *iwin_name, int *ierr, int len) {
char* c_win_name = _foMPI_ALLOC( (len+1) * sizeof(char) );
memcpy( c_win_name, iwin_name, len );
c_win_name[len] = '\0';
int i;
/* remove padding */
for (i=len-1; i>=0; i--) {
if (c_win_name[i] == ' ') {
c_win_name[i] = '\0';
} else {
break;
}
}
*ierr = foMPI_Win_set_name( glob_info.Fortran_Windows[*win], c_win_name );
_foMPI_FREE( c_win_name );
}
void F77_FUNC_(fompi_win_get_name,FOMPI_WIN_GET_NAME)(int *win, char *win_name, int *resultlen, int *ierr, int len);
void F77_FUNC_(fompi_win_get_name,FOMPI_WIN_GET_NAME)(int *win, char *iwin_name, int *resultlen, int *ierr, int len) {
char* c_win_name = _foMPI_ALLOC( (len+1) * sizeof(char) );
*ierr = foMPI_Win_get_name( glob_info.Fortran_Windows[*win], c_win_name, resultlen );
int minimum;
if (*resultlen > len) {
minimum = len;
} else {
minimum = *resultlen;
}
memcpy( iwin_name, c_win_name, minimum );
int i;
/* add padding */
for( i = minimum ; i<len ; i++ ) {
iwin_name[i] = ' ';
}
_foMPI_FREE( c_win_name );
}
void F77_FUNC_(fompi_win_create_keyval,FOMPI_WIN_CREATE_KEYVAL)(MPI_Win_copy_attr_function *win_copy_attr_fn, MPI_Win_delete_attr_function *win_delete_attr_fn,
int *win_keyval, MPI_Aint *extra_state, int *ierr);
void F77_FUNC_(fompi_win_create_keyval,FOMPI_WIN_CREATE_KEYVAL)(MPI_Win_copy_attr_function *win_copy_attr_fn, MPI_Win_delete_attr_function *win_delete_attr_fn,
int *win_keyval, MPI_Aint *extra_state, int *ierr) {
*ierr = foMPI_Win_create_keyval( win_copy_attr_fn, win_delete_attr_fn, win_keyval, extra_state );
}
void F77_FUNC_(fompi_win_free_keyval,FOMPI_WIN_FREE_KEYVAL)(int *win_keyval, int *ierr) {
*ierr = foMPI_Win_free_keyval( win_keyval );
}
void F77_FUNC_(fompi_win_set_attr,FOMPI_WIN_SET_ATTR)(int* win, int *win_keyval, MPI_Aint *attribute_val, int *ierr);
void F77_FUNC_(fompi_win_set_attr,FOMPI_WIN_SET_ATTR)(int* win, int *win_keyval, MPI_Aint *attribute_val, int *ierr) {
*ierr = foMPI_Win_set_attr( glob_info.Fortran_Windows[*win], *win_keyval, (void*) *attribute_val );
}
void F77_FUNC_(fompi_win_get_attr,FOMPI_WIN_GET_ATTR)(int *win, int *win_keyval, MPI_Aint *attribute_val, int *flag, int *ierr);
void F77_FUNC_(fompi_win_get_attr,FOMPI_WIN_GET_ATTR)(int *win, int *win_keyval, MPI_Aint *attribute_val, int *flag, int *ierr) {
void *addr;
int int_attribute;
switch (*win_keyval) {
case foMPI_WIN_BASE:
*ierr = foMPI_Win_get_attr( glob_info.Fortran_Windows[*win], *win_keyval, &addr, flag );
*attribute_val = (MPI_Aint) addr;
break;
case foMPI_WIN_SIZE:
*ierr = foMPI_Win_get_attr( glob_info.Fortran_Windows[*win], *win_keyval, attribute_val, flag );
break;
default:
*ierr = foMPI_Win_get_attr( glob_info.Fortran_Windows[*win], *win_keyval, &int_attribute, flag );
*attribute_val = int_attribute;
break;
}
}
void F77_FUNC_(fompi_win_delete_attr,FOMPI_WIN_DELETE_ATTR)(int *win, int *win_keyval, int *ierr);
void F77_FUNC_(fompi_win_delete_attr,FOMPI_WIN_DELETE_ATTR)(int *win, int *win_keyval, int *ierr) {
*ierr = foMPI_Win_delete_attr( glob_info.Fortran_Windows[*win], *win_keyval );
}
//=============================================================================
//============================ Overloaded Functions ===========================
//=============================================================================
// TODO: this should also be done more carefully (see libnbc's handling) -- no time
void F77_FUNC_(fompi_init,FOMPI_INIT)(int *ierr);
void F77_FUNC_(fompi_init,FOMPI_INIT)(int *ierr) {
*ierr = foMPI_Init( NULL, NULL);
}
void F77_FUNC_(fompi_finalize,FOMPI_FINALIZE)(int *ierr);
void F77_FUNC_(fompi_finalize,FOMPI_FINALIZE)(int *ierr) {
*ierr = foMPI_Finalize();
}
/* we can't actual recognize MPI_STATUS_IGNORE, but since MPI_STATUS_IGNORE in Fortran is also an integer array of MPI_STATUS_SIZE, we fill it anyway */
void F77_FUNC_(fompi_wait,FOMPI_WAIT)(int *request, int *status, int *ierr);
void F77_FUNC_(fompi_wait,FOMPI_WAIT)(int *request, int *status, int *ierr) {
MPI_Status c_status;
*ierr = foMPI_Wait( &(glob_info.Fortran_Requests[*request]), &c_status );
if (*ierr == MPI_SUCCESS) {
//according to mpif.h: PARAMETER (MPI_SOURCE=3,MPI_TAG=4,MPI_ERROR=5)
//really ugly
status[2] = c_status.MPI_SOURCE;
status[3] = c_status.MPI_TAG;
status[4] = c_status.MPI_ERROR;
//Fortan_Requests[*request] = foMPI_REQUEST_NULL; already done by foMPI_Wait
insert_free_elem( *request, &glob_info.Fortran_free_req );
*request = -1; /* equivalent to fompi_request_null in fompif.h */
}
}
/* we can't actual recognize MPI_STATUS_IGNORE, but since MPI_STATUS_IGNORE in Fortran is also an integer array of MPI_STATUS_SIZE, we fill it anyway */
void F77_FUNC_(fompi_test,FOMPI_TEST)(int *request, int *flag, int *status, int *ierr);
void F77_FUNC_(fompi_test,FOMPI_TEST)(int *request, int *flag, int *status, int *ierr) {
MPI_Status c_status;
*flag = 0;
*ierr = foMPI_Test( &(glob_info.Fortran_Requests[*request]), flag, &c_status );
if( (*ierr == MPI_SUCCESS) && ( *flag != 0 ) ) {
//according to mpif.h: PARAMETER (MPI_SOURCE=3,MPI_TAG=4,MPI_ERROR=5)
//really ugly
status[2] = c_status.MPI_SOURCE;
status[3] = c_status.MPI_TAG;
status[4] = c_status.MPI_ERROR;
//Fortan_Requests[*request] = foMPI_REQUEST_NULL; already done by foMPI_Test
insert_free_elem( *request, &glob_info.Fortran_free_req );
*request = -1; /* equivalent to fompi_request_null in fompif.h */
}
}
void F77_FUNC_(fompi_type_free,FOMPI_TYPE_FREE)( int *datatype, int *ierr );
void F77_FUNC_(fompi_type_free,FOMPI_TYPE_FREE)( int *datatype, int *ierr ) {
MPI_Datatype dtype;
dtype = MPI_Type_f2c(*datatype);
*ierr = foMPI_Type_free( &dtype );
}