Beispiel #1
0
void Simulation::readCheckpoint() {
    int checkpointNum = readCheckpointNum();
    
  // Open the latest file
  ostringstream name;
  name << CHECKPOINT << checkpointNum;	// try uncompressed
  ifstream in(name.str().c_str(), ios::in | ios::binary);
  if (in.good()) {
    checkpoint (in, checkpointNum);
    in.close();
  } else {
    name << ".gz";				// then compressed
    igzstream in(name.str().c_str(), ios::in | ios::binary);
    if (!in.good())
      throw util::checkpoint_error ("Unable to read file");
    checkpoint (in, checkpointNum);
    in.close();
  }
  
  cerr << "Loaded checkpoint from: " << name.str() << endl;
  
  // On resume, write a checkpoint so we can tell whether we have identical checkpointed state
  if (util::CommandLine::option (util::CommandLine::TEST_CHECKPOINTING))
    writeCheckpoint();
}
static int runSystem(const NBodyCtx* ctx, NBodyState* st, const NBodyFlags* nbf)
{
    const real tstop = ctx->timeEvolve - ctx->timestep / 1024.0;

    if (nbf->visualizer)
    {
        launchVisualizer(st, nbf->visArgs);
    }

    while (st->tnow < tstop)
    {
        updateDisplayedBodies(st);

        if (stepSystem(ctx, st))   /* advance N-body system */
            return 1;

        nbodyCheckpoint(ctx, st);
    }

    if (BOINC_APPLICATION || ctx->checkpointT >= 0)
    {
        mw_report("Making final checkpoint\n");
        if (writeCheckpoint(ctx, st))
            return warn1("Failed to write final checkpoint\n");
    }

    return 0;
}
static void finalCheckpoint(EvaluationState* es)
{
  #if BOINC_APPLICATION
    boinc_begin_critical_section();
  #endif

    if (writeCheckpoint(es))
        fail("Failed to write final checkpoint\n");

  #if BOINC_APPLICATION
    boinc_end_critical_section();
  #endif
}
static CALresult checkpointCAL(SeparationCALMem* cm, const IntegralArea* ia, EvaluationState* es)
{
    CALresult err;

    readResults(cm, ia, es);
    err = writeCheckpoint(es) ? CAL_RESULT_ERROR : CAL_RESULT_OK;

  #if BOINC_APPLICATION
    boinc_checkpoint_completed();
  #endif

    return err;
}
static cl_int checkpointCL(CLInfo* ci, SeparationCLMem* cm, const IntegralArea* ia, EvaluationState* es)
{
    cl_int err;

    err = readKernelResults(ci, cm, es, ia);
    if (err != CL_SUCCESS)
        return err;

    err = writeCheckpoint(es) ? MW_CL_ERROR : CL_SUCCESS;
    mw_checkpoint_completed();

    return err;
}
static inline void nbodyCheckpoint(const NBodyCtx* ctx, NBodyState* st)
{
    if (nbodyTimeToCheckpoint(ctx, st))
    {
        if (writeCheckpoint(ctx, st))
            fail("Failed to write checkpoint\n");

      #if BOINC_APPLICATION
        boinc_checkpoint_completed();
      #endif /* BOINC_APPLICATION */
    }

  #if BOINC_APPLICATION
    boinc_fraction_done(st->tnow / ctx->timeEvolve);
  #endif /* BOINC_APPLICATION */
}
Beispiel #7
0
/*
 * This is the basic entry point for most IO operations.  It should be called
 * once per iteration of the code, and it will determine which types of IO
 * IO should be performed.  The different types of IO are:
 * 
 * 1.   Spatial dumps
 * 2.   Checkpoint dumps
 * 3.   Scalar reductions
 * 4.   Status file updates
 * 
 * The frequency of each of these is controlled by parameters read in from the
 * configuration file.
 */
