-
Notifications
You must be signed in to change notification settings - Fork 10
/
pack.c
151 lines (120 loc) · 3.58 KB
/
pack.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mpiP.h"
#include "type.h"
/*
*
*/
int FC_FUNC( mpi_pack , MPI_PACK )
( void *inbuf, int *incount, int *datatype,
void *outbuf, int *outsize, int *position, int *comm, int *ierror)
{
*ierror=MPI_Pack(inbuf, *incount,* datatype,
outbuf, *outsize, position, *comm);
return MPI_SUCCESS;
}
int MPI_Pack( void *inbuf, int incount, MPI_Datatype datatype,
void *outbuf, int outsize, int *position, MPI_Comm comm)
{
int ret;
Datatype type_ptr = *(Datatype*) mpi_handle_to_datatype(datatype);
Comm* comm_ptr = mpi_handle_to_ptr(comm);
ret = Pack(inbuf, incount, type_ptr, outbuf, outsize, position, comm_ptr);
return ret;
}
int Pack(void *inbuf, int incount, Datatype type,
void *outbuf, int outsize, int *position, Comm * comm)
{
int i, j;
MPI_Aint extent;
//check that buffer is large enough
Type_extent(type, &extent);
for (i = 0; i < incount; i++)
{
for (j = 0; j < type->count; j++)
{
if ((*position) + Simpletype_length(type->pairs[j].type) > outsize)
{
printf("MPI_Pack: data exceeds buffer size\n");
exit(1);
}
memcpy(((char*) outbuf)+(*position), inbuf+type->pairs[j].disp + (extent*i),
Simpletype_length(type->pairs[j].type));
*position += Simpletype_length(type->pairs[j].type);
}
}
return MPI_SUCCESS;
}
int Pack_size(int incount, Datatype datatype,
Comm * comm, MPI_Aint * size)
{
int i;
*size = 0;
//sum up all sizes
for(i = 0; i < datatype->count; i++)
{
*size += Simpletype_length(datatype->pairs[i].type);
}
*size *= incount;
printf("Size = %d\n", *size);
return MPI_SUCCESS;
}
int FC_FUNC( mpi_pack_size, MPI_PACK_SIZE )(int * incount, int * datatype,
int * comm, MPI_Aint * size, int *ierr)
{
*ierr = MPI_Pack_size(*incount, *datatype, *comm, size);
return MPI_SUCCESS;
}
int MPI_Pack_size(int incount, MPI_Datatype datatype,
MPI_Comm comm, MPI_Aint * size)
{
int ret;
Datatype type_ptr = *(Datatype*) mpi_handle_to_datatype(datatype);
Comm * comm_ptr = mpi_handle_to_ptr(comm);
ret = Pack_size(incount, type_ptr, comm_ptr, size);
return ret;
}
/*
*
*/
int FC_FUNC( mpi_unpack , MPI_UNPACK )
( void *inbuf, int *insize, int *position,
void *outbuf, int *outcount, int *datatype,
int *comm, int *ierror )
{
*ierror=MPI_Unpack( inbuf, *insize, position,
outbuf, *outcount, *datatype, *comm);
return MPI_SUCCESS;
}
int MPI_Unpack(void * inbuf, int insize, int * position, void * outbuf,
int outcount, MPI_Datatype type, MPI_Comm comm)
{
int ret;
Datatype type_ptr = *(Datatype*) mpi_handle_to_datatype(type);
Comm * comm_ptr = mpi_handle_to_ptr(comm);
ret = Unpack(inbuf, insize, position, outbuf, outcount, type_ptr, comm_ptr);
return ret;
}
int Unpack(void * inbuf, int insize, int * position, void *outbuf,
int outcount, Datatype type, Comm* comm)
{
int i, j;
MPI_Aint extent;
Type_extent(type, &extent);
for (i = 0; i < outcount; i++)
{
for (j = 0; j < type->count; j++)
{
if ((*position) + Simpletype_length(type->pairs[j].type) > insize)
{
printf("MPI_Unpack: Data exceeds buffer size\n");
exit(1);
}
memcpy(outbuf+type->pairs[j].disp + (extent*i), ((char*) inbuf)+(*position) ,
Simpletype_length(type->pairs[j].type));
*position += Simpletype_length(type->pairs[j].type);
}
}
return MPI_SUCCESS;
}