mpid_rma.c 20.1 KB
Newer Older
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
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#include "mpidimpl.h"

static int setupRMAFunctions = 1;
/* Define the functions that are used to implement the RMA operations */
static MPIDI_RMAFns RMAFns = { MPIDI_Win_create, MPIDI_Win_free,
			       MPIDI_Put, MPIDI_Get, MPIDI_Accumulate,
			       MPIDI_Win_fence, MPIDI_Win_post, 
			       MPIDI_Win_start, MPIDI_Win_complete,
			       MPIDI_Win_wait, MPIDI_Win_lock,
			       MPIDI_Win_unlock, MPIDI_Alloc_mem, MPIDI_Free_mem };

#undef FUNCNAME
#define FUNCNAME MPID_Win_create
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_create(void *base, MPI_Aint size, int disp_unit, MPID_Info *info, 
                    MPID_Comm *comm_ptr, MPID_Win **win_ptr)
{
    int mpi_errno=MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_CREATE);
    
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_CREATE);

    /* Check to see if we need to setup channel-specific functions
       for handling the RMA operations */
32
    /* --BEGIN OPTIONALINIT-- */
33
34
35
36
    if (setupRMAFunctions) {
	MPIU_CALL(MPIDI_CH3,RMAFnsInit( &RMAFns ));
	setupRMAFunctions = 0;
    }
37
    /* --END OPTIONALINIT-- */
38
39
40
41
42
43
44
45

    /* The default for this function is MPIDI_Win_create.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_CH3_Win_create.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    /* We pass the RMAFns function table to this function because a channel may 
46
47
48
49
       want to reset it to the default if it finds that it cannot
       optimize for this   
       set of windows. The sshm channel does this if windows are not
       allocated in shared memory. */
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
       
    if (RMAFns.Win_create) {
	mpi_errno = RMAFns.Win_create(base, size, disp_unit, info, comm_ptr, 
				      win_ptr, &RMAFns);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_CREATE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_free
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_free(MPID_Win **win_ptr)
{
   int mpi_errno=MPI_SUCCESS;
   MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_FREE);
        
   MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_FREE);
78
79
80
81
82
83
84
85
86
87
88
89

   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
90
    }
91
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_free.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_CH3_Win_free.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_free) {
	mpi_errno = RMAFns.Win_free(win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_FREE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Put
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Put(void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_PUT);
        
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_PUT);

128
129
130
131
132
133
134
135
136
137
138
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
139
    }
140
#   endif /* HAVE_ERROR_CHECKING */
141
142
143
144
145
146
147
148
149

    /* The default for this function is MPIDI_Put.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_CH3_Put.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Put) {
	mpi_errno = RMAFns.Put(origin_addr, origin_count, origin_datatype, 
150
151
			       target_rank, target_disp, target_count, 
			       target_datatype, win_ptr);
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
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_PUT);    
    return mpi_errno;
}



#undef FUNCNAME
#define FUNCNAME MPID_Get
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Get(void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_GET);
        
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_GET);

180
181
182
183
184
185
186
187
188
189
190
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
191
    }
192
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Get.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_CH3_Get.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Get) {
	mpi_errno = RMAFns.Get(origin_addr, origin_count, origin_datatype, 
			       target_rank, target_disp, target_count, target_datatype,
			       win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_GET);
    return mpi_errno;
}



#undef FUNCNAME
#define FUNCNAME MPID_Accumulate
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Accumulate(void *origin_addr, int origin_count, MPI_Datatype
                    origin_datatype, int target_rank, MPI_Aint target_disp,
                    int target_count, MPI_Datatype target_datatype, MPI_Op op,
                    MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_ACCUMULATE);
        
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_ACCUMULATE);

233
234
235
236
237
238
239
240
241
242
243
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
244
    }
245
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Accumulate.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_CH3_Accumulate.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Accumulate) {
	mpi_errno = RMAFns.Accumulate(origin_addr, origin_count, origin_datatype, 
			       target_rank, target_disp, target_count, target_datatype,
			       op, win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_ACCUMULATE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_fence
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_fence(int assert, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_FENCE);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_FENCE);

282
283
284
285
286
287
288
289
290
291
292
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
293
    }
294
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_fence.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_fence.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_fence) {
	mpi_errno = RMAFns.Win_fence(assert, win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_FENCE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_post
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_post(MPID_Group *group_ptr, int assert, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_POST);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_POST);

329
330
331
332
333
334
335
336
337
338
339
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
340
    }
341
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_post.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_post.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_post) {
	mpi_errno = RMAFns.Win_post(group_ptr, assert, win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_POST);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_start
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_start(MPID_Group *group_ptr, int assert, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_START);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_START);

376
377
378
379
380
381
382
383
384
385
386
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
387
    }
388
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_start.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_start.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_start) {
	mpi_errno = RMAFns.Win_start(group_ptr, assert, win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_START);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_complete
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_complete(MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_COMPLETE);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_COMPLETE);

423
424
425
426
427
428
429
430
431
432
433
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
434
    }
435
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_complete.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_complete.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_complete) {
	mpi_errno = RMAFns.Win_complete(win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_COMPLETE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_wait
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_wait(MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_WAIT);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_WAIT);

470
471
472
473
474
475
476
477
478
479
480
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
481
    }
482
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_wait.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_wait.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_wait) {
	mpi_errno = RMAFns.Win_wait(win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_WAIT);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_lock
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_lock(int lock_type, int dest, int assert, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_LOCK);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_LOCK);

517
518
519
520
521
522
523
524
525
526
527
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
528
    }
529
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_lock.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_lock.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_lock) {
	mpi_errno = RMAFns.Win_lock(lock_type, dest, assert, win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_LOCK);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_unlock
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_unlock(int dest, MPID_Win *win_ptr)
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_UNLOCK);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_UNLOCK);

564
565
566
567
568
569
570
571
572
573
574
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
575
    }
576
#   endif /* HAVE_ERROR_CHECKING */
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

    /* The default for this function is MPIDI_Win_unlock.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Win_unlock.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Win_unlock) {
	mpi_errno = RMAFns.Win_unlock(dest, win_ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }

 fn_fail:
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_UNLOCK);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Alloc_mem
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
void *MPID_Alloc_mem( size_t size, MPID_Info *info_ptr )
{
    void *ap=NULL;
    MPIDI_STATE_DECL(MPID_STATE_MPID_ALLOC_MEM);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_ALLOC_MEM);

    /* Check to see if we need to setup channel-specific functions
       for handling the RMA operations */
