//#include "genFuncs.hpp" #include #include #include #include #include #include #include #include #include #include using namespace std; PetscErrorCode loadValueFromCheckpoint(const string outputDir, const string filename, PetscScalar &value) { PetscErrorCode ierr = 0; #if VERBOSE > 1 ierr = PetscPrinf(PETSC_COMM_WORLD, "Starting loadValueFromCheckpoint in genFuncs.cpp.\n"); CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD, "Attempting to load %s%s\n", outputDir.c_str(), filename.c_str()); CHKERRQ(ierr); #endif string checkpointFile = outputDir + filename; bool fileExists = doesFileExist(checkpointFile); if (fileExists) { PetscPrintf(PETSC_COMM_WORLD, "Loading %s\n", filename.c_str()); PetscViewer viewer; int fd; PetscViewerBinaryOpen(PETSC_COMM_WORLD, checkpointFile.c_str(), FILE_MODE_READ, &viewer); PetscViewerBinaryGetDescriptor(viewer, &fd); PetscBinaryRead(fd, &value, 1, PETSC_SCALAR); PetscViewerDestroy(&viewer); } else { PetscPrintf(PETSC_COMM_WORLD, "Warning: %s not found.\n", checkpointFile.c_str()); } #if VERBOSE > 1 ierr = PetscPrintf(PETSC_COMM_WORLD, "Ending loadValueFromCheckpoint in %s.\n", filename.c_str()); CHKERRQ(ierr); #endif return ierr; } int main(int argc, char **args) { PetscErrorCode ierr = 0; ierr = PetscInitialize(&argc, &args, NULL, NULL); CHKERRQ(ierr); // directory and filename const string outputDir = "/home/yyy910805/"; const string filename = "_test"; PetscScalar value = 0; loadValueFromCheckpoint(outputDir, filename, value); ierr = PetscPrintf(PETSC_COMM_WORLD, " %f\n", value); CHKERRQ(ierr); ierr = PetscFinalize(); CHKERRQ(ierr); return 0; }