Esempio n. 1
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;
}
Esempio n. 2
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;
}