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
290
291
292
293
294
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
/*
* h5ff_client_attr.c: Client side test for attribute routines.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "mpi.h"
#include "hdf5.h"
int main(int argc, char **argv) {
char file_name[50];
hid_t file_id;
hid_t gid1;
hid_t sid, dtid, stype_id;
hid_t sid2;
hid_t did1, map;
hid_t aid1, aid2, aid3, aid4, aid5;
hid_t tid1, tid2, rid1, rid2, rid3;
hid_t fapl_id, trspl_id;
hid_t e_stack;
hbool_t exists1;
hbool_t exists2;
uint64_t version;
uint64_t trans_num;
int *wdata1 = NULL, *wdata2 = NULL;
int *rdata1 = NULL, *rdata2 = NULL;
char str_data[128];
const unsigned int nelem=60;
hsize_t dims[1];
int my_rank, my_size;
int provided;
MPI_Request mpi_req;
uint32_t cs_scope = 0;
size_t num_events = 0;
H5ES_status_t status;
unsigned int i = 0;
herr_t ret;
sprintf(file_name, "%s_%s", getenv("USER"), "eff_file_attr.h5");
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. */
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);
/* Choose the IOD VOL plugin to use with this file. */
fapl_id = H5Pcreate (H5P_FILE_ACCESS);
H5Pset_fapl_iod(fapl_id, MPI_COMM_WORLD, MPI_INFO_NULL);
/* set the metada data integrity checks to happend at transfer through mercury */
cs_scope |= H5_CHECKSUM_TRANSFER;
ret = H5Pset_metadata_integrity_scope(fapl_id, cs_scope);
assert(ret == 0);
/* allocate and initialize arrays for dataset I/O */
wdata1 = malloc (sizeof(int32_t)*nelem);
wdata2 = malloc (sizeof(int32_t)*nelem);
rdata1 = malloc (sizeof(int32_t)*nelem);
rdata2 = malloc (sizeof(int32_t)*nelem);
for(i=0;i<nelem;++i) {
rdata1[i] = 0;
rdata2[i] = 0;
wdata1[i]=i;
wdata2[i]=i*2;
}
/* create an event Queue for managing asynchronous requests. */
e_stack = H5EScreate();
assert(e_stack);
/* create the file. */
file_id = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
assert(file_id > 0);
/* create 1-D dataspace with 60 elements */
dims [0] = nelem;
sid = H5Screate_simple(1, dims, NULL);
dtid = H5Tcopy(H5T_STD_I32LE);
stype_id = H5Tcopy(H5T_C_S1 ); assert( stype_id );
ret = H5Tset_strpad(stype_id, H5T_STR_NULLTERM ); assert( ret == 0 );
ret = H5Tset_size(stype_id, 128); assert( ret == 0 );
/* start transaction 2 with default Leader/Delegate model. Leader
which is rank 0 here starts the transaction. It can be
asynchronous, but we make it synchronous here so that the
Leader can tell its delegates that the transaction is
started. */
if(0 == my_rank) {
/* acquire container version 1 - EXACT.
This can be asynchronous, but here we need the acquired ID
right after the call to start the transaction so we make synchronous. */
version = 1;
rid1 = H5RCacquire(file_id, &version, H5P_DEFAULT, H5_EVENT_STACK_NULL);
/* create transaction object */
tid1 = H5TRcreate(file_id, rid1, (uint64_t)2);
assert(tid1);
ret = H5TRstart(tid1, H5P_DEFAULT, e_stack);
assert(0 == ret);
sid2 = H5Screate(H5S_SCALAR); assert( sid2 );
/* create group /G1 */
gid1 = H5Gcreate_ff(file_id, "G1", H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT, tid1, e_stack);
assert(gid1 > 0);
/* create dataset /G1/D1 */
did1 = H5Dcreate_ff(gid1, "D1", dtid, sid2, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack);
assert(did1 > 0);
/* Commit the datatype dtid to the file. */
ret = H5Tcommit_ff(file_id, "DT1", dtid, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT, tid1, e_stack);
assert(ret == 0);
/* create a Map object on the root group */
map = H5Mcreate_ff(file_id, "MAP1", H5T_STD_I32LE, H5T_STD_I32LE,
H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT, tid1, e_stack);
assert(map > 0);
/* create an attribute on root group */
aid1 = H5Acreate_ff(file_id, "ROOT_ATTR", dtid, sid,
H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack);
assert(aid1);
/* create an attribute on group G1. */
aid2 = H5Acreate_ff(gid1, "GROUP_ATTR", dtid, sid,
H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack);
assert(aid2);
/* write data to attributes */
ret = H5Awrite_ff(aid1, dtid, wdata1, tid1, e_stack);
assert(ret == 0);
ret = H5Awrite_ff(aid2, dtid, wdata2, tid1, e_stack);
assert(ret == 0);
/* create an attribute on dataset */
aid3 = H5Acreate_ff(did1, "DSET_ATTR", dtid, sid,
H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack);
assert(aid3);
/* create an attribute on datatype */
aid4 = H5Acreate_ff(dtid, "DTYPE_ATTR", dtid, sid,
H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack);
assert(aid4);
aid5 = H5Acreate_ff(map, "MAP_ATTR", stype_id, sid2, H5P_DEFAULT,
H5P_DEFAULT, tid1, H5_EVENT_STACK_NULL );
assert(aid5);
ret = H5Awrite_ff(aid5, stype_id, "/AA by rank 0", tid1, H5_EVENT_STACK_NULL );
assert( ret == 0 );
H5Sclose(sid2);
{
hid_t temp_sid;
temp_sid = H5Aget_space(aid5);
assert(temp_sid > 0);
H5Sclose(temp_sid);
}
ret = H5Aclose_ff(aid1, e_stack);
assert(ret == 0);
/* make this synchronous so we know the container version has been acquired */
ret = H5TRfinish(tid1, H5P_DEFAULT, &rid2, H5_EVENT_STACK_NULL);
assert(0 == ret);
/* release container version 1. This is async. */
ret = H5RCrelease(rid1, e_stack);
assert(0 == ret);
}
H5ESget_count(e_stack, &num_events);
H5ESwait_all(e_stack, &status);
H5ESclear(e_stack);
printf("%d events in event stack. Completion status = %d\n", num_events, status);
if(0 != num_events) assert(status == H5ES_STATUS_SUCCEED);
if(0 == my_rank) {
/* Local op */
ret = H5TRclose(tid1);
assert(0 == ret);
/* create transaction object */
tid2 = H5TRcreate(file_id, rid2, (uint64_t)3);
assert(tid2);
ret = H5TRstart(tid2, H5P_DEFAULT, e_stack);
assert(0 == ret);
/* Delete an attribute */
ret = H5Adelete_ff(file_id, "ROOT_ATTR", tid2, e_stack);
assert(ret == 0);
/* rename an attribute */
ret = H5Arename_ff(gid1, "GROUP_ATTR", "RENAMED_GROUP_ATTR", tid2, e_stack);
assert(ret == 0);
ret = H5Aclose_ff(aid2, e_stack);
assert(ret == 0);
ret = H5Aclose_ff(aid3, e_stack);
assert(ret == 0);
ret = H5Aclose_ff(aid4, e_stack);
assert(ret == 0);
ret = H5Aclose_ff(aid5, e_stack);
assert(ret == 0);
ret = H5Dclose_ff(did1, e_stack);
assert(ret == 0);
ret = H5Mclose_ff(map, e_stack);
assert(ret == 0);
ret = H5Gclose_ff(gid1, e_stack);
assert(ret == 0);
/* make this synchronous so we know the container version has been acquired */
ret = H5TRfinish(tid2, H5P_DEFAULT, &rid3, H5_EVENT_STACK_NULL);
assert(0 == ret);
/* release container version 2. This is async. */
ret = H5RCrelease(rid2, e_stack);
assert(0 == ret);
version = 3;
}
H5ESget_count(e_stack, &num_events);
H5ESwait_all(e_stack, &status);
H5ESclear(e_stack);
printf("%d events in event stack. Completion status = %d\n", num_events, status);
if(0 != num_events) assert(status == H5ES_STATUS_SUCCEED);
/* Tell other procs that container version 3 is acquired */
MPI_Bcast(&version, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD);
/* other processes just create a read context object; no need to
acquire it */
if(0 != my_rank) {
assert(3 == version);
rid3 = H5RCcreate(file_id, version);
assert(rid3 > 0);
}
/* do some reads/gets from container version 1 */
ret = H5Aexists_ff(file_id, "ROOT_ATTR", &exists1, rid3, e_stack);
assert(ret == 0);
ret = H5Aexists_by_name_ff(file_id, "G1", "RENAMED_GROUP_ATTR", H5P_DEFAULT,
&exists2, rid3, e_stack);
assert(ret == 0);
gid1 = H5Gopen_ff(file_id, "G1", H5P_DEFAULT, rid3, e_stack);
aid2 = H5Aopen_ff(gid1, "RENAMED_GROUP_ATTR", H5P_DEFAULT, rid3, e_stack);
assert(aid2);
ret = H5Aread_ff(aid2, dtid, rdata2, rid3, e_stack);
assert(ret == 0);
aid5 = H5Aopen_by_name_ff(file_id, "MAP1", "MAP_ATTR", H5P_DEFAULT,
H5P_DEFAULT, rid3, e_stack);
assert(aid5);
ret = H5Aread_ff(aid5, stype_id, str_data, rid3, e_stack);
assert(ret == 0);
ret = H5Aclose_ff(aid2, e_stack);
assert(ret == 0);
ret = H5Aclose_ff(aid5, e_stack);
assert(ret == 0);
ret = H5Gclose_ff(gid1, e_stack);
assert(ret == 0);
H5ESget_count(e_stack, &num_events);
H5ESwait_all(e_stack, &status);
H5ESclear(e_stack);
printf("%d events in event stack. Completion status = %d\n", num_events, status);
if(0 != num_events) assert(status == H5ES_STATUS_SUCCEED);
/* barrier so root knows all are done reading */
MPI_Barrier(MPI_COMM_WORLD);
if(my_rank == 0) {
/* Local op */
ret = H5TRclose(tid2);
assert(0 == ret);
/* release container version 3. This is async. */
ret = H5RCrelease(rid3, e_stack);
assert(0 == ret);
}
ret = H5Sclose(sid);
assert(ret == 0);
ret = H5Tclose(dtid);
assert(ret == 0);
ret = H5Tclose(stype_id);
assert(ret == 0);
ret = H5Pclose(fapl_id);
assert(ret == 0);
H5Fclose_ff(file_id, 1, H5_EVENT_STACK_NULL);
H5ESget_count(e_stack, &num_events);
H5ESwait_all(e_stack, &status);
H5ESclear(e_stack);
printf("%d events in event stack. Completion status = %d\n", num_events, status);
if(0 != num_events) assert(status == H5ES_STATUS_SUCCEED);
if(0 == my_rank) {
ret = H5RCclose(rid1);
assert(0 == ret);
ret = H5RCclose(rid2);
assert(0 == ret);
}
ret = H5RCclose(rid3);
assert(0 == ret);
assert(!exists1);
assert(exists2);
fprintf(stderr, "RENAMED_GROUP_ATTR value: ");
for(i=0;i<nelem;++i)
fprintf(stderr, "%d ",rdata2[i]);
fprintf(stderr, "\n");
fprintf(stderr, "MAP_ATTR value: %s\n", str_data);
ret = H5ESclose(e_stack);
assert(ret == 0);
free(wdata1);
free(wdata2);
free(rdata1);
free(rdata2);
MPI_Barrier(MPI_COMM_WORLD);
EFF_finalize();
MPI_Finalize();
return 0;
}
|