Skip to content

Commit

Permalink
Qiao develop (#12)
Browse files Browse the repository at this point in the history
* fixed region problems

* Update write_obj_shared.c

* Update obj_round_robin_io.c

* Update readme.md

* Update readme.md

* obj get data

* Update obj_get_data.c

* Update obj_get_data.c

* Update obj_get_data.c

* fix get data

* Update obj_get_data.c

* Update obj_get_data.c

* Update obj_get_data.c

* Update obj_round_robin_io.c
  • Loading branch information
Qiao Kang authored Mar 12, 2021
1 parent 3b7aa57 commit d4eb9d0
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 50 deletions.
10 changes: 5 additions & 5 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
+ remote_reg: Remote region ID
- Output:
+ Region ID
- Create a region with ndims offset/length pairs
- Create a region with ndims offset/length pairs. At this stage of PDC development, the buffer has to be filled if you are performing PDC_WRITE with lock and release functions.
- For developers: see pdc_region.c. Need to use PDC_get_kvtag to submit RPCs to the servers for metadata update.
+ perr_t PDCbuf_obj_unmap(pdcid_t remote_obj_id, pdcid_t remote_reg_id)
- Input:
Expand All @@ -291,7 +291,7 @@
+ perr_t PDCreg_obtain_lock(pdcid_t obj_id, pdcid_t reg_id, pdc_access_t access_type, pdc_lock_mode_t lock_mode)
- Input:
+ obj_id: local object ID
+ reg_id: local region ID
+ reg_id: remote region ID
+ access_type: [PDC access type](#access-type)
+ lock_mode: PDC_BLOCK or PDC_NOBLOCK
- Output:
Expand All @@ -301,11 +301,11 @@
+ perr_t PDCreg_release_lock(pdcid_t obj_id, pdcid_t reg_id, pdc_access_t access_type)
- Input:
+ obj_id: local object ID
+ reg_id: local region ID
+ reg_id: remote region ID
+ access_type: [PDC access type](#access-type)
- Output:
+ error code, SUCCEED or FAIL.
- Release the lock to access a region in an object.
+ error code, SUCCESS or FAIL.
- Release the lock to access a region in an object. PDC_READ data is available after this lock release.
- For developers: see pdc_region.c.
## PDC property APIs
+ pdcid_t PDCprop_create(pdc_prop_type_t type, pdcid_t pdcid)
Expand Down
52 changes: 29 additions & 23 deletions src/api/pdc_client_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -6262,36 +6262,42 @@ PDCobj_put_data(const char *obj_name, void *data, uint64_t size, pdcid_t cont_id
FUNC_LEAVE(ret_value);
}

perr_t PDCobj_get_data(pdcid_t obj_id, void **data, uint64_t *size ATTRIBUTE(unused) )
perr_t PDCobj_get_data(pdcid_t obj_id, void *data, uint64_t size)
{
perr_t ret_value = SUCCEED;
struct pdc_region_info obj_region;
char *obj_name;
pdc_metadata_t *meta;
struct _pdc_obj_info *obj_prop;

FUNC_ENTER(NULL);
uint64_t offset = 0;
pdcid_t reg, reg_global;
reg = PDCregion_create(1, &offset, &size);
reg_global = PDCregion_create(1, &offset, &size);

obj_region.ndim = 1;
obj_region.offset = 0;
obj_region.size = 0; // TODO: size=0 means read entire object
ret_value = PDCbuf_obj_map(data, PDC_CHAR, reg, obj_id, reg_global);
if (ret_value != SUCCEED) {
goto done;
}

obj_prop = PDC_obj_get_info(obj_id);
obj_name = obj_prop->obj_info_pub->name;
ret_value = PDCreg_obtain_lock(obj_id, reg_global, PDC_READ, PDC_BLOCK);
if (ret_value != SUCCEED) {
goto done;
}

#ifdef ENABLE_MPI
ret_value = PDC_Client_query_metadata_name_timestep_agg(obj_name, 0, &meta);
#else
ret_value = PDC_Client_query_metadata_name_timestep(obj_name, 0, &meta);
#endif
ret_value = PDCreg_release_lock(obj_id, reg_global, PDC_READ);
if (ret_value != SUCCEED) {
goto done;
}

ret_value = PDC_Client_read(meta, &obj_region, data);
if (ret_value != SUCCEED)
PGOTO_ERROR(FAIL, "==PDC_CLIENT[%d]: Error with PDC_Client_write_id for obj",
pdc_client_mpi_rank_g);
ret_value = PDCbuf_obj_unmap(obj_id, reg_global);
if (ret_value != SUCCEED) {
goto done;
}

free(meta);

ret_value = PDCregion_close(reg);
if (ret_value != SUCCEED) {
goto done;
}
ret_value = PDCregion_close(reg_global);
if (ret_value != SUCCEED) {
goto done;
}
done:
fflush(stdout);
FUNC_LEAVE(ret_value);
Expand Down
2 changes: 1 addition & 1 deletion src/api/pdc_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pdcid_t PDCobj_put_data(const char *obj_name, void *data, uint64_t size, pdcid_t
*
* \return Non-negative on success/Negative on failure
*/
perr_t PDCobj_get_data(pdcid_t obj_id, void **data, uint64_t *size);
perr_t PDCobj_get_data(pdcid_t obj_id, void *data, uint64_t size);

/**
* ***********
Expand Down
3 changes: 3 additions & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(PROGRAMS
obj_buf
obj_tags
obj_put_data
obj_get_data
open_obj_round_robin
region_obj_map_2D
region_obj_map_3D
Expand Down Expand Up @@ -142,6 +143,7 @@ add_test(NAME obj_buf WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} CO
add_test(NAME obj_tags WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./obj_tags )
add_test(NAME obj_info WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./obj_info )
add_test(NAME obj_put_data WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./obj_put_data )
add_test(NAME obj_get_data WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./obj_get_data )
add_test(NAME create_region WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./create_region )
add_test(NAME region_obj_map WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./region_obj_map )
add_test(NAME region_obj_map_2D WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND run_test.sh ./region_obj_map_2D )
Expand Down Expand Up @@ -202,6 +204,7 @@ if(BUILD_MPI_TESTING)
add_test(NAME obj_tags_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./obj_tags ${MPI_RUN_CMD} 2 4 )
add_test(NAME obj_info_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./obj_info ${MPI_RUN_CMD} 2 4 )
add_test(NAME obj_put_data_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./obj_put_data ${MPI_RUN_CMD} 2 4 )
add_test(NAME obj_get_data_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./obj_get_data ${MPI_RUN_CMD} 2 4 )
add_test(NAME create_region_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./create_region ${MPI_RUN_CMD} 2 4 )
add_test(NAME region_obj_map_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./region_obj_map ${MPI_RUN_CMD} 2 4 )
add_test(NAME write_obj_mpi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND mpi_test.sh ./write_obj ${MPI_RUN_CMD} 2 4 o 1 int)
Expand Down
154 changes: 154 additions & 0 deletions src/tests/obj_get_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright Notice for
* Proactive Data Containers (PDC) Software Library and Utilities
* -----------------------------------------------------------------------------
*** Copyright Notice ***
* Proactive Data Containers (PDC) Copyright (c) 2017, The Regents of the
* University of California, through Lawrence Berkeley National Laboratory,
* UChicago Argonne, LLC, operator of Argonne National Laboratory, and The HDF
* Group (subject to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved.
* If you have questions about your rights to use or distribute this software,
* please contact Berkeley Lab's Innovation & Partnerships Office at IPO@lbl.gov.
* NOTICE. This Software was developed under funding from the U.S. Department of
* Energy and the U.S. Government consequently retains certain rights. As such, the
* U.S. Government has been granted for itself and others acting on its behalf a
* paid-up, nonexclusive, irrevocable, worldwide license in the Software to
* reproduce, distribute copies to the public, prepare derivative works, and
* perform publicly and display publicly, and to permit other to do so.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pdc.h"


int main(int argc, char **argv) {
pdcid_t pdc, cont_prop, cont;
pdcid_t obj1, obj2;
perr_t error_code;
char cont_name[128], obj_name1[128], obj_name2[128];

int rank = 0, size = 1;
unsigned i;
int ret_value = 0;

char *data = (char*)malloc(sizeof(double)*128);

#ifdef ENABLE_MPI
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
#endif
// create a pdc
pdc = PDCinit("pdc");
printf("create a new pdc\n");

// create a container property
cont_prop = PDCprop_create(PDC_CONT_CREATE, pdc);
if(cont_prop > 0) {
printf("Create a container property\n");
} else {
printf("Fail to create container property @ line %d!\n", __LINE__);
ret_value = 1;
}
// create a container
sprintf(cont_name, "c%d", rank);
cont = PDCcont_create(cont_name, cont_prop);
if(cont > 0) {
printf("Rank %d Create a container %s\n", rank, cont_name);
} else {
printf("Fail to create container @ line %d!\n", __LINE__);
ret_value = 1;
}

memset(data, 1, 128 * sizeof(double));
sprintf(obj_name1, "o1_%d", rank);
obj1 = PDCobj_put_data(obj_name1, (void*)data, 16*sizeof(double), cont);
if(obj1 > 0) {
printf("Rank %d Put data to %s\n", rank, obj_name1);
} else {
printf("Fail to put data into object @ line %d!\n", __LINE__);
ret_value = 1;
}

memset(data, 2, 128 * sizeof(double));
sprintf(obj_name2, "o2_%d", rank);
obj2 = PDCobj_put_data(obj_name2, (void*)data, 128*sizeof(double), cont);
if(obj2 > 0) {
printf("Rank %d Put data to %s\n", rank, obj_name2);
} else {
printf("Fail to put data into object @ line %d!\n", __LINE__);
ret_value = 1;
}

memset(data, 0, 128 * sizeof(double));
error_code = PDCobj_get_data(obj1, (void*)(data), 16 * sizeof(double));
if (error_code!= SUCCEED) {
printf("Fail to get obj 1 data\n");
ret_value = 1;
}
for ( i = 0; i < 16*sizeof(double); ++i ) {
if (data[i] != 1) {
printf("wrong value at obj 1\n");
ret_value = 1;
break;
}
}
memset(data, 0, 128 * sizeof(double));
error_code = PDCobj_get_data(obj2, (void*)(data), 128 * sizeof(double));
if (error_code!= SUCCEED) {
printf("Fail to get obj 1 data\n");
ret_value = 1;
}
for ( i = 0; i < 128*sizeof(double); ++i ) {
if (data[i] != 2) {
printf("wrong value at obj 2\n");
ret_value = 1;
break;
}
}

// close object
if(PDCobj_close(obj1) < 0) {
printf("fail to close object o1\n");
ret_value = 1;
} else {
printf("successfully close object o1\n");
}
if(PDCobj_close(obj2) < 0) {
printf("fail to close object o2\n");
ret_value = 1;
} else {
printf("successfully close object o2\n");
}

// close a container
if(PDCcont_close(cont) < 0) {
printf("fail to close container c1\n");
ret_value = 1;
} else {
printf("successfully close container c1\n");
}
// close a container property
if(PDCprop_close(cont_prop) < 0) {
printf("Fail to close property @ line %d\n", __LINE__);
ret_value = 1;
} else {
printf("successfully close container property\n");
}
// close pdc
if(PDCclose(pdc) < 0) {
printf("fail to close PDC\n");
ret_value = 1;
}
#ifdef ENABLE_MPI
MPI_Finalize();
#endif
return ret_value;
}
12 changes: 6 additions & 6 deletions src/tests/obj_round_robin_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ int main(int argc, char **argv) {
printf("PDCbuf_obj_map failed\n");
ret_value = 1;
}
ret = PDCreg_obtain_lock(obj1, local_region, PDC_WRITE, PDC_BLOCK);
ret = PDCreg_obtain_lock(obj1, global_region, PDC_WRITE, PDC_BLOCK);
if (ret != SUCCEED) {
printf("Failed to obtain lock for region\n");
ret_value = 1;
}
ret = PDCreg_release_lock(obj1, local_region, PDC_WRITE);
ret = PDCreg_release_lock(obj1, global_region, PDC_WRITE);
if (ret != SUCCEED) {
printf("Failed to release lock for region\n");
ret_value = 1;
Expand Down Expand Up @@ -219,12 +219,12 @@ int main(int argc, char **argv) {
printf("PDCbuf_obj_map failed %d\n", __LINE__);
ret_value = 1;
}
ret = PDCreg_obtain_lock(obj2, local_region, PDC_WRITE, PDC_BLOCK);
ret = PDCreg_obtain_lock(obj2, global_region, PDC_WRITE, PDC_BLOCK);
if (ret != SUCCEED) {
printf("Failed to obtain lock for region %d\n", __LINE__);
ret_value = 1;
}
ret = PDCreg_release_lock(obj2, local_region, PDC_WRITE);
ret = PDCreg_release_lock(obj2, global_region, PDC_WRITE);
if (ret != SUCCEED) {
printf("Failed to release lock for region %d\n", __LINE__);
ret_value = 1;
Expand Down Expand Up @@ -301,13 +301,13 @@ int main(int argc, char **argv) {
ret_value = 1;
}

ret = PDCreg_obtain_lock(obj2, local_region, PDC_READ, PDC_BLOCK);
ret = PDCreg_obtain_lock(obj2, global_region, PDC_READ, PDC_BLOCK);
if(ret != SUCCEED) {
printf("PDCreg_obtain_lock failed %d\n", __LINE__);
ret_value = 1;
}

ret = PDCreg_release_lock(obj2, local_region, PDC_READ);
ret = PDCreg_release_lock(obj2, global_region, PDC_READ);
if(ret != SUCCEED) {
printf("PDCreg_release_lock failed %d\n", __LINE__);
ret_value = 1;
Expand Down
Loading

0 comments on commit d4eb9d0

Please sign in to comment.