void performOutput()
{

    if(crank == 0)
    {
        //update the status file?
        if(iteration % statusRate == 0)
        {
            status = fopen("status", "a");
            fprintf(status, "Iteration %d:\n dt = %g\tElapsed Time = %g\nMax Vel: %g %g %g\n", iteration, dt, elapsedTime, maxVel[0], maxVel[1], maxVel[2]);
            fclose(status);
        }
    }

    /*
     * The scalars are single values that result from a global operation on the
     * domain.  The scalars are:
     * 
     * [0]  --  iteration
     * [1]  --  elapsed time
     * [2]  --  min  u
     * [3]  --  max  u
     * [4]  --  mean u
     * [5]  --  min  v
     * [6]  --  max  v
     * [7]  --  mean v
     * [8]  --  min  w
     * [9]  --  max  w
     * [10] --  mean w
     * [11] --  mean kinetic energy density
     * [12] --  max kinetic energy density
     * 
     * ------------ Only present if magnetic fields are included:
     * [13] --  min  Bx
     * [14] --  max  Bx
     * [15] --  mean Bx
     * [16] --  min  By
     * [17] --  max  By
     * [18] --  mean By
     * [19] --  min  Bz
     * [20] --  max  Bz
     * [21] --  mean Bz
     * [22] --  mean magnetic energy density
     * [23] --  max  magnetic energy density* 
     */
    if(compute_node)
    {
        if(iteration % scalarRate == 0)
        {
            PRECISION * local = (PRECISION*)malloc(sizeof(PRECISION)*numScalar);
            int i;

            PRECISION * datax = u->vec->x->spatial;
            PRECISION * datay = u->vec->y->spatial;
            PRECISION * dataz = u->vec->z->spatial;
            PRECISION temp;

            //I feel like there should be an MPI operation that doesn't require
            //me to manually take a local min/max/etc, but I'm failing to find
            //it.  The general MPI_Reduce does an element by element reduction,
            //which is not what we want.
            
            local[0] = iteration;
            local[1] = elapsedTime;
            local[2] = datax[0];
            local[3] = datax[0];
            local[4] = datax[0];
            local[5] = datay[0];
            local[6] = datay[0];
            local[7] = datay[0];
            local[8] = dataz[0];
            local[9] = dataz[0];
            local[10] = dataz[0];
            temp = pow(datax[0],2) + pow(datay[0],2) + pow(dataz[0],2);
            local[11] = temp;
            local[12] = temp;
            for(i = 1; i < spatialCount; i++)
            {
                local[2] = fmin(local[2], datax[i]);
                local[3] = fmax(local[3], datax[i]);
                local[4] += datax[i];
                local[5] = fmin(local[5], datay[i]);
                local[6] = fmax(local[6], datay[i]);
                local[7] += datay[i];
                local[8] = fmin(local[8], dataz[i]);
                local[9] = fmax(local[9], dataz[i]);
                local[10] += dataz[i];
                temp = pow(datax[i],2) + pow(datay[i],2) + pow(dataz[i],2);
                local[11] += temp;
                local[12] = fmax(temp, local[12]);
            }

            if(crank == 0)
            {
                piScalarData[0] = local[0];
                piScalarData[1] = local[1];
            }
            MPI_Reduce(local+2, piScalarData+2, 1, MPI_PRECISION, MPI_MIN, 0, ccomm);
            MPI_Reduce(local+3, piScalarData+3, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
            MPI_Reduce(local+4, piScalarData+4, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
            MPI_Reduce(local+5, piScalarData+5, 1, MPI_PRECISION, MPI_MIN, 0, ccomm);
            MPI_Reduce(local+6, piScalarData+6, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
            MPI_Reduce(local+7, piScalarData+7, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
            MPI_Reduce(local+8, piScalarData+8, 1, MPI_PRECISION, MPI_MIN, 0, ccomm);
            MPI_Reduce(local+9, piScalarData+9, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
            MPI_Reduce(local+10, piScalarData+10, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
            MPI_Reduce(local+11, piScalarData+11, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
            MPI_Reduce(local+12, piScalarData+12, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);

            if(magEquation)
            {
                datax = B->vec->x->spatial;
                datay = B->vec->y->spatial;
                dataz = B->vec->z->spatial;

                local[13] = datax[0];
                local[14] = datax[0];
                local[15] = datax[0];
                local[16] = datay[0];
                local[17] = datay[0];
                local[18] = datay[0];
                local[19] = dataz[0];
                local[20] = dataz[0];
                local[21] = dataz[0];
                temp = pow(datax[0],2) + pow(datay[0],2) + pow(dataz[0],2);
                local[22] = temp;
                local[23] = temp;
                for(i = 1; i < spatialCount; i++)
                {
                    local[13] = fmin(local[13], datax[i]);
                    local[14] = fmax(local[14], datax[i]);
                    local[15] += datax[i];
                    local[16] = fmin(local[16], datay[i]);
                    local[17] = fmax(local[17], datay[i]);
                    local[18] += datay[i];
                    local[19] = fmin(local[19], dataz[i]);
                    local[20] = fmax(local[20], dataz[i]);
                    local[21] += dataz[i];
                    temp = pow(datax[i],2) + pow(datay[i],2) + pow(dataz[i],2);
                    local[22] += temp;
                    local[23] = fmax(temp, local[21]);
                }

                MPI_Reduce(local+13, piScalarData+13, 1, MPI_PRECISION, MPI_MIN, 0, ccomm);
                MPI_Reduce(local+14, piScalarData+14, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
                MPI_Reduce(local+15, piScalarData+15, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
                MPI_Reduce(local+16, piScalarData+16, 1, MPI_PRECISION, MPI_MIN, 0, ccomm);
                MPI_Reduce(local+17, piScalarData+17, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
                MPI_Reduce(local+18, piScalarData+18, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
                MPI_Reduce(local+19, piScalarData+19, 1, MPI_PRECISION, MPI_MIN, 0, ccomm);
                MPI_Reduce(local+20, piScalarData+20, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
                MPI_Reduce(local+21, piScalarData+21, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
                MPI_Reduce(local+22, piScalarData+22, 1, MPI_PRECISION, MPI_SUM, 0, ccomm);
                MPI_Reduce(local+23, piScalarData+23, 1, MPI_PRECISION, MPI_MAX, 0, ccomm);
            }
            free(local);
            
            //Either store our data for later output, or perform the write to 
            //file
            if(crank == 0)
            {
                //make the means means and not sums
                piScalarData[4] /= (nx*ny*nz);
                piScalarData[7] /= (nx*ny*nz);
                piScalarData[10] /= (nx*ny*nz);
                if(magEquation)
                {
                    piScalarData[15] /= (nx*ny*nz);
                    piScalarData[18] /= (nx*ny*nz);
                    piScalarData[21] /= (nx*ny*nz);
                }

                scalarCount++;
                piScalarData += numScalar;

                //no reason to send this small amount of data to an IO node.
                //our root compute node will just quickly take care of this.
                if(scalarCount >= scalarPerF)
                {
                    char fileName[100];
                    sprintf(fileName, "Scalars/%08d",iteration);

                    FILE * out = fopen(fileName, "w");
                    fwrite(scalarData, sizeof(PRECISION), numScalar * scalarPerF, out);
                    fclose(out);

                    scalarCount = 0;
                    piScalarData = scalarData;
                }
            }
        }
    }
    
    //Time for spatial file output?
    if(iteration % spatialRate == 0)
    {
        char * name = (char *)malloc(100);
        
        //create the directory
        if(crank == 0)
        {
            sprintf(name, "Spatial/%08d",iteration);
            mkdir(name, S_IRWXU);

            //Record the simulation time that this snapshot belongs to
            sprintf(name, "Spatial/%08d/info",iteration);
            FILE * info;
            info = fopen(name, "w");
            fprintf(info, infostro, elapsedTime);
            fclose(info);
        }
        MPI_Barrier(MPI_COMM_WORLD);

        if(compute_node)
        {
            if(momEquation || kinematic)
            {
                trace("Outputing u\n");
                writeSpatial(u->vec->x,0);

                trace("Outputing v\n");
                writeSpatial(u->vec->y,0);

                trace("Outputing w\n");
                writeSpatial(u->vec->z,0);
            }
            if(tEquation)
            {
                trace("Outputting T\n");
                writeSpatial(T, 0);
            }
            if(magEquation)
            {
                trace("Outputing Bx\n");
                writeSpatial(B->vec->x,0);

                trace("Outputing By\n");
                writeSpatial(B->vec->y,0);

                trace("Outputing Bz\n");
                writeSpatial(B->vec->z,0);
            }
        }
        else if(io_node)
        {
            if(momEquation || kinematic)
            {
                sprintf(name, "Spatial/%08d/u", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);

                sprintf(name, "Spatial/%08d/v", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);

                sprintf(name, "Spatial/%08d/w", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);
            }
            if(tEquation)
            {
                sprintf(name, "Spatial/%08d/T", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);
            }
            if(magEquation)
            {
                sprintf(name, "Spatial/%08d/Bx", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);

                sprintf(name, "Spatial/%08d/By", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);

                sprintf(name, "Spatial/%08d/Bz", iteration);
                trace("Writing to file %s\n", name);
                writeSpatial(0, name);
            }
        }

        free(name);
    }

    if(iteration % checkRate == 0)
    {
        if(compute_node)
            writeCheckpoint();
    }
}
Beispiel #8
0
int main(int argc, char **argv)
{
	cout << "Greetings, [INSERT_SUBJECT_NAME_HERE]!\n"
	        "Welcome to the Log-Indexed File Emulator, or L.I.F.E.\n"
	        "Wait just a moment while we set up a few things...\n\n";
	
	initDrive();
	checkPointInit();
	readFileMap();
	cout << "\nDone! Now it's time for you to grab L.I.F.E. by the horns!\n"
	        "Enter a command, or enter 'help' for usage information.\n"
	        "\n{epic prompt} ";

  string command;
  vector<string> args;
  while(getline(cin, command))
	{
		args.clear();
		split(command, ' ', args);
		if(!command.empty()){
			if((args[0] == "import" || args[0] == "i") && args.size() == 3) 
			{
				import(args[1], args[2]);                                                 
			}
			else if((args[0] == "remove" || args[0] == "r") && args.size() == 2)
			{
				remove(args[1]);
			}
			else if((args[0] == "cat" || args[0] == "r") && args.size() == 2)
			{
				cat(args[1]);
			}
			else if((args[0] == "list" || args[0] == "l") && args.size() == 1)
			{
				list();
			}
			else if((args[0] == "exit" || args[0] == "q") && args.size() == 1)
			{
				cout << "Getting L.I.F.E. together...\n\n";
				writeCheckpoint();
				wbuffer.writeToDisk();
				writeFileMap();
				cout << "\nQuitting L.I.F.E.\n\u0CA0_\u0CA0\n";
				exit(0);
			}
			else if((args[0] == "overwrite" || args[0] == "o") && args.size() == 5)
			  {
			    cout<<"overwriting...\n";
			    overwrite(args[1],args[2], args[3],args[4]);
			  }
			else if((args[0] == "display" || args[0] == "d") && args.size() == 4)

			{
				cout<<"displaying...\n";
				//display(args[1],args[2], args[3]);
			}

			else if((args[0] == "help" || args[0] == "h"))
			{
				if(args.size() == 1){
					cout << "Thanks for calling L.I.F.E. help.\nHeaven knows we all need it from time to time.\nValid L.I.F.E. commands:\n"
									"\timport <filename> <lfs_filename>\n"
									"\tremove <lfs_filename>\n"
									"\tlist\n"
									"\texit\n"
									"For more details on a command, enter 'help <command>'.\n";
				}else if(args.size() == 2){
					if(args[1] == "import"){
						cout << "Usage: import <filepath> <lfs_filename>\n"
						        "Info:  Imports a file from a filepath to the DRIVE, using the given filename.\n";
					}
					else if(args[1] == "remove"){
						cout << "Usage: remove <lfs_filename>\n"
						        "Info:  Removes a file from the DRIVE.\n";
					}
					else if(args[1] == "list"){
						cout << "Usage: list\n"
						        "Info:  Lists the names and sizes of all files currently in the DRIVE.\n";
					}
					else if(args[1] == "exit"){
						cout << "Usage: exit\n"
						        "Info:  C'mon bro. Take a good guess.\n";
					}
					else if(args[1] == "help"){
						cout << "Usage: help <command>\n"
						        "Info:  Prints usage info for all commands, and optionally prints specific info for one command.\n";
					}else if(args[1] == "me"){
						cout << "You're not alone; many of us have had suicidal thoughts at some point in our lives. "
						        "Feeling suicidal is not a character defect, and it doesn't mean that you are crazy, or weak, or flawed. "
										"It only means that you have more pain than you can cope with right now. "
										"This pain seems overwhelming and permanent at the moment. "
										"But with time and support, you can overcome your problems and the pain and suicidal feelings will pass.\n"
										"If you’re feeling suicidal right now, please call for help!\n\n"
										"Call 1-800-273-TALK in the U.S.\n"
										"Or visit IASP(http://www.iasp.info/resources/Crisis_Centres) to find a helpline in your country. "
										"Alternatively, talk to someone you trust and let them know how bad things are.\n";
					}else{
						cout << "'" << args[1] << "' is not a command... Take your funny business elsewhere. This is a serious, real-world program.\n";
					}
				}else{
					cout << "Hey, don't get too crazy, now.\n";
				}
			}
			else
			{
				cout << "Invalid command and/or parameters. Enter 'help' for...y'know...help.\n";
			}
		}
		cout << "\n{epic prompt} ";
	}
	return 0;
}
Beispiel #9
0
int Simulation::start(){
    // +1 to let final survey run
    totalSimDuration = _population->_transmissionModel->vectorInitDuration() + Global::maxAgeIntervals + Surveys.getFinalTimestep() + 1;
    int testCheckpointStep = -1;	// declare here so goto doesn't cross initialization
    
    if (isCheckpoint()) {
	readCheckpoint();
    } else {
	_population->createInitialHumans();
    }
    
    
    // phase loop
    while (true) {
	// loop for steps within a phase
	while (Global::simulationTime < simPeriodEnd) {
	    // checkpoint
	    if (util::BoincWrapper::timeToCheckpoint() || Global::simulationTime == testCheckpointStep) {
		writeCheckpoint();
		util::BoincWrapper::checkpointCompleted();
		if (Global::simulationTime == testCheckpointStep)
		    throw util::cmd_exit ("Checkpoint test: checkpoint written");
	    }
	    
	    // interventions
	    if (Global::timeStep == Surveys.currentTimestep) {
		_population->newSurvey();
		Surveys.incrementSurveyPeriod();
	    }
	    _population->implementIntervention(Global::timeStep);
	    
	    // update
	    ++Global::simulationTime;
	    _population->update1();
	    ++Global::timeStep;
	    util::BoincWrapper::reportProgress (double(Global::simulationTime) / totalSimDuration);
	}
	
	// phase transition: end of one phase to start of next
	if (phase == STARTING_PHASE) {
	    simPeriodEnd = _population->_transmissionModel->vectorInitDuration();
	    phase = VECTOR_FITTING;
	} else if (phase == VECTOR_FITTING) {
	    int extend = _population->_transmissionModel->vectorInitIterate ();
	    if (extend > 0) {	// repeat phase
		simPeriodEnd += extend;
		totalSimDuration += extend;
	    } else {		// next phase
		simPeriodEnd += Global::maxAgeIntervals;
		phase = ONE_LIFE_SPAN;
	    }
	} else if (phase == ONE_LIFE_SPAN) {
	    simPeriodEnd = totalSimDuration;
	    Global::timeStep=0;
	    _population->preMainSimInit();
	    _population->newSurvey();	// Only to reset TransmissionModel::innoculationsPerAgeGroup
	    Surveys.incrementSurveyPeriod();
	    phase = MAIN_PHASE;
	} else if (phase == MAIN_PHASE) {
	    phase = END_SIM;
	    break;
	}
	testCheckpointStep = -1;
	if (util::CommandLine::option (util::CommandLine::TEST_CHECKPOINTING))
	    testCheckpointStep = Global::simulationTime + (simPeriodEnd - Global::simulationTime) / 2;
    }
    
    delete _population;	// must destroy all Human instances to make sure they reported past events
    Surveys.writeSummaryArrays();
    
    // Write scenario checksum, only if simulation completed.
    cksum.writeToFile (util::BoincWrapper::resolveFile ("scenario.sum"));
    
    return 0;
}