int Traj_AmberNetcdf::parallelOpenTrajout(Parallel::Comm const& commIn) { if (Ncid() != -1) return 0; int err = ncmpi_open(commIn.MPIcomm(), filename_.full(), NC_WRITE, MPI_INFO_NULL, &ncid_); if (checkPNCerr(err)) { mprinterr("Error: Opening NetCDF file '%s' for writing in parallel.\n", filename_.full()); return 1; } err = ncmpi_begin_indep_data( ncid_ ); // Independent data mode return 0; }
int Traj_AmberNetcdf::parallelReadFrame(int set, Frame& frameIn) { MPI_Offset pstart_[3]; MPI_Offset pcount_[3]; pstart_[0] = set; pstart_[1] = 0; pstart_[2] = 0; pcount_[0] = 1; pcount_[1] = Ncatom(); pcount_[2] = 3; //int err = ncmpi_get_vara_float_all(ncid_, coordVID_, pstart_, pcount_, Coord_); int err = ncmpi_get_vara_float(ncid_, coordVID_, pstart_, pcount_, Coord_); if (checkPNCerr(err)) return Parallel::Abort(err); FloatToDouble(frameIn.xAddress(), Coord_); if (velocityVID_ != -1) { //err = ncmpi_get_vara_float_all(ncid_, velocityVID_, pstart_, pcount_, Coord_); err = ncmpi_get_vara_float(ncid_, velocityVID_, pstart_, pcount_, Coord_); if (checkPNCerr(err)) return Parallel::Abort(err); FloatToDouble(frameIn.vAddress(), Coord_); } if (frcVID_ != -1) { err = ncmpi_get_vara_float(ncid_, frcVID_, pstart_, pcount_, Coord_); if (checkPNCerr(err)) return Parallel::Abort(err); FloatToDouble(frameIn.fAddress(), Coord_); } pcount_[2] = 0; if (cellLengthVID_ != -1) { pcount_[1] = 3; //err = ncmpi_get_vara_double_all(ncid_, cellLengthVID_, pstart_, pcount_, frameIn.bAddress()); err = ncmpi_get_vara_double(ncid_, cellLengthVID_, pstart_, pcount_, frameIn.bAddress()); if (checkPNCerr(err)) return Parallel::Abort(err); //err = ncmpi_get_vara_double_all(ncid_, cellAngleVID_, pstart_, pcount_, frameIn.bAddress()+3); err = ncmpi_get_vara_double(ncid_, cellAngleVID_, pstart_, pcount_, frameIn.bAddress()+3); } if (TempVID_ != -1) { //err = ncmpi_get_vara_double_all(ncid_, TempVID_, pstart_, pcount_, frameIn.tAddress()); err = ncmpi_get_vara_double(ncid_, TempVID_, pstart_, pcount_, frameIn.tAddress()); if (checkPNCerr(err)) return Parallel::Abort(err); } if (timeVID_ != -1) { float time; err = ncmpi_get_vara_float(ncid_, timeVID_, pstart_, pcount_, &time); if (checkPNCerr(err)) return Parallel::Abort(err); frameIn.SetTime( (double)time ); } if (indicesVID_ != -1) { pcount_[1] = remd_dimension_; //err = ncmpi_get_vara_int_all(ncid_, indicesVID_, pstart_, pcount_, frameIn.iAddress()); err = ncmpi_get_vara_int(ncid_, indicesVID_, pstart_, pcount_, frameIn.iAddress()); if (checkPNCerr(err)) return Parallel::Abort(err); } return 0; }
int Traj_AmberNetcdf::parallelWriteFrame(int set, Frame const& frameOut) { MPI_Offset pstart_[3]; MPI_Offset pcount_[3]; pstart_[0] = set; pstart_[1] = 0; pstart_[2] = 0; pcount_[0] = 1; pcount_[1] = Ncatom(); pcount_[2] = 3; // TODO check error better DoubleToFloat(Coord_, frameOut.xAddress()); //int err = ncmpi_put_vara_float_all(ncid_, coordVID_, pstart_, pcount_, Coord_); int err = ncmpi_put_vara_float(ncid_, coordVID_, pstart_, pcount_, Coord_); if (checkPNCerr(err)) return Parallel::Abort(err); if (velocityVID_ != -1) { DoubleToFloat(Coord_, frameOut.vAddress()); //err = ncmpi_put_vara_float_all(ncid_, velocityVID_, pstart_, pcount_, Coord_); err = ncmpi_put_vara_float(ncid_, velocityVID_, pstart_, pcount_, Coord_); if (checkPNCerr(err)) return Parallel::Abort(err); } if (frcVID_ != -1) { DoubleToFloat(Coord_, frameOut.fAddress()); err = ncmpi_put_vara_float(ncid_, frcVID_, pstart_, pcount_, Coord_); if (checkPNCerr(err)) return Parallel::Abort(err); } pcount_[2] = 0; if (cellLengthVID_ != -1) { pcount_[1] = 3; //err = ncmpi_put_vara_double_all(ncid_, cellLengthVID_, pstart_, pcount_, frameOut.bAddress()); err = ncmpi_put_vara_double(ncid_, cellLengthVID_, pstart_, pcount_, frameOut.bAddress()); if (checkPNCerr(err)) return Parallel::Abort(err); //err = ncmpi_put_vara_double_all(ncid_, cellAngleVID_, pstart_, pcount_, frameOut.bAddress()+3); err = ncmpi_put_vara_double(ncid_, cellAngleVID_, pstart_, pcount_, frameOut.bAddress()+3); } if (TempVID_ != -1) { //err = ncmpi_put_vara_double_all(ncid_, TempVID_, pstart_, pcount_, frameOut.tAddress()); err = ncmpi_put_vara_double(ncid_, TempVID_, pstart_, pcount_, frameOut.tAddress()); if (checkPNCerr(err)) return Parallel::Abort(err); } if (timeVID_ != -1) { float tVal = (float)frameOut.Time(); err = ncmpi_put_vara_float(ncid_, timeVID_, pstart_, pcount_, &tVal); if (checkPNCerr(err)) return Parallel::Abort(err); } if (indicesVID_ != -1) { pcount_[1] = remd_dimension_; //err = ncmpi_put_vara_int_all(ncid_, indicesVID_, pstart_, pcount_, frameOut.iAddress()); err = ncmpi_put_vara_int(ncid_, indicesVID_, pstart_, pcount_, frameOut.iAddress()); if (checkPNCerr(err)) return Parallel::Abort(err); } return 0; }
// Traj_NcEnsemble::readArray() //TODO RemdValues int Traj_NcEnsemble::readArray(int set, FrameArray& f_ensemble) { # ifdef HAS_PNETCDF MPI_Offset pstart_[4]; MPI_Offset pcount_[4]; # define start_ pstart_ # define count_ pcount_ # endif start_[0] = set; // Frame start_[2] = 0; // Atoms start_[3] = 0; // XYZ count_[0] = 1; // Frame count_[1] = 1; // Ensemble count_[3] = 3; // XYZ //rprintf("DEBUG: Reading frame %i\n", set+1); for (int member = ensembleStart_; member != ensembleEnd_; member++) { # ifdef MPI Frame& frm = f_ensemble[0]; # else Frame& frm = f_ensemble[member]; # endif start_[1] = member; // Ensemble count_[2] = Ncatom(); // Atoms // Read Coords # ifdef HAS_PNETCDF if (checkPNCerr(ncmpi_get_vara_float_all(ncid_, coordVID_, start_, count_, Coord_))) # else if (NC::CheckErr(nc_get_vara_float(ncid_, coordVID_, start_, count_, Coord_))) # endif { rprinterr("Error: Getting coordinates for frame %i\n", set+1); return 1; } FloatToDouble(frm.xAddress(), Coord_); //mprintf("Frm=%8i Rep=%8i ", set+1, member+1); // DEBUG //frm.printAtomCoord(0); // DEBUG // Read Velocities if (velocityVID_ != -1) { # ifdef HAS_PNETCDF if (checkPNCerr(ncmpi_get_vara_float_all(ncid_, velocityVID_, start_, count_, Coord_))) # else if (NC::CheckErr(nc_get_vara_float(ncid_, velocityVID_, start_, count_, Coord_))) # endif { rprinterr("Error: Getting velocities for frame %i\n", set+1); return 1; } FloatToDouble(frm.vAddress(), Coord_); } // Read Box if (cellLengthVID_ != -1) { count_[2] = 3; # ifdef HAS_PNETCDF if (checkPNCerr(ncmpi_get_vara_double_all(ncid_, cellLengthVID_, start_, count_, frm.bAddress()))) # else if (NC::CheckErr(nc_get_vara_double(ncid_, cellLengthVID_, start_, count_, frm.bAddress()))) # endif { rprinterr("Error: Getting cell lengths for frame %i.\n", set+1); return 1; } # ifdef HAS_PNETCDF if (checkPNCerr(ncmpi_get_vara_double_all(ncid_, cellAngleVID_, start_, count_, frm.bAddress()+3))) # else if (NC::CheckErr(nc_get_vara_double(ncid_, cellAngleVID_, start_, count_, frm.bAddress()+3))) # endif { rprinterr("Error: Getting cell angles for frame %i.\n", set+1); return 1; } } // Read Temperature if (TempVID_!=-1) { # ifdef HAS_PNETCDF if (checkPNCerr(ncmpi_get_vara_double_all(ncid_, TempVID_, start_, count_, frm.tAddress()))) # else if (NC::CheckErr(nc_get_vara_double(ncid_, TempVID_, start_, count_, frm.tAddress()))) # endif { rprinterr("Error: Getting replica temperature for frame %i.\n", set+1); return 1; } //fprintf(stderr,"DEBUG: Replica Temperature %lf\n",F->T); } // Read indices if (indicesVID_!=-1) { count_[2] = remd_dimension_; # ifdef HAS_PNETCDF if (checkPNCerr(ncmpi_get_vara_int_all(ncid_, indicesVID_, start_, count_, frm.iAddress()))) # else if (NC::CheckErr(nc_get_vara_int(ncid_, indicesVID_, start_, count_, frm.iAddress()))) # endif { rprinterr("Error: Getting replica indices for frame %i.\n", set+1); return 1; } // DEBUG //char buffer[128]; //char* ptr = buffer; //ptr += sprintf(buffer,"DEBUG:\tReplica indices:"); //for (int dim=0; dim < remd_dimension_; dim++) ptr += sprintf(ptr, " %i", frm.RemdIndices()[dim]); //sprintf(ptr,"\n"); //rprintf("%s", buffer); } } # ifdef HAS_PNETCDF // DEBUG # undef start_ # undef count_ # endif return 0; }