AdjoinableMPI
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
support.c
Go to the documentation of this file.
1
/*
2
##########################################################
3
# This file is part of the AdjoinableMPI library #
4
# released under the MIT License. #
5
# The full COPYRIGHT notice can be found in the top #
6
# level directory of the AdjoinableMPI distribution. #
7
##########################################################
8
*/
9
#include <malloc.h>
10
#include <assert.h>
11
#include <string.h>
12
#include "
ampi/tape/support.h
"
13
14
static
void
*
myTapeStorage
=0;
15
static
size_t
myTapeStorageSize
=0;
16
static
void
*
myStack_p
=0;
17
static
void
*
myRead_p
=0;
18
static
void
*
myStackTop_p
=0;
19
20
void
TAPE_AMPI_init
() {
21
/* reset things */
22
if
(
myTapeStorage
) {
23
free(
myTapeStorage
);
24
}
25
myTapeStorage
=0;
26
myTapeStorageSize
=0;
27
myStack_p
=
myTapeStorage
;
28
myRead_p
=
myTapeStorage
;
29
myStackTop_p
=
myTapeStorage
;
30
}
31
32
33
static
void
writeBlob
(
void
*,
size_t
);
34
static
void
readBlob
(
void
*,
size_t
);
35
36
void
writeBlob
(
void
* aBlob,
size_t
aSize) {
37
assert(aBlob);
38
/* make some space*/
39
if
(aSize>(
char
*)
myTapeStorage
+
myTapeStorageSize
-(
char
*)
myStack_p
) {
40
size_t
increment=0;
41
void
*newTapeStorage=0;
42
if
(increment<aSize) increment=aSize;
43
if
(increment<1024) increment=1024;
44
myTapeStorageSize
=
myTapeStorageSize
+increment;
45
newTapeStorage=realloc(
myTapeStorage
,
myTapeStorageSize
);
46
assert(newTapeStorage);
47
if
(newTapeStorage!=
myTapeStorage
) {
48
myStack_p
=(
char
*)newTapeStorage+((
char
*)
myStack_p
-(
char
*)
myTapeStorage
);
49
myRead_p
=(
char
*)newTapeStorage+((
char
*)
myRead_p
-(
char
*)myTapeStorage);
50
myTapeStorage=newTapeStorage;
51
}
52
}
53
memcpy(
myStack_p
,aBlob,aSize);
54
myStack_p
=(
char
*)
myStack_p
+aSize;
55
myStackTop_p
=
myStack_p
;
56
}
57
58
void
readBlob
(
void
* aBlob,
size_t
aSize) {
59
assert(aSize<=(
char
*)
myTapeStorage
+
myTapeStorageSize
-(
char
*)
myRead_p
);
60
memcpy(aBlob,
myRead_p
,aSize);
61
myRead_p
=(
char
*)
myRead_p
+aSize;
62
}
63
64
void
popBlob
(
void
* aBlob,
size_t
aSize) {
65
assert(aSize<=(
char
*)
myStack_p
-(
char
*)
myTapeStorage
);
66
myStack_p
=(
char
*)
myStack_p
-aSize;
67
memcpy(aBlob,
myStack_p
,aSize);
68
}
69
70
void
TAPE_AMPI_resetBottom
() {
71
myRead_p
=
myTapeStorage
;
72
}
73
74
void
TAPE_AMPI_resetTop
() {
75
myStack_p
=
myStackTop_p
;
76
}
77
78
void
TAPE_AMPI_push_int
(
int
an_int) {
writeBlob
((
void
*)(&an_int),
sizeof
(
int
)); }
79
void
TAPE_AMPI_pop_int
(
int
*an_int) {
popBlob
((
void
*)(an_int),
sizeof
(
int
)); }
80
void
TAPE_AMPI_read_int
(
int
* an_int) {
readBlob
((
void
*)(an_int),
sizeof
(
int
)); }
81
82
void
TAPE_AMPI_push_MPI_Aint
(MPI_Aint an_MPI_Aint) {
writeBlob
((
void
*)(&an_MPI_Aint),
sizeof
(MPI_Aint)); }
83
void
TAPE_AMPI_pop_MPI_Aint
(MPI_Aint *an_MPI_Aint) {
popBlob
((
void
*)(an_MPI_Aint),
sizeof
(MPI_Aint)); }
84
void
TAPE_AMPI_read_MPI_Aint
(MPI_Aint* an_MPI_Aint) {
readBlob
((
void
*)(an_MPI_Aint),
sizeof
(MPI_Aint)); }
85
86
void
TAPE_AMPI_push_ptr
(
void
*an_int) {
writeBlob
((
void
*)(&an_int),
sizeof
(
void
*)); }
87
void
TAPE_AMPI_pop_ptr
(
void
**ptr) {
popBlob
((
void
*)(ptr),
sizeof
(
void
*)); }
88
void
TAPE_AMPI_read_ptr
(
void
**ptr) {
readBlob
((
void
*)(ptr),
sizeof
(
void
*)); }
89
90
void
TAPE_AMPI_push_MPI_Datatype
(MPI_Datatype an_MPI_Datatype) {
writeBlob
((
void
*)(&an_MPI_Datatype),
sizeof
(MPI_Datatype)); }
91
void
TAPE_AMPI_pop_MPI_Datatype
(MPI_Datatype *an_MPI_Datatype) {
popBlob
((
void
*)(an_MPI_Datatype),
sizeof
(MPI_Datatype)); }
92
void
TAPE_AMPI_read_MPI_Datatype
(MPI_Datatype* an_MPI_Datatype) {
readBlob
((
void
*)(an_MPI_Datatype),
sizeof
(MPI_Datatype)); }
93
94
void
TAPE_AMPI_push_MPI_Comm
(MPI_Comm an_MPI_Comm) {
writeBlob
((
void
*)(&an_MPI_Comm),
sizeof
(MPI_Comm)); }
95
void
TAPE_AMPI_pop_MPI_Comm
(MPI_Comm *an_MPI_Comm) {
popBlob
((
void
*)(an_MPI_Comm),
sizeof
(MPI_Comm)); }
96
void
TAPE_AMPI_read_MPI_Comm
(MPI_Comm* an_MPI_Comm) {
readBlob
((
void
*)(an_MPI_Comm),
sizeof
(MPI_Comm)); }
97
98
void
TAPE_AMPI_push_MPI_Request
(MPI_Request an_MPI_Request) {
writeBlob
((
void
*)(&an_MPI_Request),
sizeof
(MPI_Request)); }
99
void
TAPE_AMPI_pop_MPI_Request
(MPI_Request *an_MPI_Request) {
popBlob
((
void
*)(an_MPI_Request),
sizeof
(MPI_Request)); }
100
void
TAPE_AMPI_read_MPI_Request
(MPI_Request* an_MPI_Request) {
readBlob
((
void
*)(an_MPI_Request),
sizeof
(MPI_Request)); }
101
102
void
TAPE_AMPI_push_MPI_Op
(MPI_Op an_MPI_Op) {
writeBlob
((
void
*)(&an_MPI_Op),
sizeof
(MPI_Op)); }
103
void
TAPE_AMPI_pop_MPI_Op
(MPI_Op *an_MPI_Op) {
popBlob
((
void
*)(an_MPI_Op),
sizeof
(MPI_Op)); }
104
void
TAPE_AMPI_read_MPI_Op
(MPI_Op* an_MPI_Op) {
readBlob
((
void
*)(an_MPI_Op),
sizeof
(MPI_Op)); }
105
106
void
TAPE_AMPI_push_double
(
double
a_double) {
writeBlob
((
void
*)(&a_double),
sizeof
(
double
)); }
107
void
TAPE_AMPI_pop_double
(
double
*a_double) {
popBlob
((
void
*)(a_double),
sizeof
(
double
)); }
108
void
TAPE_AMPI_read_double
(
double
* a_double) {
readBlob
((
void
*)(a_double),
sizeof
(
double
)); }
109
110
void
TAPE_AMPI_push_MPI_Win
(MPI_Win an_MPI_Win) {
writeBlob
((
void
*)(&an_MPI_Win),
sizeof
(MPI_Win)); }
111
void
TAPE_AMPI_pop_MPI_Win
(MPI_Win *an_MPI_Win) {
popBlob
((
void
*)(an_MPI_Win),
sizeof
(MPI_Win)); }
112
void
TAPE_AMPI_read_MPI_Win
(MPI_Win * an_MPI_Win) {
readBlob
((
void
*)(an_MPI_Win),
sizeof
(MPI_Win)); }
113
Tape
support.c
Generated on Mon Feb 22 2016 23:45:09 for AdjoinableMPI by
1.8.4