613
    /* --BEGIN OPTIONALINIT-- */
614
615
616
617
    if (setupRMAFunctions) {
	MPIU_CALL(MPIDI_CH3,RMAFnsInit( &RMAFns ));
	setupRMAFunctions = 0;
    }
618
    /* --END OPTIONALINIT-- */
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

    /* The default for this function is MPIDI_Alloc_mem.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Alloc_mem.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Alloc_mem) {
	ap = RMAFns.Alloc_mem(size, info_ptr);
    }
    
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_ALLOC_MEM);
    return ap;
}


#undef FUNCNAME
#define FUNCNAME MPID_Free_mem
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Free_mem( void *ptr )
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_FREE_MEM);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_FREE_MEM);

646
647
648
649
650
651
652
653
654
655
656
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**memnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
657
    }
658
#   endif /* HAVE_ERROR_CHECKING */
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680

    /* The default for this function is MPIDI_Free_mem.
       A channel may define its own function and set it in the 
       init check above; such a function may be named MPIDI_Free_mem.
       If a channel does not implement this operation, it will set
       the function pointer to NULL */

    if (RMAFns.Free_mem) {
	mpi_errno = RMAFns.Free_mem(ptr);
	if (mpi_errno != MPI_SUCCESS) {
	    MPIU_ERR_POP(mpi_errno);
	}
    }
    else {
	MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**notimpl");
    }
        
 fn_fail:
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_FREE_MEM);
    return mpi_errno;
}

681
/* FIXME: The test function needs to be settable by the RMA support */
682
683
684
685
686
687
688
689
690
691
692
693
#undef FUNCNAME
#define FUNCNAME MPID_Win_test
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
int MPID_Win_test(MPID_Win *win_ptr, int *flag)
{
    int mpi_errno=MPI_SUCCESS;

    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_TEST);

    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_TEST);

694
695
696
   /* If we call this function but setup has not been called, 
      the program is in error */
#   ifdef HAVE_ERROR_CHECKING
697
    {
698
699
700
701
702
703
704
705
706
707
708
709
710
        MPID_BEGIN_ERROR_CHECKS;
        {
	    if (setupRMAFunctions) {
		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnotinit");
	    }
        }
        MPID_END_ERROR_CHECKS;
    }
#   endif /* HAVE_ERROR_CHECKING */

    mpi_errno = MPID_Progress_test();
    if (mpi_errno != MPI_SUCCESS) {
	MPIU_ERR_POP(mpi_errno);
711
712
713
714
    }

    *flag = (win_ptr->my_counter) ? 0 : 1;

715
 fn_fail:
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
    MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPID_WIN_TEST);
    return mpi_errno;
}



/* This was probably added by Brad. Leaving it here for now. Needs to be fixed 
   according to the FIXME below. */
/* FIXME: It would be better to install this as an abort and a finalize 
   handler, ranter than expecting all routines to call this.  It
   can be installed on first use of alloc_mem */
#undef FUNCNAME
#define FUNCNAME MPID_Cleanup_mem
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
void MPID_Cleanup_mem()
{
#if defined(MPIDI_CH3_IMPLEMENTS_CLEANUP_MEM)
    MPIDI_CH3_Cleanup_mem();
#endif
}