|
13 | 13 | #include <stdio.h> |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <string.h> /* strcpy(), strncpy(), strstr() */ |
16 | | -#include <unistd.h> /* getopt() */ |
| 16 | +#include <unistd.h> /* getopt(), unlink() */ |
17 | 17 |
|
18 | 18 | #include <mpi.h> |
19 | 19 |
|
@@ -235,6 +235,82 @@ int set_info(e3sm_io_config *cfg, |
235 | 235 | return err; |
236 | 236 | } |
237 | 237 |
|
| 238 | +/*----< delete_output_files() >----------------------------------------------*/ |
| 239 | +static |
| 240 | +void delete_output_files(e3sm_io_config *cfg) |
| 241 | +{ |
| 242 | + char *filename, *base, *ext, *out_path_h0, *out_path_h1; |
| 243 | + size_t len; |
| 244 | + |
| 245 | + if (cfg->rank > 0) goto fnc_exit; |
| 246 | + |
| 247 | + /* remove file system type prefix, if there is any */ |
| 248 | + filename = strchr(cfg->out_path, ':'); |
| 249 | + if (filename == NULL) |
| 250 | + filename = cfg->out_path; |
| 251 | + else |
| 252 | + filename++; |
| 253 | + |
| 254 | + len = strlen(filename) + 8; |
| 255 | + |
| 256 | + out_path_h0 = (char*) malloc(len); |
| 257 | + out_path_h1 = (char*) malloc(len); |
| 258 | + |
| 259 | + base = strdup(filename); |
| 260 | + ext = strrchr(base, '.'); |
| 261 | + if (ext != NULL) { |
| 262 | + *ext = '\0'; |
| 263 | + ext++; |
| 264 | + } |
| 265 | + |
| 266 | + if (ext == NULL || (strcmp(ext, "nc") && strcmp(ext, "h5") && strcmp(ext, "nc4") && strcmp(ext, "bp"))) { |
| 267 | + sprintf(out_path_h0, "%s_h0", filename); |
| 268 | + sprintf(out_path_h1, "%s_h1", filename); |
| 269 | + } else { |
| 270 | + sprintf(out_path_h0, "%s_h0.%s", base, ext); |
| 271 | + sprintf(out_path_h1, "%s_h1.%s", base, ext); |
| 272 | + } |
| 273 | + free(base); |
| 274 | + |
| 275 | + /* delete the output file and ignore the error */ |
| 276 | + if (cfg->run_case == G) { |
| 277 | + unlink(filename); |
| 278 | + if (cfg->strategy == blob && cfg->api != adios) { |
| 279 | + char *out_path_subfile = (char*) malloc(len); |
| 280 | + sprintf(out_path_subfile, "%s.%04d", filename, cfg->subfile_ID); |
| 281 | + unlink(out_path_subfile); |
| 282 | + free(out_path_subfile); |
| 283 | + } |
| 284 | + } else { /* F and I cases */ |
| 285 | + if (cfg->hx == 0 || cfg->hx == -1) { /* h0 file */ |
| 286 | + unlink(out_path_h0); |
| 287 | + if (cfg->strategy == blob && cfg->api != adios) { |
| 288 | + char *out_path_subfile_h0 = (char*) malloc(len); |
| 289 | + /* append subfile ID */ |
| 290 | + sprintf(out_path_subfile_h0, "%s.%04d", out_path_h0, cfg->subfile_ID); |
| 291 | + unlink(out_path_subfile_h0); |
| 292 | + free(out_path_subfile_h0); |
| 293 | + } |
| 294 | + } |
| 295 | + if (cfg->hx == 1 || cfg->hx == -1) { /* h1 file */ |
| 296 | + unlink(out_path_h1); |
| 297 | + if (cfg->strategy == blob && cfg->api != adios) { |
| 298 | + char *out_path_subfile_h1 = (char*) malloc(len); |
| 299 | + /* append subfile ID */ |
| 300 | + sprintf(out_path_subfile_h1, "%s.%04d", out_path_h1, cfg->subfile_ID); |
| 301 | + unlink(out_path_subfile_h1); |
| 302 | + free(out_path_subfile_h1); |
| 303 | + } |
| 304 | + } |
| 305 | + } |
| 306 | + |
| 307 | + free(out_path_h0); |
| 308 | + free(out_path_h1); |
| 309 | + |
| 310 | +fnc_exit: |
| 311 | + MPI_Barrier(cfg->io_comm); |
| 312 | +} |
| 313 | + |
238 | 314 | /*----< print_info() >------------------------------------------------------*/ |
239 | 315 | void print_info (MPI_Info *info_used) { |
240 | 316 | int i, nkeys; |
@@ -370,24 +446,13 @@ int main (int argc, char **argv) { |
370 | 446 | cfg.factor = 1; |
371 | 447 |
|
372 | 448 | for (i = 0; i < MAX_NUM_DECOMP; i++) { |
373 | | - cfg.G_case.nvars_D[i] = 0; |
374 | | - cfg.F_case_h0.nvars_D[i] = 0; |
375 | | - cfg.F_case_h1.nvars_D[i] = 0; |
376 | | - cfg.I_case_h0.nvars_D[i] = 0; |
377 | | - cfg.I_case_h1.nvars_D[i] = 0; |
378 | | - |
379 | | - cfg.G_case.num_attrs = 0; |
380 | | - cfg.F_case_h0.num_attrs = 0; |
381 | | - cfg.F_case_h1.num_attrs = 0; |
382 | | - cfg.I_case_h0.num_attrs = 0; |
383 | | - cfg.I_case_h1.num_attrs = 0; |
384 | | - |
385 | 449 | decom.blocklens[i] = NULL; |
386 | 450 | decom.disps[i] = NULL; |
387 | 451 | decom.raw_offsets[i] = NULL; |
388 | 452 | decom.w_starts[i] = NULL; |
389 | 453 | decom.max_nreqs[i] = 0; |
390 | 454 | } |
| 455 | + |
391 | 456 | ffreq = 1; |
392 | 457 |
|
393 | 458 | /* command-line arguments */ |
@@ -449,11 +514,11 @@ int main (int argc, char **argv) { |
449 | 514 | break; |
450 | 515 |
|
451 | 516 | case 'o': |
452 | | - strncpy(cfg.out_path, optarg, E3SM_IO_MAX_PATH); |
| 517 | + strncpy(cfg.out_path, optarg, E3SM_IO_MAX_PATH-1); |
453 | 518 | cfg.wr = 1; |
454 | 519 | break; |
455 | 520 | case 'i': |
456 | | - strncpy(cfg.in_path, optarg, E3SM_IO_MAX_PATH); |
| 521 | + strncpy(cfg.in_path, optarg, E3SM_IO_MAX_PATH-1); |
457 | 522 | cfg.rd = 1; |
458 | 523 | break; |
459 | 524 | case 'm': |
@@ -508,7 +573,7 @@ int main (int argc, char **argv) { |
508 | 573 | if (!cfg.rank) usage(argv[0]); |
509 | 574 | ERR_OUT("Decomposition file not provided") |
510 | 575 | } |
511 | | - strncpy(cfg.decomp_path, argv[optind], E3SM_IO_MAX_PATH); |
| 576 | + strncpy(cfg.decomp_path, argv[optind], E3SM_IO_MAX_PATH-1); |
512 | 577 |
|
513 | 578 | cfg.F_case_h0.nrecs = 1; /* force only one record for F h0 case */ |
514 | 579 | cfg.F_case_h1.nrecs = nrecs; |
@@ -678,7 +743,8 @@ int main (int argc, char **argv) { |
678 | 743 |
|
679 | 744 | char *hint_lines[64]; |
680 | 745 | int num_hint_lines; |
681 | | - parse_hint_file(&cfg, "e3sm_io_hints.txt", &num_hint_lines, hint_lines); |
| 746 | + // parse_hint_file(&cfg, "e3sm_io_hints.txt", &num_hint_lines, hint_lines); |
| 747 | + parse_hint_file(&cfg, "/pscratch/sd/w/wkliao/e3sm_io_hints.txt", &num_hint_lines, hint_lines); |
682 | 748 |
|
683 | 749 | timing[1] = MPI_Wtime() - timing[1]; |
684 | 750 | MPI_Barrier(MPI_COMM_WORLD); |
@@ -708,7 +774,27 @@ int main (int argc, char **argv) { |
708 | 774 |
|
709 | 775 | char *hint_str = (num_hint_lines == 0) ? NULL : hint_lines[j]; |
710 | 776 |
|
711 | | -if (cfg.rank == 0) printf("\nHINTS: %s\n\n", (hint_str) ? hint_str : ""); |
| 777 | + if (cfg.rank == 0) { |
| 778 | + printf("\nHINTS: %s\n\n", (hint_str) ? hint_str : ""); |
| 779 | + fflush(stdout); |
| 780 | + } |
| 781 | + |
| 782 | + /* reset counters */ |
| 783 | + for (i = 0; i < MAX_NUM_DECOMP; i++) { |
| 784 | + cfg.G_case.nvars_D[i] = 0; |
| 785 | + cfg.F_case_h0.nvars_D[i] = 0; |
| 786 | + cfg.F_case_h1.nvars_D[i] = 0; |
| 787 | + cfg.I_case_h0.nvars_D[i] = 0; |
| 788 | + cfg.I_case_h1.nvars_D[i] = 0; |
| 789 | + } |
| 790 | + cfg.G_case.num_attrs = 0; |
| 791 | + cfg.F_case_h0.num_attrs = 0; |
| 792 | + cfg.F_case_h1.num_attrs = 0; |
| 793 | + cfg.I_case_h0.num_attrs = 0; |
| 794 | + cfg.I_case_h1.num_attrs = 0; |
| 795 | + |
| 796 | + /* delete output files */ |
| 797 | + delete_output_files(&cfg); |
712 | 798 |
|
713 | 799 | /* set MPI-IO and PnetCDF hints */ |
714 | 800 | err = set_info(&cfg, hint_str); |
@@ -743,7 +829,7 @@ if (cfg.rank == 0) printf("\nHINTS: %s\n\n", (hint_str) ? hint_str : ""); |
743 | 829 | } |
744 | 830 | } |
745 | 831 |
|
746 | | - if (cfg.info != MPI_INFO_NULL) MPI_Info_free (&(cfg.info)); |
| 832 | + if (cfg.info != MPI_INFO_NULL) MPI_Info_free(&cfg.info); |
747 | 833 |
|
748 | 834 | timing[0] = timing[1] + timing[2] + timing[3]; |
749 | 835 | MPI_Reduce(timing, max_t, 4, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); |
|
0 commit comments