This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfompi_win_allocate.c
71 lines (56 loc) · 1.84 KB
/
fompi_win_allocate.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
// 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 <assert.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include "fompi.h"
/* TODO: I assume that baseptr is a pointer to a pointer: Is this correct? */
int foMPI_Win_allocate(MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *baseptr, foMPI_Win *win) {
int result;
if (baseptr != NULL) {
#ifdef SYMHEAP
int rank;
int pagesize;
void* ptr;
char test, result;
MPI_Comm_rank( comm, &rank );
pagesize = getpagesize();
/*
if ( rank == 0 ) {
*(void **)baseptr = mmap( 0, (size_t) size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 );
ptr = *(void **)baseptr;
}
MPI_Bcast( &ptr, sizeof(void*), MPI_BYTE, 0, comm );
if ( rank != 0 ) {
*(void **)baseptr = mmap( ptr, (size_t) size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 );
}
if( ptr == *(void **)baseptr ) {
test = 1;
} else {
test = 0;
}
MPI_Allreduce( &test, &result, 1, MPI_CHAR, MPI_MIN, comm );
if ( result == 1 ) {
printf("%i: We have a symmetric heap at %p.\n", rank, *(void **)baseptr );
} else {
printf("%i: We have no symmetric heap. My allocation begins at %p.\n", rank, *(void **)baseptr );
}
*/
//MPI_Abort( comm, -1 );
#else
void * memptr;
_foMPI_ALIGNED_ALLOC(&memptr, size)
*((void **)baseptr) = memptr;
assert( *(void **)baseptr != NULL );
#endif
result = foMPI_Win_create(*(void **)baseptr, size, disp_unit, info, comm, win);
} else {
result = foMPI_Win_create(NULL, size, disp_unit, info, comm, win);
}
if ( result == MPI_SUCCESS ) {
(*win)->create_flavor = foMPI_WIN_FLAVOR_ALLOCATE;
}
return result;
}