Skip to content

Commit

Permalink
Add timer
Browse files Browse the repository at this point in the history
  • Loading branch information
houjun committed Sep 30, 2024
1 parent 2eae52c commit 323b712
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/tools/pdc_region_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <unistd.h>
#include <getopt.h>
#include <math.h>
#include <sys/time.h>

#include "pdc.h"

Expand All @@ -42,6 +43,9 @@ main(int argc, char **argv)
void * data;
perr_t ret;
pdc_var_type_t dtype;
struct timeval t0;
struct timeval t1;
double elapsed;

fname = argv[1];

Expand Down Expand Up @@ -100,6 +104,8 @@ main(int argc, char **argv)

transfer_request = PDCregion_transfer_create(data, PDC_WRITE, obj_id, region_local, region_remote);

gettimeofday(&t0, NULL);

ret = PDCregion_transfer_start(transfer_request);
if (ret != SUCCEED) {
printf("Failed to start transfer for region_xx\n");
Expand All @@ -112,6 +118,10 @@ main(int argc, char **argv)
exit(-1);
}

gettimeofday(&t1, NULL);
elapsed = t1.tv_sec - t0.tv_sec + (t1.tv_usec - t0.tv_usec) / 1000000.0;
printf("Pull data to PDC took %.2fs\n", elapsed);

ret = PDCregion_transfer_close(transfer_request);
if (ret != SUCCEED) {
printf("Failed to close region transfer\n");
Expand Down
18 changes: 14 additions & 4 deletions src/tools/pdc_region_push.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <unistd.h>
#include <getopt.h>
#include <math.h>
#include <sys/time.h>

#include "pdc.h"

Expand All @@ -38,17 +39,20 @@ main(int argc, char **argv)
uint64_t *obj_dims, dims[4], offset_local[4] = {0, 0, 0, 0}, offset_remote[4], count[4], total_size,
unit_size = 4;
pdcid_t pdc_id, cont_prop, cont_id, region_local, region_remote, obj_id, transfer_request;
char * cont_name = "c1", *obj_name = "x", out_path[256], out_name[256];
char * cont_name = "c1", *obj_name = "x", *out_path, out_name[256];
void * data;
perr_t ret;
pdc_var_type_t dtype;
struct timeval t0;
struct timeval t1;
double elapsed;

if (argc > 1) {
cont_name = argv[1];
obj_name = argv[2];
}
else {
printf("Usage:\n ./pdc_region_push cont_name, obj_name, ndim, offsets[], counts[]");
printf("Usage:\n ./pdc_region_push cont_name, obj_name, ndim, offsets[], counts[], outpath");
return 0;
}

Expand Down Expand Up @@ -81,14 +85,15 @@ main(int argc, char **argv)
count[i] = atoll(argv[cnt++]);
total_size *= count[i];
}
out_path = argv[cnt];

printf("Transfer obj name [%s]\ndtype:%s\noffsets: ", obj_name, get_enum_name_by_dtype(dtype));
for (i = 0; i < ndim; i++)
printf("%llu ", offset_remote[i]);
printf("\ncounts: ");
for (i = 0; i < ndim; i++)
printf("%llu ", count[i]);
printf("\n");
printf("\nWriting to %s\n", out_path);

data = (void *)malloc(total_size);

Expand Down Expand Up @@ -116,9 +121,10 @@ main(int argc, char **argv)
}

// Write data to a bin file
sprintf(out_path, "./pdc_region_push_data"); // harded coded for now
mkdir(out_path, 0755);
sprintf(out_name, "%s/data.bin", out_path); // harded coded for now
//
gettimeofday(&t0, NULL);

FILE *file = fopen(out_name, "wb");
if (file == NULL) {
Expand All @@ -142,6 +148,10 @@ main(int argc, char **argv)
fwrite(data, sizeof(char), total_size, file);
fclose(file);

gettimeofday(&t1, NULL);
elapsed = t1.tv_sec - t0.tv_sec + (t1.tv_usec - t0.tv_usec) / 1000000.0;
printf("Write data took %.2fs\n", elapsed);

free(data);
ret = PDCobj_close(obj_id);
if (ret < 0) {
Expand Down

0 comments on commit 323b712

Please sign in to comment.