int main(int argc, char * argv[]) { BigFile bf = {0}; BigBlock bb = {0}; int opt; while(-1 != (opt = getopt(argc, argv, "l"))) { switch(opt) { case 'l': longfmt = 1; break; default: usage(); } } argv += optind - 1; if(argc - optind < 2) { usage(); } if(0 != big_file_open(&bf, argv[1])) { fprintf(stderr, "failed to open file : %s %s\n", argv[1], big_file_get_error_message()); exit(1); } if(0 != big_file_open_block(&bf, &bb, argv[2])) { fprintf(stderr, "failed to open block: %s %s\n", argv[2], big_file_get_error_message()); exit(1); } int i; if(argc - optind == 2) { size_t nattr; BigAttr * attrs = big_block_list_attrs(&bb, &nattr); for(i = 0; i < nattr; i ++) { BigAttr * attr = &attrs[i]; print_attr(attr, 0); } } for(i = 3; i < argc - optind + 1; i ++) { BigAttr * attr = big_block_lookup_attr(&bb, argv[i]); if(attr) { print_attr(attr, argc - optind == 3); } else { printf("%s, not attr:\n", argv[i]); } } big_block_close(&bb); big_file_close(&bf); return 0; }
int main(int argc, char * argv[]) { MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask); MPI_Comm_size(MPI_COMM_WORLD, &NTask); MPI_Type_contiguous(2, MPI_LONG, &MPI_TYPE_WORK); MPI_Type_commit(&MPI_TYPE_WORK); int ch; while(-1 != (ch = getopt(argc, argv, "n:N:vb:f:"))) { switch(ch) { case 'N': case 'n': Nfile = atoi(optarg); break; case 'b': sscanf(optarg, "%td", &buffersize); break; case 'f': newfilepath = optarg; break; case 'v': verbose = 1; break; default: usage(); } } if(argc - optind + 1 != 4) { usage(); } argv += optind - 1; if(0 != big_file_mpi_open(&bf, argv[1], MPI_COMM_WORLD)) { fprintf(stderr, "failed to open: %s\n", big_file_get_error_message()); exit(1); } if(0 != big_file_mpi_open_block(&bf, &bb, argv[2], MPI_COMM_WORLD)) { fprintf(stderr, "failed to open: %s\n", big_file_get_error_message()); exit(1); } if(Nfile == -1 || bb.Nfile == 0) { Nfile = bb.Nfile; } if(newfilepath == NULL) { newfilepath = argv[1]; } if(0 != big_file_mpi_create(&bfnew, newfilepath, MPI_COMM_WORLD)) { fprintf(stderr, "failed to open: %s\n", big_file_get_error_message()); exit(1); } if(0 != big_file_mpi_create_block(&bfnew, &bbnew, argv[3], bb.dtype, bb.nmemb, Nfile, bb.size, MPI_COMM_WORLD)) { fprintf(stderr, "failed to create temp: %s\n", big_file_get_error_message()); exit(1); } if(bbnew.size != bb.size) { abort(); } /* copy attrs */ size_t nattr; BigAttr * attrs = big_block_list_attrs(&bb, &nattr); int i; for(i = 0; i < nattr; i ++) { BigAttr * attr = &attrs[i]; big_block_set_attr(&bbnew, attr->name, attr->data, attr->dtype, attr->nmemb); } if(bb.nmemb > 0 && bb.size > 0) { /* copy data */ if(ThisTask == 0) { server(); } else { slave(); } } if(0 != big_block_mpi_close(&bbnew, MPI_COMM_WORLD)) { fprintf(stderr, "failed to close new: %s\n", big_file_get_error_message()); exit(1); } big_block_mpi_close(&bb, MPI_COMM_WORLD); big_file_mpi_close(&bf, MPI_COMM_WORLD); big_file_mpi_close(&bfnew, MPI_COMM_WORLD); return 0; }