Example #1
0
/** \fn queueing_miniapp(po::variables_map const& vm)
    \brief Execute the queing miniapp
    \param vm encapsulate the command line and all needed informations
 */
void queueing_miniapp(po::variables_map const& vm){
	bool verbose = vm.count("verbose");
	bool spike = vm.count("spike-enabled");
	bool algebra = vm.count("with-algebra");

    if(vm.count("spinlock")){
   		Pool<spinlock> pl(verbose, vm["eventsper"].as<int>(), vm["percent-ite"].as<int>(), spike, algebra);
		run_sim(pl,vm);
    } else {
   		Pool<mutex> pl(verbose, vm["eventsper"].as<int>(), vm["percent-ite"].as<int>(), spike, algebra);
		run_sim(pl,vm);
    }
}
Example #2
0
int main(int argc, const char * argv[]) {
    // insert code here...
    if(argc != 5){
        printf("Please pass required arguement with required sequence into program. \n");
        printf("cpssim Time config.txt stats.txt log.txt \n");
        return 1;
    }
    
    double time_limit = atof(argv[1]);
    FILE* config_file = fopen(argv[2], "r");
    FILE* stats_file = fopen(argv[3], "a");
    FILE* log_file = fopen(argv[4], "a");

    if(config_file == NULL || stats_file == NULL || log_file == NULL){
        printf("Read/Write files fails. \n");
        return 1;
    }
    
    bool result = build_network(config_file,stats_file , log_file);
    if(result){
        printf("Build sucess! \n");
        run_sim(time_limit);
    }
    else{
        printf("Build fail! \n");
    }
    
    fclose(config_file);
    fclose(log_file);
    fclose(stats_file);
    printf("Finish!\n");
    
    return 0;
}
Example #3
0
/**
 * \brief instantiate an environment variable(either spike::environment or queueing::pool)
 * and performs run_simulation() function on it.
 */
