Example #1
0
main (int argc, char **argv) 
{
    char   c, fname[64], buf[64], resp[32], val[12], config[128];
    int	   i, j, debug=0, clear = 1, nimages=1, delay=0, interactive=1;
    int    nsegs, pagenum, nvals, imnum=0;
    void   *data;
    char   *cdata, *cp;
    int    *idata, *ip;
    short  *sdata, *sp;
    double stime, etime;


    /* Process command-line arguments.
     */
    strcpy (fname, "\0");
    for (i=1; i < argc; i++) {
        if (strncmp (argv[i], "-cache", 2) == 0) {
	    strcpy (fname, argv[++i]);
        } else if (strncmp (argv[i], "-delay", 2) == 0) {
	    delay = atoi (argv[++i]);
        } else if (strncmp (argv[i], "-x", 2) == 0) {
	    debug++;
        } else if (strncmp (argv[i], "-nimages", 2) == 0) {
	    nimages = atoi (argv[++i]);
        } else if (strncmp (argv[i], "-keep", 2) == 0) {
	    clear = 0;
        } else if (strncmp (argv[i], "-interactive", 2) == 0) {
	    interactive = 1;
        } else if (strncmp (argv[i], "-batch", 2) == 0) {
	    interactive = 0;
        } else if (strncmp (argv[i], "-help", 2) == 0) {
	    printHelp ();
	    exit (0);

	} else
	    printf ("Unrecognized option: %s\n", argv[i]);
    }


    /* Initialize the config string.
     */
    sprintf (config, "debug=%d,cache_file=%s", debug, fname);


    /*  Open/Attach to the cache.
     */
    printf ("Opening cache....\n");
    if ((smc = smcOpen (config)) == (smCache_t *)NULL)
	fprintf (stderr, "Error opening cache, invalid file?.\n");



    /*  Simulate the readout sequence>
     */
    for (i=1; i <= nimages; i++) {
	printf ("Generating image %d ....", i);
        simMetaData ();				/* pre-readout header	*/
        simData ();				/* pixel data		*/
        simMetaData ();				/* post-readout header	*/
	printf ("done.\n");

        sleep (delay); 				/* pause requested time */
    }


    /* Once we're done, see if we want drop into a command mode.
     */
    if (interactive) {
	imnum = nimages;

        /* Command loop */
        printf ("%s (%d)>  ", argv[0], getpid());
        while ((c = getchar())) {

	    switch (c) {
            case 'n':                       /*   new sequence		*/
		stime = smUtilTime();
                nimages = optargi ();
                nimages = max (1, nimages);
		for (i=0; i < nimages; i++) {
		    printf ("Generating readout %d (%d/%d) ....", 
			imnum++, smc->npages, smc->top);
        	    simMetaData ();
		        simData ();
		    simMetaData ();
		    printf ("done.\n");
		}
		etime = smUtilTime();
		printf ("Created %d images in %f sec\n",nimages,(etime-stime));
                break;

            case 'd':                       /*   detach from segment        */
                smcListPages (smc, -1);
                printf ("which page? ");  scanf ("%d", &pagenum);
                page = &smc->pdata[pagenum];
                if (page->ac_locked)
                    printf ("Page is locked for access.\n");
                else
                    smcDetach (smc, page, FALSE);
                break;

            case 'l':                       /*   list segments              */
                nsegs = optargi ();
                if (nsegs < 0 && smc->npages == 0) {
                    printf ("No pages yet allocated, showing first 8.\n");
                    smcListPages (smc, 8);
                } else
                    smcListPages (smc, nsegs);
                break;

            case 'i':                       /*   initialize cache           */
            case 'I':
                if (smc) {
		    int stat;
                    printf ("Initializing cache....\n");
                    stat = smcInitialize (smc);
                    if (stat && debug) 
                        smcPrintCacheInfo (smc, "After Initialize:");
                } else
                    printf ("Cannot initialize() before open()\n");
                break;

	    case '\n':
                printf ("%s (%d)>  ", argv[0], getpid());
	        continue;

            case 'p':                       /*   print cache info           */
                if (smc) {
                    smcPrintCacheInfo (smc, (char *)NULL);
                    smcPrintCfgInfo (&smc->sysConfig, (char *)NULL);
                } else
                    printf ("Null cache ptr, try opening a cache first.\n");
            break;


            case 'q':                       /*   quit                       */
            case 'C':                       /*   close cache                */
                printf ("free cache? ");    scanf ("%s", val);
                smc = smcClose (smc, is_true(val[0]));
                printf ("After smcClose(): smc = 0x%x\n", smc);
                break;

            case 'g':                       /*   print segment data         */
                smcListPages (smc, -1);
                printf ("which page? ");  scanf ("%d", &pagenum);
                page = &smc->pdata[pagenum];
                if (page->ac_locked)
                    printf ("Page is locked for access.\n");
                else {
                    printf ("how many lines? ");  scanf ("%d", &nvals);
                    if (page->type == TY_META) {
                        cdata = (char *)smcGetPageData (page);
                        for (cp=cdata, i=0; i < nvals; i++) {
                            printf ("%.80s", cp);
			    cp += 80;
			}
                    } else {
                        idata = (int *)smcGetPageData (page);
                        for (i=0; i < nvals; i++)
                            printf ("(%d) %s", idata[i],(i&&(i%4==0))?"\n":"");
                    }
                    printf ("\n");
                }
                break;


	    default:
	        printf ("Unknown command: '%c'\n", c);
	    }

            if (c == 'q' || c == 'C')
                break;
        }
    }

    printf ("Done\n");
    if (smc && !interactive) 
	smcClose (smc, clear);
}
Example #2
0
  void
  EReplicaExchangeSimulation::initialisation()
  {
    preSimInit();

    for (unsigned int i = 0; i < nSims; i++)
      {
	setupSim(Simulations[i], 
		 vm["config-file"].as<std::vector<std::string> >()[i]);

	Simulations[i].initialise();

	postSimInit(Simulations[i]);
      }

    //Ensure we are in the right ensemble for all simulations
    for (size_t i = nSims; i != 0;)
      if (dynamic_cast<const dynamo::EnsembleNVT* >(Simulations[--i].getEnsemble().get()) == NULL)
	M_throw() << vm["config-file"].as<std::vector<std::string> >()[i]
		  << " does not have an NVT ensemble";

    //Ensure the types of the simulation Liouvilleans match
    for (size_t i(1); i < nSims; ++i)
      if (typeid(Simulations[i].dynamics.getLiouvillean())
	  != typeid(Simulations[0].dynamics.getLiouvillean()))
	M_throw() << vm["config-file"].as<std::vector<std::string> >()[i]
		  << " does not have the same Liouvillean type as "
		  << vm["config-file"].as<std::vector<std::string> >()[0];

    //Test a thermostat is available
    for (unsigned int i = 0; i < nSims; i++)
      if (Simulations[i].getSystem("Thermostat") == NULL)
	M_throw() << "Could not find the Thermostat for system " << i 
		  << "\nFilename " << vm["config-file"].as<std::vector<std::string> >()[i];
  
    //Set up the replex organisation
    temperatureList.clear();

    for (unsigned int i = 1; i < nSims; i++)
      if (Simulations[0].N != Simulations[i].N)
	M_throw() << "Every replica configuration file must have the same number of particles!";
  
    for (unsigned int i = 0; i < nSims; i++)
      {
	bool didWork = false;
	BOOST_FOREACH(shared_ptr<System>& sysPtr1, Simulations[i].dynamics.getSystemEvents())
	  if (sysPtr1->getName() == "Thermostat")
	    {
	      if (dynamic_cast<SysAndersen*>(sysPtr1.get()) == NULL)
		M_throw() << "Could not upcast thermostat to Andersens";
	    
	      temperatureList.push_back
		(replexPair
		 (Simulations[i].getEnsemble()->getEnsembleVals()[2], 
		  simData(i,Simulations[i].getEnsemble()->getReducedEnsembleVals()[2])));
	    
	      didWork = true;
	      break;
	    }
      
#ifdef DYNAMO_DEBUG
	if (!didWork)
	  {	 
	    std::cout << "Could not find thermostat system event";
	    exit(1);
	  }
#endif
      
      }
  
    std::sort(temperatureList.begin(), temperatureList.end());  
  
    SimDirection.resize(temperatureList.size(), 0);
    roundtrip.resize(temperatureList.size(), false);
  
    SimDirection[temperatureList.front().second.simID] = 1; //Going up
    SimDirection[temperatureList.back().second.simID] = -1; //Going down
  
    //If a system ticker is set we scale the ticker time such that the
    //number of ticks in all systems is equal.
    if (vm.count("ticker-period"))
      for (size_t i = 0; i < nSims; ++i)
	{
	  double tFactor 
	    = std::sqrt(temperatureList.begin()->second.realTemperature
			/ Simulations[i].getEnsemble()->getReducedEnsembleVals()[2]); 
	  Simulations[i].setTickerPeriod(vm["ticker-period"].as<double>() * tFactor);
	}
  }