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; }
/** Get the specified frame from amber netcdf file * Coords are a 1 dimensional array of format X1,Y1,Z1,X2,Y2,Z2,... */ int Traj_AmberNetcdf::readFrame(int set,double *X, double *V,double *box, double *T) { // Get temperature if (TempVID_!=-1) { start_[0] = set; count_[0] = 1; if ( checkNCerr(nc_get_vara_double(ncid_, TempVID_, start_, count_, T)) ) { mprinterr("Error: Getting replica temperature.\n"); return 1; } //fprintf(stderr,"DEBUG: Replica Temperature %lf\n",F->T); } // Read Coords start_[0] = set; start_[1] = 0; start_[2] = 0; count_[0] = 1; count_[1] = Ncatom(); count_[2] = 3; if ( checkNCerr(nc_get_vara_float(ncid_, coordVID_, start_, count_, Coord_)) ) { mprinterr("Error: Getting frame %i\n", set); return 1; } FloatToDouble(X, Coord_); // Read Velocities if (velocityVID_ != -1) { if ( checkNCerr(nc_get_vara_float(ncid_, velocityVID_, start_, count_, Veloc_)) ) { mprinterr("Error: Getting velocities for frame %i\n", set); return 1; } FloatToDouble(V, Veloc_); } // Read box info if (cellLengthVID_ != -1) { count_[1] = 3; count_[2] = 0; if ( checkNCerr(nc_get_vara_double(ncid_, cellLengthVID_, start_, count_, box)) ) { mprinterr("Getting cell lengths.\n"); return 1; } if ( checkNCerr(nc_get_vara_double(ncid_, cellAngleVID_, start_, count_, box+3)) ) { mprinterr("Getting cell angles.\n"); return 1; } } return 0; }
JNIEXPORT jint JNICALL Java_edu_berkeley_bid_CUMATD_FloatToDouble (JNIEnv *env, jobject obj, jobject jA, jobject jB, jint N) { float *A = (float*)getPointer(env, jA); double *B = (double*)getPointer(env, jB); return FloatToDouble(A, B, N); }
// As DeSerialize, but reads an old (float) format WeightMatrix for // backward compatibility. bool WeightMatrix::DeSerializeOld(bool training, bool swap, TFile* fp) { GENERIC_2D_ARRAY<float> float_array; if (int_mode_) { if (!wi_.DeSerialize(swap, fp)) return false; GenericVector<float> old_scales; if (!old_scales.DeSerialize(swap, fp)) return false; scales_.init_to_size(old_scales.size(), 0.0); for (int i = 0; i < old_scales.size(); ++i) scales_[i] = old_scales[i]; } else { if (!float_array.DeSerialize(swap, fp)) return false; FloatToDouble(float_array, &wf_); } if (training) { InitBackward(use_ada_grad_); if (!float_array.DeSerialize(swap, fp)) return false; FloatToDouble(float_array, &updates_); // Errs was only used in int training, which is now dead. if (!float_array.DeSerialize(swap, fp)) return false; } return true; }
// Traj_AmberNetcdf::readVelocity() int Traj_AmberNetcdf::readVelocity(int set, Frame& frameIn) { start_[0] = set; start_[1] = 0; start_[2] = 0; count_[0] = 1; count_[1] = Ncatom(); count_[2] = 3; // Read Velocities if (velocityVID_ != -1) { if ( checkNCerr(nc_get_vara_float(ncid_, velocityVID_, start_, count_, Coord_)) ) { mprinterr("Error: Getting velocities for frame %i\n", set+1); return 1; } FloatToDouble(frameIn.vAddress(), Coord_); } return 0; }
// Traj_AmberNetcdf::readForce() int Traj_AmberNetcdf::readForce(int set, Frame& frameIn) { start_[0] = set; start_[1] = 0; start_[2] = 0; count_[0] = 1; count_[1] = Ncatom(); count_[2] = 3; // Read forces if (frcVID_ != -1) { if ( NC::CheckErr(nc_get_vara_float(ncid_, frcVID_, start_, count_, Coord_)) ) { mprinterr("Error: Getting forces for frame %i\n", set+1); return 1; } FloatToDouble(frameIn.fAddress(), Coord_); } return 0; }
TEST(DSP, FloatDoubleConversion) { float in[10] = {1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0}; double out[10]; float fout[10]; FloatToDouble(out, in, 10); for (unsigned i = 0; i < 10; ++i) { ASSERT_DOUBLE_EQ((double)in[i], out[i]); } DoubleToFloat(fout, out, 10); for (unsigned i = 0; i < 10; ++i) { ASSERT_FLOAT_EQ(in[i], fout[i]); } }
// 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; }
/** Get the specified frame from amber netcdf file * Coords are a 1 dimensional array of format X1,Y1,Z1,X2,Y2,Z2,... */ int Traj_AmberNetcdf::readFrame(int set, Frame& frameIn) { start_[0] = set; start_[1] = 0; start_[2] = 0; count_[0] = 1; count_[1] = Ncatom(); count_[2] = 3; // Get temperature if (TempVID_!=-1) { if ( checkNCerr(nc_get_vara_double(ncid_, TempVID_, start_, count_, frameIn.tAddress())) ) { mprinterr("Error: Getting replica temperature for frame %i.\n", set+1); return 1; } //fprintf(stderr,"DEBUG: Replica Temperature %lf\n",F->T); } // Get time if (timeVID_!=-1) { float time; if (checkNCerr(nc_get_vara_float(ncid_, timeVID_, start_, count_, &time))) { mprinterr("Error: Getting time for frame %i.\n", set + 1); return 1; } frameIn.SetTime( (double)time ); } // Read Coords if ( checkNCerr(nc_get_vara_float(ncid_, coordVID_, start_, count_, Coord_)) ) { mprinterr("Error: Getting coordinates for frame %i\n", set+1); return 1; } FloatToDouble(frameIn.xAddress(), Coord_); // Read Velocities if (velocityVID_ != -1) { if ( checkNCerr(nc_get_vara_float(ncid_, velocityVID_, start_, count_, Coord_)) ) { mprinterr("Error: Getting velocities for frame %i\n", set+1); return 1; } FloatToDouble(frameIn.vAddress(), Coord_); } // Read indices. Input array must be allocated to be size remd_dimension. if (indicesVID_!=-1) { count_[1] = remd_dimension_; if ( checkNCerr(nc_get_vara_int(ncid_, indicesVID_, start_, count_, frameIn.iAddress())) ) { mprinterr("Error: Getting replica indices for frame %i.\n", set+1); return 1; } //mprintf("DEBUG:\tReplica indices:"); //for (int dim=0; dim < remd_dimension_; dim++) mprintf(" %i",remd_indices[dim]); //mprintf("\n"); } // Read box info if (cellLengthVID_ != -1) { count_[1] = 3; count_[2] = 0; if (checkNCerr(nc_get_vara_double(ncid_, cellLengthVID_, start_, count_, frameIn.bAddress()))) { mprinterr("Error: Getting cell lengths for frame %i.\n", set+1); return 1; } if (checkNCerr(nc_get_vara_double(ncid_, cellAngleVID_, start_, count_, frameIn.bAddress()+3))) { mprinterr("Error: Getting cell angles for frame %i.\n", set+1); return 1; } } return 0; }