int main(int argc, char* argv[]) {
    assert(argc == 7);
    int size = mapp::master.size();
    int rank = mapp::master.rank();

    int eventsPer = atoi(argv[1]);
    int simTime = atoi(argv[2]);
    int numOut = atoi(argv[3]);
    int numIn = atoi(argv[4]);
    int netconsPer = atoi(argv[5]);
    int isNonBlocking = atoi(argv[6]);

    struct timeval start, end;
    assert(numIn <= (numOut * (size - 1)));
    //numcells, eventsper, percent ite, verbose, algebra, percent spike, numout, numin, size, rank
    queueing::pool env(64, eventsPer, 90, false, true, 4, numOut, numIn, netconsPer, size, rank);

    gettimeofday(&start, NULL);
    run_sim(env, simTime, isNonBlocking);
    gettimeofday(&end, NULL);

    env.accumulate_stats();
    long long diff_ms = (1000 * (end.tv_sec - start.tv_sec)) + ((end.tv_usec - start.tv_usec) / 1000);
        std::cout<<"run time: "<<diff_ms<<" ms"<<std::endl;
        std::cout<<"Process zero received: "<<env.received()<<" spikes"<<std::endl;
        std::cout<<"Process zero received: "<<env.relevent()<<" RELEVENT spikes"<<std::endl;
    return 0;
}
Example #4
0
int main(int argc, char **argv)
{
	srand48(time(NULL));
	N = atoi(argv[1]);
	setup_r_values();

	for(int j = 0; j< num_runs-1; j++)
	{
		initialize_sim();
		run_sim();
		record_sim(j);
		clear_sim();
	}

	initialize_sim();
	run_sim();
	record_sim(num_runs-1);
	write_sim_to_file();

	write_runs_to_file();

	return 0;
}
Example #5
0
int main(int argc, char* argv[]){
	// Get the number of processors
	int np = omp_get_num_procs();
	// Set the number of OpenMP threads to be the number of processors	
	omp_set_num_threads(np);

	
	// First, run it with the OpenMP turned on.
	struct timeval tim;
	gettimeofday(&tim, NULL);
	double timing1 = tim.tv_sec+(tim.tv_usec/1000000.0);
	run_sim();

	// Reduce the number of threads to 1 and run again.
	gettimeofday(&tim, NULL);
	double timing2 = tim.tv_sec+(tim.tv_usec/1000000.0);
	omp_set_num_threads(1);
	run_sim();
	gettimeofday(&tim, NULL);
	double timing3 = tim.tv_sec+(tim.tv_usec/1000000.0);

	// Output speedup
	printf("\n\nOpenMP speed-up: %.3fx (perfect scaling would give %dx)\n",(timing3-timing2)/(timing2-timing1),np);
}
Example #6
0
int run_sim()
{
  struct event* eve;
  while (!end_condition)
    {
      eve = head;
      clock = eve->time;
      switch (eve->type)
	{
	case EVENT1:
		process_event1(eve);
		break;
	case EVENT2:
		process_event2(eve);
		break;

	// add more events

	default:
		// error
	}

      head = eve->next;
      free(eve);
      eve = NULL;
    }
  return 0;
}
////////////////////////////////////////////////////////////////
int main(int argc, char *argv[] )
{
  // parse arguments
  init();
  run_sim();
  generate_report();
  return 0;
}
Example #7
0
//-------- Begin of function Battle::run --------//
//
// <int> mpGame - whether this is a multiplayer game or not.
//
void Battle::run(NewNationPara *mpGame, int mpPlayerCount)
{
	int oldCursor = mouse_cursor.get_icon();
	mouse_cursor.set_icon(CURSOR_WAITING);

#ifdef DEBUG
	debug_sim_game_type = (misc.is_file_exist("sim.sys")) ? 2 : 0;
	if(debug_sim_game_type)
	{
		run_sim();
		return;
	}
#endif

#ifdef HEADLESS_SIM
	game.game_mode = GAME_DEMO; // skip end screens
#endif

	// ####### begin Gilbert 24/10 #######//
	//-- random seed is initalized at connecting multiplayer --//
	//if( !mpGame )
	//	info.init_random_seed(0);
	// ####### end Gilbert 24/10 #######//

	//----------- save the current seed for generating map -----------//
	#ifdef DEBUG2
		File seedFile;
		char *chPtr = misc.format(misc.get_random_seed());
		seedFile.file_create("mapseed.rs");
		seedFile.file_write(chPtr, strlen(chPtr));
		seedFile.file_close();
	#endif

	world.generate_map();

	//------- create player nation --------//

	if( !mpGame )
	{
#ifndef HEADLESS_SIM
		// if config.race_id == 0, select a random race, but don't call misc.random
		int nationRecno = nation_array.new_nation( NATION_OWN,
								config.race_id ? config.race_id : 1+misc.get_time() % MAX_RACE,
								config.player_nation_color );

		nation_array.set_human_name( nationRecno, config.player_name );
#endif
	}
	else
	{
		for( int i = 0; i < mpPlayerCount; ++i )
		{
			int nationRecno = nation_array.new_nation(mpGame[i]);
			if( nationRecno != mpGame[i].nation_recno )
				err.run( "Unexpected nation recno created" );
			nation_array.set_human_name( nationRecno, mpGame[i].player_name );
		}
	}

	//--------- create ai nations --------//

	if( mpGame )
	{
		int aiToCreate = config.ai_nation_count;
		if( aiToCreate + mpPlayerCount > MAX_NATION )
			aiToCreate = MAX_NATION - mpPlayerCount;
		err_when( aiToCreate < 0 );
		create_ai_nation(aiToCreate);
	}
	else
	{
#ifdef HEADLESS_SIM
		create_ai_nation(config.ai_nation_count+1); // no human player
#else
		create_ai_nation(config.ai_nation_count);
#endif
	}

	//------ create pregame objects ------//

	create_pregame_object();

	//------- update nation statistic -------//

	nation_array.update_statistic();

	//--- highlight the player's town in the beginning of the game ---//

	Town* townPtr;

	for( int i=1 ; i<=town_array.size() ; i++ )
	{
		townPtr = town_array[i];

		if( townPtr->nation_recno == nation_array.player_recno )
		{
			world.go_loc( townPtr->loc_x1, townPtr->loc_y1 );
			break;
		}
	}

	//---- reset config parameter ----//

	// Set speed to normal. When hosting, broadcast the speed to the clients. As a client, set to default speed initially.
	if ( remote.is_enable() && !remote.is_host )
		sys.set_speed(12, COMMAND_REMOTE);
#ifndef HEADLESS_SIM
	else
		sys.set_speed(12, COMMAND_PLAYER);
#endif

	//---- reset cheats ----//

	config.fast_build = 0;
	config.king_undie_flag = sys.testing_session && !mpGame;
	config.blacken_map = 1;
	config.disable_ai_flag = 0;

	if( sys.testing_session )
		config.show_unit_path = 3;

	// ######## begin Gilbert 11/11 #######//
	// enable tech and god, useful for multi-player
#if(0)
	for( i = 1; i < nation_array.size(); ++i )
	{
		if( !nation_array.is_deleted(i) && !nation_array[i]->is_ai() )
		{
			tech_res.inc_all_tech_level(i);
			god_res.enable_know_all(i);
		}
	}
#endif
	// ######## end Gilbert 11/11 #######//

	//------- enable/disable sound effects -------//

#ifndef HEADLESS_SIM
	int songId = (~nation_array)->race_id <= 7 ? (~nation_array)->race_id+1 : music.random_bgm_track();
	music.play(songId, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
#endif

	mouse_cursor.restore_icon(oldCursor);

	//--- give the control to the system main loop, start the game now ---//

	sys.run();
}
int main(int argc, char **argv) {
	
	long num_agents;
	long num_steps;
	int thread_count;
	char* filename;
	long timestep;

	if (argc != 5) {
        printf("Usage: num_agents num_steps filename\n");
        exit(1);
        }
        
        thread_count = atoi(argv[1]);
        num_agents = atol(argv[2]);
        num_steps = atol(argv[3]);
        filename = argv[4];
        
        
        
        printf("Running a simulation with %lu agents for %lu steps and saving the data to the file %s...\n", 
        	num_agents, num_steps, filename);
        
        // here's the simulation skeleton
        
        
        // create the agents, with random headings, maybe random locations or all in a bunch
        unsigned int i = 1;
        int j;
        
        Agent **agent_lists_at_timesteps;
        
        agent_lists_at_timesteps = malloc(num_steps * sizeof(Agent*));
        
	int a;
	for(a=0; a<num_steps; a++)
	{
		agent_lists_at_timesteps[a] = malloc(num_agents * sizeof(Agent));	
	}
        
      //  Agent *agent_list = malloc(num_agents * sizeof(Agent));
        
        
        struct timeval tv;
        gettimeofday(&tv, NULL);
        
        
        srand(tv.tv_usec);
        for(j = 0; j < num_agents - 1; j++){
        	//printf("Creating agent %d\n", j);
        	Vector2D heading = init_vector(-(rand_r(&i) % 5), -(rand_r(&i) % 5));
        	//printf("Done vector creation\n");
        	Point2D start_loc = init_point((rand_r(&i) % WINDOWSIZE), (rand_r(&i) % WINDOWSIZE));
        	double speed = 5;
        	Agent_Type prey_type = prey;
        	//printf("initing agent\n");
        	Agent new_agent = init_agent(&heading, &start_loc, speed, prey_type);
        	//printf("Adding to list\n");	
        	agent_lists_at_timesteps[0][j] = new_agent;
        	
        	//printf("Done creating agent %d\n", j);
        }
        Vector2D heading = init_vector((rand_r(&i) % 5), (rand_r(&i) % 5));
        Point2D start_loc = init_point((rand_r(&i) % WINDOWSIZE), (rand_r(&i) % WINDOWSIZE));
        double speed = 5;
        Agent_Type predator_type = predator;
        agent_lists_at_timesteps[0][j] = init_agent(&heading, &start_loc, speed, predator_type);
        int agent_close;
        double ts, te;
        
        
        // for each numstep
        ts = omp_get_wtime();
        
        for(timestep = 1; timestep < num_steps; timestep++){
        
        	int k;
        	Vector2D s,c,a, combo, seek_vector;
        	
# 		pragma omp parallel for num_threads(thread_count) \
        		private(s, c, a, combo, k)
        	for(k = 0; k< num_agents; k++){
        		if(agent_lists_at_timesteps[timestep-1][k].type == prey) {
        			
				s = separation(&agent_lists_at_timesteps[timestep-1][k], k, agent_lists_at_timesteps[timestep-1], num_agents);
				c = cohesion(&agent_lists_at_timesteps[timestep-1][k], k, agent_lists_at_timesteps[timestep-1], num_agents);
				a = alignment(&agent_lists_at_timesteps[timestep-1][k], k, agent_lists_at_timesteps[timestep-1], num_agents);
						
				
	
				combo = plus(&agent_lists_at_timesteps[timestep-1][k].heading, &s);
				plus_equals(&combo, &c);
				plus_equals(&combo, &a);
				divide_equals(&combo, 1.1);
				
				agent_lists_at_timesteps[timestep][k].heading.x = combo.x;
				agent_lists_at_timesteps[timestep][k].heading.y = combo.y;
				
				agent_lists_at_timesteps[timestep][k].position.x = agent_lists_at_timesteps[timestep-1][k].position.x;
				agent_lists_at_timesteps[timestep][k].position.y = agent_lists_at_timesteps[timestep-1][k].position.y;
				
				agent_lists_at_timesteps[timestep][k].speed = agent_lists_at_timesteps[timestep-1][k].speed;
				agent_lists_at_timesteps[timestep][k].type = agent_lists_at_timesteps[timestep-1][k].type;
        		}
        		
        		else {
        			/*
        			if(((timestep - 1) % 50) == 0) {
        				
        				agent_close = find_closest(&agent_lists_at_timesteps[timestep-1][k], k, agent_lists_at_timesteps[timestep-1], num_agents);	
        			}
        			*/
        			
        			//seek_vector = seek(&agent_lists_at_timesteps[timestep-1][k], &agent_lists_at_timesteps[timestep-1][agent_close]);
        			seek_vector = init_vector(5.0, 0.0);
        			
        			agent_lists_at_timesteps[timestep][k].heading.x = seek_vector.x;
				agent_lists_at_timesteps[timestep][k].heading.y = seek_vector.y;
					
				agent_lists_at_timesteps[timestep][k].position.x = agent_lists_at_timesteps[timestep-1][k].position.x;
				agent_lists_at_timesteps[timestep][k].position.y = agent_lists_at_timesteps[timestep-1][k].position.y;
					
				agent_lists_at_timesteps[timestep][k].speed = agent_lists_at_timesteps[timestep-1][k].speed;
				agent_lists_at_timesteps[timestep][k].type = agent_lists_at_timesteps[timestep-1][k].type;
        				
        			}
        			
        			
        	}
        				
        			
        			
        		
        		
        	
        	printf("just changed headings\n");
# 		pragma omp parallel for num_threads(thread_count)
        	for(k = 0; k< num_agents; k++){
        		agent_update(&agent_lists_at_timesteps[timestep][k], 1);
        		//printf("TRYING TO MOD %f \n", agent_list[k].position.x);
        		agent_lists_at_timesteps[timestep][k].position.x = ((int)agent_lists_at_timesteps[timestep][k].position.x % WINDOWSIZE);
        		agent_lists_at_timesteps[timestep][k].position.y = ((int)agent_lists_at_timesteps[timestep][k].position.y % WINDOWSIZE);
        		//printf("AND I GOT %f \n", agent_list[k].position.x);
        		
        	}
        	
        	/* for(k = 0; k < num_agents; k++){
        		add_point_to_file(agent_lists_at_timesteps[timestep][k].position.x, agent_lists_at_timesteps[timestep][k].position.y, 0, filename);	
        	}
        	
        	if(timestep != num_steps -1)
        		add_terminator_to_file(-2, filename); */
        	
        	//printf("timestep is %d\n", timestep);
        	
        }
 /*        add_terminator_to_file(-1, filename); */
        
        te = omp_get_wtime();
        
        
        printf("Time to do all computation and updating %f\n", te-ts);
        	
        		
        //	for each agent
        //		do cohesion, alignment, and seperation
        //		update new heading
        // 	
        // 	for each agent
        //		update the agent location
        //		check their position within boundaries, fix it with mod	
        //		update old heading by setting it = to new heading
        //		write position of agent to file
        //
        //	(if it's not the last step)
        //	write -2 to file
        
        
        //
        // write -1 to file
        
        
        
        create_window(WINDOWSIZE, WINDOWSIZE, "Test");
      //  run_file(filename);
      run_sim(agent_lists_at_timesteps, num_steps, num_agents);
        
        
        
        
        
        
        
        
        
        
        return 0;
        
}
Example #9
0
int main(int argc, char *argv[])
{

  if(argc != 5)
  {
    fprintf(stdout, "Usage: %s npoints npebs time_finish nthreads \n",argv[0]);
    return 0;
  }

  /* grab the arguments and setup some vars */
  int     npoints   = atoi(argv[1]);
  int     npebs     = atoi(argv[2]);
  double  end_time  = (double)atof(argv[3]);
  int     nthreads  = atoi(argv[4]);
  int 	  narea	    = npoints * npoints;

  /* check input params for resitrictions */
  if ( npoints % nthreads != 0 )
  {
    fprintf(stderr, "BONK! npoints must be evenly divisible by nthreads\n Try again!");
    return 0;
  }

  /* get the program directory */
  set_wrkdir(argv[0]);
  /* main simulation arrays */
  double *u_i0, *u_i1;
  double *u_cpu, *pebs;

  /* u_err is used when calculating the
   * error between one version of the code
   * and another. */
  double *u_err;

  /* h is the size of each grid cell */
  double h;
  /* used for error analysis */
  double avgerr;

  /* used for time analysis */
  double elapsed_cpu;
  struct timeval cpu_start, cpu_end;

  /* allocate arrays */
  u_i0 = (double*)malloc(sizeof(double) * narea);
  u_i1 = (double*)malloc(sizeof(double) * narea);
  pebs = (double*)malloc(sizeof(double) * narea);

  u_cpu = (double*)malloc(sizeof(double) * narea);

  start_lake_log("lake.log");

  lake_log("running %s with (%d x %d) grid, until %f, with %d threads\n", argv[0], npoints, npoints, end_time, nthreads);

  /* initialize the simulation */
  h = (XMAX - XMIN)/npoints;

  lake_log("grid step size is %f\n",h);

#ifdef __DEBUG
  lake_log("initializing pebbles\n");
#endif

  init_pebbles(pebs, npebs, npoints);

#ifdef __DEBUG
  lake_log("initializing u0, u1\n");
#endif

  init(u_i0, pebs, npoints);
  init(u_i1, pebs, npoints);

  /* print the initial configuration */
#ifdef __DEBUG
  lake_log("printing initial configuration file\n");
#endif

  print_heatmap("lake_i.dat", u_i0, npoints, h);

  /* time, run the simulation */
#ifdef __DEBUG
  lake_log("beginning simulation\n");
#endif

  gettimeofday(&cpu_start, NULL);
  run_sim(u_cpu, u_i0, u_i1, pebs, npoints, h, end_time, nthreads);
  gettimeofday(&cpu_end, NULL);

  elapsed_cpu = ((cpu_end.tv_sec + cpu_end.tv_usec * 1e-6)-(
                  cpu_start.tv_sec + cpu_start.tv_usec * 1e-6));
  lake_log("\nSimulation took %f seconds\n", elapsed_cpu);
  printf("\nSimulation took %f seconds\n", elapsed_cpu);
  /* print the final configuration */
#ifdef __DEBUG
  lake_log("printing final configuration file\n");
#endif

  print_heatmap("lake_f.dat", u_cpu, npoints, h);

#ifdef __DEBUG
  lake_log("freeing memory\n");
#endif

  /* free memory */
  free(u_i0);
  free(u_i1);
  free(pebs);
  free(u_cpu);

  stop_lake_log();
  return 1;
}
Example #10
0
/*------------------------------------------------------------------
Main driver for the simulator
------------------------------------------------------------------*/
int main( int argc, char **argv ){
    double *hz, *hhxh;     /* hamiltonian components */
    double complex *psi;   /* State vector */
    params_t par;
    uint64_t i, *largest, j, samples, maxIdx, ccount;
    struct timeval tend, tbegin;
    double delta;
    double tempV, maxV;
    
    //gettimeofday( &tbegin, NULL );
    
    /* - - - - - - - - - - - Parse configuration file - - - - - - - - - - -*/
    //if( argc < 3 ){
    if( argc < 4 ){
        fprintf( stderr, "Need a json configuration file or json string. Terminating...\n" );
        return 1;
    }

    parse_file( argv[1][1], argv[2], &par );
    samples = atoi( argv[3] );
    
    par.dim = 1 << par.nQ;
    
    hz   = (double *)calloc( (par.dim),sizeof(double) );
    hhxh = (double *)calloc( (par.dim),sizeof(double) );
    psi  = (double complex *)malloc( (par.dim)*sizeof(double complex) );
    
    /* - - - - - - Compute the Hamiltonian for the simulation - - - - - - -*/
    build_h( &par, hz, hhxh );
    free( par.al ); free( par.be ); free( par.de );

    ccount = 0UL;
    for( i = 0; i < samples; ++i ){
        /* - - - - - - Compute the state vector for the simulation - - - - - - */
        init_psi( &par, psi );
        
        /* - - - - - - - - - - - - Run the Simulation - - - - - - - - - - - - -*/
        run_sim( &par, hz, hhxh, psi );

        /* - - - - - - - - - - - - - Check results - - - - - - - - - - - - - - */
        maxV = 0.0;
        for( j = 0UL; j < par.dim; ++j ){
            tempV = cabs( psi[j]*psi[j] );
            if( tempV > maxV ){
                maxV = tempV;
                maxIdx = j;
            }
        }
        ccount += ( maxIdx == par.res ) ? 1UL : 0UL;
    }
    printf( "%f\n", ccount/(double)samples );

    /* - - - - - - - - - - - - - Check results - - - - - - - - - - - - - - */
    /*
    largest = (uint64_t *)calloc( par.L, sizeof(uint64_t) );
    findLargest( par.dim, par.L, psi, largest );
    for( i = par.L; i --> 0; ){ //remember that i is unsigned
        //printf( "|psi[%d]| = %.8f\n",
        printf( "%d %.8f\n",
            largest[i],
            cabs( psi[largest[i]]*psi[largest[i]] ) );
    }
    */
    //statm_t res;
    //read_off_memory_status( &res );
    
    /* - - - - - - - - - - - Clean up and output - - - - - - - - - - - - - */
    //free( largest );
    free( psi );
    free( hz );
    free( hhxh );
    
    //gettimeofday( &tend, NULL );
    //delta = ((tend.tv_sec - tbegin.tv_sec)*1000000u + tend.tv_usec - tbegin.tv_usec)/1.e6;
    //printf( "Total time: %f s\n", delta );
    //printf( "Memory used: %ld kB\n", res.resident );
    
    return 0;
}