/* * test_client_obj.c: Client side of H5O routines */ #include #include #include #include #include "mpi.h" #include "hdf5.h" #define NELEM 60 #define NKVP 10 static hid_t gid=-1, did=-1, map=-1, dtid=-1, sid=-1; int my_rank, my_size; static void prefetch (int local_ion, int sub_obj, hid_t rcxt) { hrpl_t map_replica, dt_replica, dset_replica, grp_replica; hid_t dxpl_id; int key, value, i; int32_t rdata1[NELEM]; herr_t ret; if((my_size > 1 && 1 == my_rank) || (my_size == 1 && 0 == my_rank)) { /* prefetch objects */ dxpl_id = H5Pcreate (H5P_DATASET_XFER); if(sub_obj) { hsize_t start=0, count=NELEM/2; H5Sselect_hyperslab(sid, H5S_SELECT_SET, &start, NULL, &count, NULL); H5Pset_prefetch_selection(dxpl_id, sid); } if(local_ion) H5Pset_prefetch_layout(dxpl_id, H5_LOCAL_NODE); ret = H5Dprefetch_ff(did, rcxt, &dset_replica, dxpl_id, H5_EVENT_STACK_NULL); assert(0 == ret); printf("prefetched dataset with replica id %"PRIx64"\n", dset_replica); H5Pclose(dxpl_id); /* prefetch objects */ dxpl_id = H5Pcreate (H5P_DATASET_XFER); if(sub_obj) { int low_key = 3; int high_key = 8; H5Pset_prefetch_range(dxpl_id, H5T_STD_I32LE, &low_key, &high_key); } if(local_ion) H5Pset_prefetch_layout(dxpl_id, H5_LOCAL_NODE); ret = H5Mprefetch_ff(map, rcxt, &map_replica, dxpl_id, H5_EVENT_STACK_NULL); assert(0 == ret); printf("prefetched map with replica id %"PRIx64"\n", map_replica); H5Pclose(dxpl_id); dxpl_id = H5Pcreate (H5P_DATASET_XFER); if(local_ion) H5Pset_prefetch_layout(dxpl_id, H5_LOCAL_NODE); ret = H5Tprefetch_ff(dtid, rcxt, &dt_replica, dxpl_id, H5_EVENT_STACK_NULL); assert(0 == ret); printf("prefetched datatype with replica id %"PRIx64"\n", dt_replica); ret = H5Gprefetch_ff(gid, rcxt, &grp_replica, dxpl_id, H5_EVENT_STACK_NULL); assert(0 == ret); printf("prefetched group with replica id %"PRIx64"\n", grp_replica); H5Pclose(dxpl_id); } if(my_size > 1) { MPI_Bcast(&map_replica, 1, MPI_UINT64_T, 1, MPI_COMM_WORLD); MPI_Bcast(&dt_replica, 1, MPI_UINT64_T, 1, MPI_COMM_WORLD); MPI_Bcast(&dset_replica, 1, MPI_UINT64_T, 1, MPI_COMM_WORLD); MPI_Bcast(&grp_replica, 1, MPI_UINT64_T, 1, MPI_COMM_WORLD); } /* Read from prefetched Replicas */ /* set dxpl to read from replica in BB */ dxpl_id = H5Pcreate (H5P_DATASET_XFER); ret = H5Pset_dxpl_replica(dxpl_id, dset_replica); assert(0 == ret); ret = H5Dread_ff(did, dtid, H5S_ALL, H5S_ALL, dxpl_id, rdata1, rcxt, H5_EVENT_STACK_NULL); assert(ret == 0); printf("Read Data1: "); for(i=0;i 0); /* create 1-D dataspace with 60 elements */ dims [0] = NELEM; sid = H5Screate_simple(1, dims, NULL); dtid = H5Tcopy(H5T_STD_I32LE); /* 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. */ if(0 == my_rank) { version = 1; rid1 = H5RCacquire(file_id, &version, H5P_DEFAULT, H5_EVENT_STACK_NULL); } MPI_Bcast(&version, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD); assert(1 == version); if (my_rank != 0) rid1 = H5RCcreate(file_id, version); /* 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) { hid_t rid_temp; /* create transaction object */ tid1 = H5TRcreate(file_id, rid1, (uint64_t)2); assert(tid1); ret = H5TRstart(tid1, H5P_DEFAULT, e_stack); assert(0 == ret); /* create objects */ gid = H5Gcreate_ff(file_id, "G1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack); assert(gid >= 0); did = H5Dcreate_ff(gid, "D1", dtid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack); assert(did >= 0); ret = H5Dwrite_ff(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata1, tid1, e_stack); assert(ret == 0); ret = H5Tcommit_ff(file_id, "DT1", dtid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, tid1, e_stack); assert(ret == 0); map = H5Mcreate_ff(file_id, "MAP1", H5T_STD_I32LE, H5T_STD_I32LE, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT, tid1, e_stack); assert(map >= 0); /* write some KV pairs to each map object. */ for(i=0; i 0); } if(0 == my_rank) { /* Close transaction object. Local op */ ret = H5TRclose(tid2); assert(0 == ret); ret = H5RCpersist(rid2, H5_EVENT_STACK_NULL); assert(ret == 0); } MPI_Barrier(MPI_COMM_WORLD); gid = H5Oopen_ff(file_id, "G1", H5P_DEFAULT, rid2); assert(gid); dtid = H5Oopen_ff(file_id, "DT1", H5P_DEFAULT, rid2); assert(dtid); did = H5Oopen_ff(gid,"D1", H5P_DEFAULT, rid2); assert(did); map = H5Oopen_ff(file_id,"MAP1", H5P_DEFAULT, rid2); assert(map); MPI_Barrier(MPI_COMM_WORLD); if((my_size > 1 && 1 == my_rank) || (my_size == 1 && 0 == my_rank)) { ret = H5Tevict_ff(dtid, 3, H5P_DEFAULT, H5_EVENT_STACK_NULL); assert(0 == ret); ret = H5Devict_ff(did, 3, H5P_DEFAULT, H5_EVENT_STACK_NULL); assert(0 == ret); ret = H5Mevict_ff(map, 3, H5P_DEFAULT, H5_EVENT_STACK_NULL); assert(0 == ret); ret = H5Gevict_ff(gid, 3, H5P_DEFAULT, H5_EVENT_STACK_NULL); assert(0 == ret); } MPI_Barrier(MPI_COMM_WORLD); if(0 == my_rank) { printf("***************************************************************\n"); printf("TESTING Prefetch - Default layout, Default partition\n"); } MPI_Barrier(MPI_COMM_WORLD); prefetch(0, 0, rid2); MPI_Barrier(MPI_COMM_WORLD); if(0 == my_rank) { printf("***************************************************************\n"); printf("TESTING Prefetch - NON-Default layout, Default partition\n"); } MPI_Barrier(MPI_COMM_WORLD); prefetch(1, 0, rid2); MPI_Barrier(MPI_COMM_WORLD); if(0 == my_rank) { printf("***************************************************************\n"); printf("TESTING Prefetch - Default layout, NON-Default partition\n"); } MPI_Barrier(MPI_COMM_WORLD); prefetch(0, 1, rid2); MPI_Barrier(MPI_COMM_WORLD); if(0 == my_rank) { printf("***************************************************************\n"); printf("TESTING Prefetch - NON-Default layout, NON-Default partition\n"); } MPI_Barrier(MPI_COMM_WORLD); prefetch(1, 1, rid2); MPI_Barrier(MPI_COMM_WORLD); if(my_rank == 0) { /* release container version 3. */ ret = H5RCrelease(rid2, H5_EVENT_STACK_NULL); assert(0 == ret); } assert(H5Oclose_ff(gid, e_stack) == 0); assert(H5Oclose_ff(did, e_stack) == 0); assert(H5Oclose_ff(dtid, e_stack) == 0); assert(H5Oclose_ff(map, e_stack) == 0); ret = H5RCclose(rid1); assert(0 == ret); ret = H5RCclose(rid2); assert(0 == ret); /* wait on all requests and print completion status */ 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); /* closing the container also acts as a wait all on all pending requests on the container. */ assert(H5Fclose_ff(file_id, 1, H5_EVENT_STACK_NULL) == 0); H5Sclose(sid); H5Pclose(fapl_id); H5ESclose(e_stack); /* 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 */ MPI_Barrier(MPI_COMM_WORLD); ret = EFF_finalize(); assert(ret >= 0); MPI_Finalize(); return 0; }