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
|
/*
* test_client_acg.c: Client side of ACG Dynamic Data Structure Support
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "mpi.h"
#include "hdf5.h"
int main(int argc, char **argv) {
const char file_name[]="acg_file.h5";
hid_t file_id;
hid_t dsid = -1; /* Dataset ID */
hid_t sid = -1; /* Dataspace ID */
hsize_t dim, max_dim, chunk_dim; /* Dataset and chunk dimensions */
hsize_t curr_size;
unsigned u; /* Local index variable */
unsigned write_elem[60], read_elem[60]; /* Element written/read */
hid_t fapl_id, dxpl_id;
int my_rank, my_size;
int provided;
hid_t e_stack;
H5ES_status_t *status = NULL;
int num_requests = 0, i;
herr_t ret;
H5_request_t req1;
H5ES_status_t status;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
if(MPI_THREAD_MULTIPLE != provided) {
fprintf(stderr, "MPI does not have MPI_THREAD_MULTIPLE support\n");
exit(1);
}
/* Call EFF_init to initialize the EFF stack.
As a result of this call, the Function Shipper client is started,
and HDF5 VOL calls are registered with the function shipper.
An "IOD init" call is forwarded from the FS client to the FS server
which should already be running. */
EFF_init(MPI_COMM_WORLD, MPI_INFO_NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &my_size);
fprintf(stderr, "APP processes = %d, my rank is %d\n", my_size, my_rank);
fprintf(stderr, "Create the FAPL to set the IOD VOL plugin and create the file\n");
/* Choose the IOD VOL plugin to use with this file.
First we create a file access property list. Then we call a new routine to set
the IOD plugin to use with this fapl */
fapl_id = H5Pcreate (H5P_FILE_ACCESS);
H5Pset_fapl_iod(fapl_id, MPI_COMM_WORLD, MPI_INFO_NULL);
/* create an event Queue for managing asynchronous requests.
Event Queues will releive the use from managing and completing
individual requests for every operation. Instead of passing a
request for every operation, the event queue is passed and
internally the HDF5 library creates a request and adds it to
the event queue.
Multiple Event queue can be created used by the application. */
e_stack = H5EScreate();
assert(e_stack);
/* create the file. This is asynchronous, but the file_id can be used. */
file_id = H5Fcreate_ff(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id, e_stack);
assert(file_id);
/* Create 1-D dataspace */
dim = 0;
max_dim = H5S_UNLIMITED;
if((sid = H5Screate_simple(1, &dim, &max_dim)) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
/* Create 1-D chunked dataset */
if((dsid = H5Dcreate_ff(file_id, "dset", H5T_NATIVE_UINT, sid,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, 0 , e_stack)) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
/* Close dataspace */
H5Sclose(sid);
/* Initialize data elements */
for(u = 0; u < 60; u++)
write_elem[u] = u;
printf("App Dataset Id = %d File id = %d\n", dsid, file_id);
ret = H5DOappend_ff(dsid, H5P_DEFAULT, 1, 10, H5T_NATIVE_UINT,
write_elem, 0 , e_stack);
assert(ret<0);
/* Append 60 elements to dataset, along proper axis */
if(H5DOappend_ff(dsid, H5P_DEFAULT, 0, 60, H5T_NATIVE_UINT,
write_elem, 0 , e_stack) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
/* Get the dataset's dataspace now */
if((sid = H5Dget_space(dsid)) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
if(H5Sget_simple_extent_dims(sid, &curr_size, NULL) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
/* Verify dataset is correct size */
if(curr_size != 60) {
fprintf(stderr, "Failed\n");
exit(1);
}
/* Close dataspace */
if(H5Sclose(sid) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
/* Read elements back, with sequence operation */
memset(read_elem, 0, sizeof(read_elem));
/* Sequence 10 elements from dataset, along bad axis */
ret = H5DOsequence_ff(dsid, H5P_DEFAULT, 1, 0, 60, H5T_NATIVE_UINT,
read_elem, 0 , e_stack);
/* Sequence first 60 elements from dataset, along proper axis */
ret = H5DOsequence_ff(dsid, H5P_DEFAULT, 0, 0, 60, H5T_NATIVE_UINT,
read_elem, 0 , e_stack);
assert(ret == 0);
/* close dataset */
assert(H5Dclose(dsid) == 0);
{
hvl_t wdata[5]; /* Information to write */
hvl_t rdata[5]; /* Information to write */
hid_t tid;
hsize_t dims[1];
int increment, j, n;
n = 0;
increment = 4;
/* Allocate and initialize VL data to write */
for(i = 0; i < 5; i++) {
int temp = i*increment + increment;
wdata[i].p = malloc(temp * sizeof(unsigned int));
wdata[i].len = temp;
for(j = 0; j < temp; j++)
((unsigned int *)wdata[i].p)[j] = n ++;
} /* end for */
/* Create a datatype to refer to */
tid = H5Tvlen_create (H5T_NATIVE_UINT);
/* create a dataspace. This is a local Bookeeping operation that
does not touch the file */
dims [0] = 5;
sid = H5Screate_simple(1, dims, NULL);
/* Create Dataset */
if((dsid = H5Dcreate_ff(file_id, "dset_vl", tid, sid,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, 0 , e_stack)) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
ret = H5Dwrite(dsid, tid, sid, sid, H5P_DEFAULT, wdata);
assert(ret == 0);
ret = H5Dread(dsid, tid, sid, sid, H5P_DEFAULT, rdata);
assert(ret == 0);
/* Print VL DATA */
for(i = 0; i < 5; i++) {
int temp = i*increment + increment;
fprintf(stderr, "Element %d size %zu: ", i, rdata[i].len);
for(j = 0; j < temp; j++)
fprintf(stderr, "%d ",((unsigned int *)rdata[i].p)[j]);
fprintf(stderr, "\n");
} /* end for */
H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, rdata);
H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, wdata);
H5Sclose(sid);
H5Tclose(tid);
/* close dataset */
assert(H5Dclose_ff(dsid, e_stack) == 0);
}
{
hid_t tid;
hsize_t dims[1];
const char *str_wdata[4]= {
"Four score and seven years ago our forefathers brought forth on this continent a new nation,",
"conceived in liberty and dedicated to the proposition that all men are created equal.",
"Now we are engaged in a great civil war,",
"testing whether that nation or any nation so conceived and so dedicated can long endure."
}; /* Information to write */
char *str_rdata[4]; /* Information read in */
/* create a dataspace. This is a local Bookeeping operation that
does not touch the file */
dims [0] = 4;
sid = H5Screate_simple(1, dims, NULL);
/* Create a datatype to refer to */
tid = H5Tcopy(H5T_C_S1);
H5Tset_size(tid,H5T_VARIABLE);
/* Create Dataset */
if((dsid = H5Dcreate_ff(file_id, "dset_vl_str", tid, sid,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, 0 , e_stack)) < 0) {
fprintf(stderr, "Failed\n");
exit(1);
}
ret = H5Dwrite(dsid, tid, sid, sid, H5P_DEFAULT, str_wdata);
assert(ret == 0);
ret = H5Dread(dsid, tid, sid, sid, H5P_DEFAULT, str_rdata);
assert(ret == 0);
fprintf(stderr, "Reading VL Strings: \n");
for(i=0 ; i<4 ; i++) {
fprintf(stderr, "%s\n", str_rdata[i]);
}
H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, str_rdata);
H5Sclose(sid);
H5Tclose(tid);
/* close dataset */
assert(H5Dclose_ff(dsid, e_stack) == 0);
}
/* closing the container also acts as a wait all on all pending requests
on the container. */
assert(H5Fclose_ff(file_id, e_stack) == 0);
fprintf(stderr, "\n*****************************************************************************************************************\n");
fprintf(stderr, "Wait on everything in EQ and check Results of operations in EQ\n");
fprintf(stderr, "*****************************************************************************************************************\n");
/* wait on all requests and print completion status */
H5EQwait(e_stack, &num_requests, &status);
fprintf(stderr, "%d requests in event queue. Completions: ", num_requests);
for(i=0 ; i<num_requests; i++)
fprintf(stderr, "%d ",status[i]);
fprintf(stderr, "\n");
free(status);
/* Verify data read */
for(u = 0; u < 60; u++) {
if(read_elem[u] != write_elem[u]) {
fprintf(stderr, "Failed\n");
exit(1);
}
}
fprintf(stderr, "\n*****************************************************************************************************************\n");
fprintf(stderr, "Finalize EFF stack\n");
fprintf(stderr, "*****************************************************************************************************************\n");
H5ESclose(e_stack);
H5Pclose(fapl_id);
/* This finalizes the EFF stack. ships a terminate and IOD finalize to the server
and shutsdown the FS server (when all clients send the terminate request)
and client */
EFF_finalize();
MPI_Finalize();
return 0;
}
|