示例#1
0
int main(int argc, char * argv[]) {
    int opt;
    while(-1 != (opt = getopt(argc, argv, "t:n:N:"))) {
        switch(opt){
            case 'N':
                Nfile = atoi(optarg);
                break;
            case 't':
                dtype = optarg;
                break;
            case 'n':
                nmemb = atoi(optarg);
                break;
            default:
                usage();
        }
    }
    if(argc - optind < 3) {
        usage();
    }
    argv += optind - 1;
    BigFile bf = {0};
    BigBlock bb = {0};
    if(0 != big_file_create(&bf, argv[1])) {
        fprintf(stderr, "failed to create file : %s\n", big_file_get_error_message());
        return -1;
    }
    int Nfile;
    int Ninput = argc - optind - 2;
    size_t size[Nfile];
    size_t total = 0;
    int i;
    for(i = 0; i < Ninput; i ++) {
        struct stat st;
        stat(argv[i + 3], &st);
        total += st.st_size / dtype_itemsize(dtype) / nmemb;
    }
    for(i = 0; i < Nfile; i ++) {

    }
    
    if(0 != big_file_create_block(&bf, &bb, argv[2], dtype, nmemb, Nfile, fsize)) {
        fprintf(stderr, "failed to create block: %s\n", big_file_get_error_message());
        return -1;
    }
    for(i = 0; i < Nfile; i ++) {
        FILE * fp = fopen
    }
    big_file_close(&bf);
    return 0;
}
示例#2
0
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;
}
示例#3
0
void slave() {
    int result = 0;
    MPI_Send(&result, 1, MPI_INT, 0, DONE_TAG, MPI_COMM_WORLD);
    while(1) {
        int64_t work[2];
        MPI_Status status;
        MPI_Recv(work, 1, MPI_TYPE_WORK, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

        if(status.MPI_TAG == DIE_TAG) {
            break;
        }
        int64_t offset = work[0];
        int64_t chunksize = work[1];
        BigArray array;
        BigBlockPtr ptrnew;

        if(0 != big_block_read_simple(&bb, offset, chunksize, &array, NULL)) {
            fprintf(stderr, "failed to read original: %s\n", big_file_get_error_message());
            result = -1;
            goto bad;
        }
        if(0 != big_block_seek(&bbnew, &ptrnew, offset)) {
            fprintf(stderr, "failed to seek new: %s\n", big_file_get_error_message());
            result = -1;
            free(array.data);
            goto bad;
        }

        if(0 != big_block_write(&bbnew, &ptrnew, &array)) {
            fprintf(stderr, "failed to write new: %s\n", big_file_get_error_message());
            result = -1;
            free(array.data);
            goto bad;
        }

        free(array.data);
        MPI_Send(&result, 1, MPI_INT, 0, DONE_TAG, MPI_COMM_WORLD);
        continue;
    bad:
        MPI_Send(&result, 1, MPI_INT, 0, ERROR_TAG, MPI_COMM_WORLD);
        continue;
    }
    return;
}
示例#4
0
/* this routine loads header data from the first file of an HDF5 snapshot.*/
int load_bigfile_header(const char *fname, double  *atime, double *redshift, double *box100, double *h100, int64_t *npart_all, double * mass, double *Omega0)
{
  BigFile bf = {0};
  if(0 != big_file_open(&bf, fname)) {
      fprintf(stderr,"Failed to open snapshot at %s:%s\n", fname,
                  big_file_get_error_message());
      return 1;
  }
  BigBlock bh = {0};
  if(0 != big_file_open_block(&bf, &bh, "Header")) {
      fprintf(stderr,"Failed to create block at %s:%s\n", "Header",
                  big_file_get_error_message());
      return 1;
  }
  if(
  (0 != big_block_get_attr(&bh, "TotNumPart", npart_all, "u8", N_TYPE)) ||
  (0 != big_block_get_attr(&bh, "MassTable", mass, "f8", N_TYPE)) ||
  (0 != big_block_get_attr(&bh, "Time", atime, "f8", 1)) ||
  (0 != big_block_get_attr(&bh, "HubbleParam", h100, "f8", 1)) ||
  (0 != big_block_get_attr(&bh, "Omega0", Omega0, "f8", 1)) ||
  (0 != big_block_get_attr(&bh, "BoxSize", box100, "f8", 1))) {
      fprintf(stderr,"Failed to read attr: %s\n",
                  big_file_get_error_message());
      return 1;
  }
  *redshift = 1/(*atime) - 1;
  if(big_block_close(&bh) ||
        big_file_close(&bf)) {
      fprintf(stderr,"Failed to close block or file: %s\n",
                  big_file_get_error_message());
      return 1;
  }
  printf("NumPart=[%ld,%ld,%ld,%ld,%ld,%ld], ",npart_all[0],npart_all[1],npart_all[2],npart_all[3],npart_all[4],npart_all[5]);
  printf("Masses=[%g %g %g %g %g %g], ",mass[0],mass[1],mass[2],mass[3],mass[4],mass[5]);
  printf("Redshift=%g, Ω_M=%g\n",(*redshift),*Omega0);
  printf("Expansion factor = %f\n",(*atime));
  printf("Hubble = %g Box=%g \n",(*h100),(*box100));
  return 0;
}
示例#5
0
/* This routine loads particle data from a bigfile snapshot set. */
int read_fieldize_bigfile(GENFLOAT * field, const char *fname, int type, double box, int field_dims, double *total_mass, int64_t* npart_all, double * mass, double Omega0)
{
  char name[32];
  BigFile bf = {0};
  if(0 != big_file_open(&bf, fname)) {
      fprintf(stderr,"Failed to open snapshot at %s:%s\n", fname,
                  big_file_get_error_message());
      return 1;
  }
  BigBlock bb = {0};
  snprintf(name,32,"%d/Position",type);
  if(0 != big_file_open_block(&bf, &bb, name)) {
      fprintf(stderr,"Failed to open block at %s:%s\n", name,
                  big_file_get_error_message());
      return 1;
  }
  BigArray pos = {0};
  /*Open particle data*/
  if(0 != big_block_read_simple(&bb, 0, npart_all[type], &pos,"f8")) {
      fprintf(stderr,"Failed to read from block: %s\n", big_file_get_error_message());
      return 1;
  }
  big_block_close(&bb);

  float * positions = (float *) malloc(3*npart_all[type]*sizeof(float));
  for(int i=0; i<3*npart_all[type]; i++)
      positions[i] = ((double *)pos.data)[i];
  free(pos.data);
  BigArray massarray = {0};
  /* Load particle masses, if present  */
   if(mass[type] == 0){
        double total_mass_this_file=0;
        snprintf(name,32,"%d/Mass",type);
        if(0 != big_file_open_block(&bf, &bb, name)) {
            fprintf(stderr,"Failed to open block at %s:%s\n", name,
                  big_file_get_error_message());
            return 1;
        }
        if(0 != big_block_read_simple(&bb, 0, npart_all[type], &massarray,"f4")) {
            fprintf(stderr,"Failed to read from block: %s\n", big_file_get_error_message());
            return 1;
        }
        for(int i = 0; i<npart_all[type]; i++)
            total_mass_this_file += ((float *)massarray.data)[i];
        *total_mass += total_mass_this_file;
        if(big_block_close(&bb) ||
              big_file_close(&bf)) {
            fprintf(stderr,"Failed to close block or file: %s\n",
                        big_file_get_error_message());
        }
  }
  //Do the final summation here to avoid fp roundoff
  *total_mass += mass[type]*npart_all[type];
  fieldize(box,field_dims,field,npart_all[type],positions, (float *)massarray.data, mass[type], 1);
  free(positions);
  free(massarray.data);
  return 0;
}
static void big_file_mpi_broadcast_error(int root, MPI_Comm comm) {
    int rank;
    MPI_Comm_rank(comm, &rank);
    char * error = big_file_get_error_message();
    int errorlen;
    if(rank == root) {
        errorlen = strlen(error);
    }
    MPI_Bcast(&errorlen, 1, MPI_INT, root, comm);
    if(rank != root) {
        error = alloca(errorlen + 1);
    }
    MPI_Bcast(error, errorlen + 1, MPI_BYTE, root, comm);
    if(rank != root) {
        big_file_set_error_message(error);
    }
}
示例#7
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;
}