|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | +#include "pdc.h" |
| 5 | + |
| 6 | +int |
| 7 | +main(int argc, char **argv) |
| 8 | +{ |
| 9 | + pdcid_t pdc_id, cont_id, cont_prop, cont_id2, obj_prop, obj_id, global_region_id, transfer_id, local_region_id; |
| 10 | + int rank = 0, size = 1; |
| 11 | + int ret_value = 0; |
| 12 | + |
| 13 | + // create a pdc |
| 14 | +#ifdef ENABLE_MPI |
| 15 | + MPI_Init(&argc, &argv); |
| 16 | + MPI_Comm_rank(MPI_COMM_WORLD, &rank); |
| 17 | + MPI_Comm_size(MPI_COMM_WORLD, &size); |
| 18 | +#endif |
| 19 | + |
| 20 | + pdc_id = PDCinit("pdc"); |
| 21 | + cont_prop = PDCprop_create(PDC_CONT_CREATE, pdc_id); |
| 22 | + if (cont_prop <= 0) |
| 23 | + printf("Fail to create container property @ line %d!\n", __LINE__); |
| 24 | + |
| 25 | + // create a container |
| 26 | + cont_id = PDCcont_create("cont", cont_prop); |
| 27 | + if (cont_id <= 0) |
| 28 | + printf("Fail to create container @ line %d!\n", __LINE__); |
| 29 | + |
| 30 | + //create object and object properties |
| 31 | + obj_prop = PDCprop_create(PDC_OBJ_CREATE, pdc_id); |
| 32 | + if (obj_prop <= 0) |
| 33 | + printf("Fail to create object property @ line %d!\n", __LINE__); |
| 34 | + uint64_t dims[] = {8, 8}; |
| 35 | + if (PDCprop_set_obj_dims(obj_prop, 2, dims) != 0) |
| 36 | + printf("Fail to set object dimensions @ line %d!\n", __LINE__); |
| 37 | + if (PDCprop_set_obj_type(obj_prop, PDC_INT8) != 0) |
| 38 | + printf("Fail to set object type @ line %d!\n", __LINE__); |
| 39 | + obj_id = PDCobj_create(cont_id, "obj", obj_prop); |
| 40 | + if (obj_id <= 0) |
| 41 | + printf("Fail to create object @ line %d!\n", __LINE__); |
| 42 | + |
| 43 | + //get object data. |
| 44 | + int8_t all_data[8*8]; |
| 45 | + PDCobj_get_data(obj_id, all_data, 8*8); |
| 46 | + |
| 47 | + //print all_data in an 8*8 grid |
| 48 | + for (int i = 0; i < 8; i++) |
| 49 | + { |
| 50 | + for (int j = 0; j < 8; j++) |
| 51 | + printf("%d\t", all_data[i*8+j]); |
| 52 | + printf("\n"); |
| 53 | + } |
| 54 | + |
| 55 | + uint64_t global_region_offsets[] = {1, 2}; |
| 56 | + uint64_t global_region_dims[] = {6, 2}; |
| 57 | + |
| 58 | + global_region_id = PDCregion_create(2, global_region_offsets, global_region_dims); |
| 59 | + if (global_region_id <= 0) |
| 60 | + printf("Fail to create region @ line %d!\n", __LINE__); |
| 61 | + |
| 62 | + uint64_t local_region_offsets[] = {0, 0}; |
| 63 | + uint64_t local_region_dims[] = {6, 2}; |
| 64 | + local_region_id = PDCregion_create(2, local_region_offsets, local_region_dims); |
| 65 | + if (local_region_id <= 0) |
| 66 | + printf("Fail to create region @ line %d!\n", __LINE__); |
| 67 | + |
| 68 | + int8_t data_to_send[6][2] = {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}}; |
| 69 | + |
| 70 | + //set object data. |
| 71 | + transfer_id = PDCregion_transfer_create(data_to_send, PDC_WRITE, obj_id, local_region_id, global_region_id); |
| 72 | + if (transfer_id <= 0) |
| 73 | + printf("Fail to create transfer @ line %d!\n", __LINE__); |
| 74 | + if (PDCregion_transfer_start(transfer_id) != SUCCEED) |
| 75 | + printf("Fail to start transfer @ line %d!\n", __LINE__); |
| 76 | + if (PDCregion_transfer_wait(transfer_id) != SUCCEED) |
| 77 | + printf("Fail to wait transfer @ line %d!\n", __LINE__); |
| 78 | + |
| 79 | + if (PDCregion_close(local_region_id) != SUCCEED) |
| 80 | + printf("Fail to close region @ line %d!\n", __LINE__); |
| 81 | + if (PDCregion_close(global_region_id) != SUCCEED) |
| 82 | + printf("Fail to close region @ line %d!\n", __LINE__); |
| 83 | + |
| 84 | + puts("AFTER:"); |
| 85 | + |
| 86 | + //get object data. |
| 87 | + PDCobj_get_data(obj_id, all_data, 8*8); |
| 88 | + |
| 89 | + //print all_data in an 8*8 grid |
| 90 | + for (int i = 0; i < 8; i++) |
| 91 | + { |
| 92 | + for (int j = 0; j < 8; j++) |
| 93 | + printf("%d\t", all_data[i*8+j]); |
| 94 | + printf("\n"); |
| 95 | + } |
| 96 | + |
| 97 | + /*//create output buffer for getting data |
| 98 | + double *data_out = (double *) malloc(sizeof(double) * 128); |
| 99 | + transfer_id = PDCregion_transfer_create(data_out, PDC_READ, obj_id, region_id, region_id); //SEGFAULT HERE |
| 100 | + if (transfer_id <= 0) |
| 101 | + printf("Fail to create transfer @ line %d!\n", __LINE__); |
| 102 | + puts("here"); |
| 103 | + if (PDCregion_transfer_start(transfer_id) != SUCCEED) |
| 104 | + printf("Fail to start transfer @ line %d!\n", __LINE__); |
| 105 | + puts("here"); |
| 106 | + if (PDCregion_transfer_wait(transfer_id) != SUCCEED) |
| 107 | + printf("Fail to wait transfer @ line %d!\n", __LINE__); |
| 108 | + |
| 109 | + for (int i = 0; i < 128; i++) |
| 110 | + if (data[i] != data_out[i]) |
| 111 | + printf("Wrong data value @ line %d!\n", __LINE__);*/ |
| 112 | + |
| 113 | + if (PDCregion_transfer_close(transfer_id) != SUCCEED) |
| 114 | + printf("Fail to close transfer @ line %d!\n", __LINE__); |
| 115 | + if (PDCobj_close(obj_id) != SUCCEED) |
| 116 | + printf("Fail to close object @ line %d!\n", __LINE__); |
| 117 | + if (PDCprop_close(obj_prop) != SUCCEED) |
| 118 | + printf("Fail to close object property @ line %d!\n", __LINE__); |
| 119 | + if (PDCcont_close(cont_id) != SUCCEED) |
| 120 | + printf("Fail to close container @ line %d!\n", __LINE__); |
| 121 | + |
| 122 | + PDCclose(pdc_id); |
| 123 | + |
| 124 | +#ifdef ENABLE_MPI |
| 125 | + MPI_Finalize(); |
| 126 | +#endif |
| 127 | + return ret_value; |
| 128 | +} |
0 commit comments