PyObject * pyCitcom_ic_readCheckpoint(PyObject *self, PyObject *args) { PyObject *obj; struct All_variables* E; if (!PyArg_ParseTuple(args, "O:readCheckpoint", &obj)) return NULL; E = (struct All_variables*)(PyCObject_AsVoidPtr(obj)); read_checkpoint(E); Py_INCREF(Py_None); return Py_None; }
void MaxPosterior::initiate(IM im, popTree* poptree, Chain coldCh, unsigned int nProcs, unsigned int crr_procID) { //-- Settings for differential evoltuion --// nParaVectors = 30; nIters = 1000; F = 0.8; CR = 0.9; nParaVectors = im.get_nParaVectors(); // std::chrono::microseconds initial(0); // totalComputingTime_eigen = initial; // totalComputingTime_eigen_subMatOfEigenVectors= initial; // totalComputingTime_condiProb = initial; checkpoint = im.get_checkpoint(); if(checkpoint ==1|| checkpoint==3) { howOften_checkpoint = im.get_howOften_checkpoint(); } unsigned int ancPop = im.get_ancPop(); unsigned int samePopulationSizes = im.get_samePopulationSizes(); unsigned int sameMigrationRates = im.get_sameMigrationRates(); double migRateMax = im.get_migRateMax(); unsigned int nPara_popSizes; if(poptree->get_age()==0) // single population { nPara =1; nPara_popSizes =1; } else // more than or equal to 2 populations { if(ancPop == 0) // island model (no ancestral populations) { if(samePopulationSizes == 1) { nPara = 1; nPara_popSizes = 1; } else { nPara = 2; nPara_popSizes = 2; } } else if(ancPop == 1) { if(samePopulationSizes == 1) { nPara = 2; // population size and splitting time nPara_popSizes = 1; } else { nPara = 4; // three population sizes and a splitting time nPara_popSizes = 3; } } if(migRateMax !=0) { if(sameMigrationRates ==1) nPara += 1; else nPara += 2; } } para_atCrr.resize(nParaVectors,nPara); para_atPrev.resize(nParaVectors,nPara); posterior_atCrr.resize(nParaVectors); posterior_atPrev.resize(nParaVectors); for(unsigned int i=0; i<nPara; i++) { if(poptree->get_age() ==0) { priorsMax.push_back(im.get_popSizeMax()); } else{ if(i < nPara_popSizes) priorsMax.push_back(im.get_popSizeMax()); else if(i==nPara-1 && ancPop ==1) priorsMax.push_back(im.get_splittingTimeMax()); else priorsMax.push_back(im.get_migRateMax()); } } // Initialize "para_atPrev" for(unsigned int i=0; i<nParaVectors; i++) { if(checkpoint ==2|| checkpoint ==3) { // read the checkpoint and save them to "para_atPrev" read_checkpoint(); } else if(checkpoint <= 1) { // initialize "para_atPrev" (individuals in DE) for(unsigned int j=0; j<nPara; j++) { double para_temp = 0.0; if(crr_procID == 0) para_temp = priorsMax.at(j)*runiform(); MPI::COMM_WORLD.Barrier(); MPI::COMM_WORLD.Bcast(¶_temp, 1, MPI_DOUBLE, 0); MPI::COMM_WORLD.Barrier(); para_atPrev(i,j)=para_temp; } } else { std::cout << "\n*** Error in void MaxPosterior::initiate() ***\n" << "checkpoint should take a value of 0, 1, 2 or 3, but checkpoint = " << checkpoint <<".\n\n"; } } // Computing the posterior of para_atPrev for(unsigned int i=0; i<nParaVectors; i++) { Eigen::MatrixXd paraVector(1,6); if(poptree->get_age()==0) { for(unsigned int j=0; j<6; j++) { if(j==2) // ancestral population paraVector(0,j) = para_atPrev(i,0); else paraVector(0,j) = 0; } } else { // sampling populations paraVector(0,0) = para_atPrev(i,0); if(samePopulationSizes == 1) paraVector(0,1) = para_atPrev(i,0); else paraVector(0,1) = para_atPrev(i,1); // ancestral population if(ancPop == 1) { if(samePopulationSizes == 1) paraVector(0,2) = para_atPrev(i,0); else paraVector(0,2) = para_atPrev(i,2); } // migration rates if(migRateMax !=0) { paraVector(0,3) = para_atPrev(i,nPara_popSizes); if(sameMigrationRates == 1) paraVector(0,4) = para_atPrev(i,nPara_popSizes); else paraVector(0,4) = para_atPrev(i,nPara_popSizes+1); } else { paraVector(0,4) = 0; paraVector(0,5) =0; } //-- splitting time --// if(ancPop == 1) paraVector(0,5) = para_atPrev(i,nPara-1); else // no ancestral population paraVector(0,5) =im.get_splittingTimeMax(); } unsigned int lociInParallel = im.get_lociInParallel(); if(lociInParallel ==1) { if(coldCh.get_multiLocusSpecific_mutationRate() ==1) // variable mutation rate scalars { posterior_atPrev.at(i) = computeLogJointDensity_mutationScalars_MPI_overSubLoci(paraVector, im, poptree, coldCh, nProcs, crr_procID); } else // constant mutation rate scalars { posterior_atPrev.at(i) = computeLogJointDensity_MPI_overSubLoci(paraVector, im, poptree, coldCh, nProcs, crr_procID); } } else if(lociInParallel ==0) { posterior_atPrev.at(i) = log(computeJointDensity_MPI_overSubSample(paraVector,im, poptree,coldCh, nProcs, crr_procID)); } else { std::cout << "lociInParallel should be 1 or 0, but lociInParallel = " << lociInParallel <<"\n"; } } return; }
void checkdata(char* file, size_t size, int times) { char* buf = malloc(size); MPI_Barrier(MPI_COMM_WORLD); if (times > 0) { /* write the checkpoint file */ int i, j; for(i=0; i < times; i++) { int rc; int valid = 0; rc = init_buffer(buf, size, rank, i); if (rank == 0) { printf("Writing checkpoint %d.\n", i); fflush(stdout); } /* open the file and write the checkpoint */ int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd_me > 0) { valid = 1; /* write the checkpoint data */ rc = write_checkpoint(fd_me, rank, i, buf, size); if (rc < 0) { valid = 0; } /* force the data to storage */ rc = fsync(fd_me); if (rc < 0) { valid = 0; } /* make sure the close is without error */ rc = close(fd_me); if (rc < 0) { valid = 0; } } if (rank == 0) { printf("Completed checkpoint %d.\n", i); fflush(stdout); } if (rank == 0) { printf("Reading checkpoint %d.\n", i); fflush(stdout); } memset(buf, 0, size); /* open the file and write the checkpoint */ int read_rank, read_timestep; fd_me = open(file, O_RDONLY); if (fd_me > 0) { valid = 1; /* write the checkpoint data */ rc = read_checkpoint(fd_me, &read_rank, &read_timestep, buf, size); if (rc < 0) { valid = 0; } /* make sure the close is without error */ rc = close(fd_me); if (rc < 0) { valid = 0; } } if (read_rank != rank || read_timestep != i) { printf("INVALID HEADER on rank %d in step %d\n", rank, i); fflush(stdout); MPI_Abort(MPI_COMM_WORLD, 0); } rc = check_buffer(buf, size, rank, i); if (! rc) { printf("INVALID DATA on rank %d in step %d\n", rank, i); fflush(stdout); MPI_Abort(MPI_COMM_WORLD, 0); } if (rank == 0) { printf("Verified checkpoint %d.\n", read_timestep); fflush(stdout); } /* optionally sleep for some time */ if (seconds > 0) { if (rank == 0) { printf("Sleeping for %d seconds... \n", seconds); fflush(stdout); } sleep(seconds); } unlink(file); } } MPI_Barrier(MPI_COMM_WORLD); if (buf != NULL) { free(buf); buf = NULL; } return; }
void process_commandline ( int argc, char **argv ) { extern FILE *sys_file; int i,params; int errorflag = 0; /* if there are no arguments, print out a brief statement of usage and exit. */ if ( argc < 2 ) { fprintf( stderr ,"usage: %s options\nValid options are:\n", argv[0] ); fprintf( stderr , " ant -f parameterfile : read named parameter file\n" ); fprintf( stderr , " ant -c checkpointfile : read named checkpoint file\n" ); fprintf( stderr , " ant -d : read default parameters\n" ); exit(1); } for ( i = 1; i < argc; ++i ) { /* all options begin with '-' and have two characters */ if ( argv[i][0] != '-' ) { fprintf( stderr , "\nunrecognized command line option: \"%s\".", argv[i] ); errorflag = 1; continue; } switch ( argv[i][1] ) { case 'f': /* load a parameter file, named in the next argument. */ oprintf( 1,sys_file," Read parameters from input file \"%s\"\n",argv[++i]); delay(1000); startfromcheckpoint = 0; read_parameter_file ( argv[2] ); break; case 'c': /* load a checkpoint file, named in the next argument. */ oprintf( 1,sys_file,"Read parameters from checkpoint file \"%s\"\n",argv[++i]); read_checkpoint ( argv[2] , gene_track_array ); break; case 'd': /* load the default parameters. */ startfromcheckpoint = 0; oprintf(1,sys_file," Read all default parameters.\n"); delay(1000); return; break; default: fprintf( stderr , "\nunrecognized command line option: \"%s\".", argv[i] ); errorflag = 1; break; } } if ( errorflag ) { fprintf( stderr , "\ncommand line errors occurred. dying." ); exit(1); } /*// read_checkpoint ( "ant1.ckp",&gene_track_array); // read_parameter_file ( "input.ant");*/ return; }
int main (int argc, char* argv[]) { char *path_to_stdout = NULL; int scr_retval; /* check that we got an appropriate number of arguments */ if (argc == 2) { path_to_stdout = argv[1]; } else if(argc == 5){ filesize = (size_t) atol(argv[1]); times = atoi(argv[2]); seconds = atoi(argv[3]); path_to_stdout = argv[4]; } else{ printf("Usage: test_api_file [filesize times sleep_secs path_to_stdout]\n"); printf("OR: test_api_file [ path_to_stdout]\n"); exit(1); } MPI_Init(&argc, &argv); int rank = -1, size = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); /* open file for stdout */ printf("new stdout filename: \"%s\"\n", path_to_stdout); fflush(stdout); freopen(path_to_stdout, "a+", stdout); MPI_Barrier(MPI_COMM_WORLD); /* time how long it takes to get through init */ MPI_Barrier(MPI_COMM_WORLD); double init_start = MPI_Wtime(); if (SCR_Init() != SCR_SUCCESS){ printf("FAILED INITIALIZING SCR\n"); fclose(stdout); return -1; } double init_end = MPI_Wtime(); double secs = init_end - init_start; MPI_Barrier(MPI_COMM_WORLD); double secsmin, secsmax, secssum; MPI_Reduce(&secs, &secsmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&secs, &secsmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(&secs, &secssum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0) { printf("Init: Min %8.6f s\tMax %8.6f s\tAvg %8.6f s\n", secsmin, secsmax, secssum/size); } MPI_Barrier(MPI_COMM_WORLD); int num_files = rank % 4; char** files = NULL; char** bufs = NULL; size_t* filesizes = NULL; char* buf = NULL; if (num_files > 0) { files = (char**) malloc(num_files * sizeof(char*)); bufs = (char**) malloc(num_files * sizeof(char*)); filesizes = (size_t*) malloc(num_files * sizeof(size_t)); } int i; for (i=0; i < num_files; i++) { // route our checkpoint file char name[256]; sprintf(name, "rank_%d.%d.ckpt", rank, i); files[i] = strdup(name); filesizes[i] = filesize + rank + 2*i; bufs[i] = (char*) malloc(filesizes[i]); } if (num_files > 0) { buf = (char*) malloc(filesizes[num_files-1]); } // check each of our checkpoint files int found_checkpoint = 1; for (i=0; i < num_files; i++) { char file[2094]; scr_retval = SCR_Route_file(files[i], file); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Route_file(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } if (read_checkpoint(file, ×tep, buf, filesizes[i])) { // check that contents are good if (!check_buffer(buf, filesizes[i], rank + 2*i, timestep)) { printf("!!!!CORRUPTION!!!! Rank %d, File %s: Invalid value in buffer\n", rank, file); fflush(stdout); fclose(stdout); MPI_Abort(MPI_COMM_WORLD, 1); return 1; } } else { found_checkpoint = 0; } } // check that everyone found their checkpoint files ok int all_found_checkpoint = 0; MPI_Allreduce(&found_checkpoint, &all_found_checkpoint, 1, MPI_INT, MPI_LAND, MPI_COMM_WORLD); if (!all_found_checkpoint && rank == 0) { printf("At least one rank (perhaps all) did not find its checkpoint\n"); fflush(stdout); } // check that everyone is at the same timestep int timestep_and, timestep_or; int timestep_a, timestep_o; if (num_files > 0) { timestep_a = timestep; timestep_o = timestep; } else { timestep_a = 0xffffffff; timestep_o = 0x00000000; } MPI_Allreduce(×tep_a, ×tep_and, 1, MPI_INT, MPI_BAND, MPI_COMM_WORLD); MPI_Allreduce(×tep_o, ×tep_or, 1, MPI_INT, MPI_BOR, MPI_COMM_WORLD); if (timestep_and != timestep_or) { printf("%d: Timesteps don't agree: timestep %d\n", rank, timestep); fflush(stdout); fclose(stdout); return 1; } timestep = timestep_and; // make up some data for the next checkpoint for (i=0; i < num_files; i++) { init_buffer(bufs[i], filesizes[i], rank + 2*i, timestep); } timestep++; // prime system once before timing int t; for(t=0; t < 1; t++) { int rc; int all_valid = 1; scr_retval = SCR_Start_checkpoint(); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Start_checkpoint(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } for (i=0; i < num_files; i++) { int valid = 0; char file[2094]; scr_retval = SCR_Route_file(files[i], file); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_route_file(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd_me > 0) { valid = 1; // write the checkpoint rc = write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]); if (rc < 0) { valid = 0; } rc = fsync(fd_me); if (rc < 0) { valid = 0; } // make sure the close is without error rc = close(fd_me); if (rc < 0) { valid = 0; } } if (!valid) { all_valid = 0; } } scr_retval = SCR_Complete_checkpoint(all_valid); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Complete_checkpoint(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } if (rank == 0) { printf("Completed checkpoint %d.\n", timestep); fflush(stdout); } timestep++; } MPI_Barrier(MPI_COMM_WORLD); if (times > 0) { int count = 0; double time_start = MPI_Wtime(); for(t=0; t < times; t++) { int rc; int all_valid = 1; scr_retval = SCR_Start_checkpoint(); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Start_checkpoint(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } for (i=0; i < num_files; i++) { int valid = 0; char file[2094]; scr_retval = SCR_Route_file(files[i], file); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Route_file(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd_me > 0) { count++; valid = 1; // write the checkpoint rc = write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]); if (rc < 0) { valid = 0; } rc = fsync(fd_me); if (rc < 0) { valid = 0; } // make sure the close is without error rc = close(fd_me); if (rc < 0) { valid = 0; } } if (!valid) { all_valid = 0; } } scr_retval = SCR_Complete_checkpoint(all_valid); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Complete_checkpoint(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } if (rank == 0) { printf("Completed checkpoint %d.\n", timestep); fflush(stdout); } timestep++; if (seconds > 0) { if (rank == 0) { printf("Sleeping for %d seconds... \n", seconds); fflush(stdout); } sleep(seconds); } } double time_end = MPI_Wtime(); double bw = (filesize*count/(1024*1024)) / (time_end - time_start); MPI_Barrier(MPI_COMM_WORLD); double bwmin, bwmax, bwsum; MPI_Reduce(&bw, &bwmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&bw, &bwmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(&bw, &bwsum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0) { printf("FileIO: Min %7.2f MB/s\tMax %7.2f MB/s\tAvg %7.2f MB/s\n", bwmin, bwmax, bwsum/size); } } if (buf != NULL) { free(buf); buf = NULL; } for (i=0; i < num_files; i++) { if (bufs[i] != NULL) { free(bufs[i]); bufs[i] = NULL; } if (files[i] != NULL) { free(files[i]); files[i] = NULL; } } if (files != NULL) { free(files); files = NULL; } if (bufs != NULL) { free(bufs); bufs = NULL; } if (filesizes != NULL) { free(filesizes); filesizes = NULL; } scr_retval = SCR_Finalize(); if (scr_retval != SCR_SUCCESS) { printf("%d: failed calling SCR_Finalize(): %d: @%s:%d\n", rank, scr_retval, __FILE__, __LINE__ ); } MPI_Finalize(); fclose(stdout); return 0; }
int main (int argc, char* argv[]) { /* check that we got an appropriate number of arguments */ if (argc != 1 && argc != 4) { printf("Usage: test_correctness [filesize times sleep_secs]\n"); return 1; } /* read parameters from command line, if any */ if (argc > 1) { filesize = (size_t) atol(argv[1]); times = atoi(argv[2]); seconds = atoi(argv[3]); } MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &ranks); /* time how long it takes to get through init */ MPI_Barrier(MPI_COMM_WORLD); double init_start = MPI_Wtime(); SCR_Init(); double init_end = MPI_Wtime(); double secs = init_end - init_start; MPI_Barrier(MPI_COMM_WORLD); /* compute and print the init stats */ double secsmin, secsmax, secssum; MPI_Reduce(&secs, &secsmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&secs, &secsmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(&secs, &secssum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0) { printf("Init: Min %8.6f s\tMax %8.6f s\tAvg %8.6f s\n", secsmin, secsmax, secssum/ranks); } MPI_Barrier(MPI_COMM_WORLD); /* allocate space for the checkpoint data (make filesize a function of rank for some variation) */ filesize = filesize + rank; char* buf = (char*) malloc(filesize); /* get the name of our checkpoint file to open for read on restart */ char name[256]; char file[SCR_MAX_FILENAME]; sprintf(name, "rank_%d.ckpt", rank); int found_checkpoint = 0; if (SCR_Route_file(name, file) == SCR_SUCCESS) { if (read_checkpoint(file, ×tep, buf, filesize)) { /* read the file ok, now check that contents are good */ found_checkpoint = 1; //printf("%d: Successfully read checkpoint from %s\n", rank, file); if (!check_buffer(buf, filesize, rank, timestep)) { printf("%d: Invalid value in buffer\n", rank); MPI_Abort(MPI_COMM_WORLD, 1); return 1; } } else { printf("%d: Could not read checkpoint %d from %s\n", rank, timestep, file); } } else printf("%d: SCR_Route_file failed during restart attempt\n", rank); /* determine whether all tasks successfully read their checkpoint file */ int all_found_checkpoint = 0; MPI_Allreduce(&found_checkpoint, &all_found_checkpoint, 1, MPI_INT, MPI_LAND, MPI_COMM_WORLD); if (!all_found_checkpoint && rank == 0) { printf("At least one rank (perhaps all) did not find its checkpoint\n"); } /* check that everyone is at the same timestep */ int timestep_and, timestep_or; MPI_Allreduce(×tep, ×tep_and, 1, MPI_INT, MPI_BAND, MPI_COMM_WORLD); MPI_Allreduce(×tep, ×tep_or, 1, MPI_INT, MPI_BOR, MPI_COMM_WORLD); if (timestep_and != timestep_or) { printf("%d: Timesteps don't agree: timestep %d\n", rank, timestep); return 1; } /* make up some data for the next checkpoint */ init_buffer(buf, filesize, rank, timestep); timestep++; /* prime system once before timing */ getbw(name, buf, filesize, 1); /* now compute the bandwidth and print stats */ if (times > 0) { double bw = getbw(name, buf, filesize, times); MPI_Barrier(MPI_COMM_WORLD); /* compute stats and print them to the screen */ double bwmin, bwmax, bwsum; MPI_Reduce(&bw, &bwmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&bw, &bwmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(&bw, &bwsum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0) { printf("FileIO: Min %7.2f MB/s\tMax %7.2f MB/s\tAvg %7.2f MB/s\tAgg %7.2f MB/s\n", bwmin, bwmax, bwsum/ranks, bwsum ); } } if (buf != NULL) { free(buf); buf = NULL; } SCR_Finalize(); MPI_Finalize(); return 0; }