void allocate_village( struct Village **capital, struct Village *back, struct Village *next, int level, long vid) { int i, population, personnel; struct Village *current, *inext; struct Patient *patient; if (level == 0) *capital = NULL; else { personnel = (int) pow(2, level); population = personnel * sim_population_ratio; /* Allocate Village */ *capital = (struct Village *) malloc(sizeof(struct Village)); /* Initialize Village */ (*capital)->back = back; (*capital)->next = next; (*capital)->level = level; (*capital)->id = vid; (*capital)->seed = vid * (IQ + sim_seed); (*capital)->population = NULL; for(i=0;i<population;i++) { patient = (struct Patient *)malloc(sizeof(struct Patient)); patient->id = sim_pid++; patient->seed = (*capital)->seed; // changes seed for capital: my_rand(&((*capital)->seed)); patient->hosps_visited = 0; patient->time = 0; patient->time_left = 0; patient->home_village = *capital; addList(&((*capital)->population), patient); } /* Initialize Hospital */ (*capital)->hosp.personnel = personnel; (*capital)->hosp.free_personnel = personnel; (*capital)->hosp.assess = NULL; (*capital)->hosp.waiting = NULL; (*capital)->hosp.inside = NULL; (*capital)->hosp.realloc = NULL; omp_init_lock(&(*capital)->hosp.realloc_lock); //printf("In mutex:%" PRIu64 "\n", (*capital)->hosp.mutex); (*capital)->hosp.mutex = hpx_lco_sema_new(1); //printf("Out mutex:%" PRIu64 "\n", (*capital)->hosp.mutex); // Create Cities (lower level) inext = NULL; for (i = sim_cities; i>0; i--) { allocate_village(¤t, *capital, inext, level-1, (vid * (long) sim_cities)+ (long) i); inext = current; } (*capital)->forward = current; } }
static int _health_main_action(void *args, size_t size) { char *ptr = (char *)args; struct Village *top; hpx_time_t start; printf("initial top = %p, %u\n", top, top); read_input_data(ptr); allocate_village(&top, ((void *)0), ((void *)0), sim_level, 0);; printf("\ninitial top = %p, %u\n", top, top); start = hpx_time_now(); sim_village_main_hpx(top);; printf("HPX-5 health took: %.7f (s)\n", hpx_time_elapsed_ms(start)/1e3); check_village(top); hpx_exit(HPX_SUCCESS); }
int main(int argc, char *argv[]) { struct Village *top; char bots_arg_file[255]="./input/small.input"; if( argc < 1 ) { printf("./omp <input file>\n"); return 0; } else strcpy(bots_arg_file, argv[1] ); read_input_data(bots_arg_file); allocate_village(&top, ((void *)0), ((void *)0), sim_level, 0);; sim_village_main_par(top);; check_village(top); return 0; }
int main(int argc, char** argv) { const char* fn = "input/health/test.input"; if(argc > 1) fn = argv[1]; std::stringstream ss; ss << "Health with input file \"" << fn << "\""; struct Village *top; read_input_data(fn); inncabs::run_all( [&](const inncabs::launch l) { sim_village_main_par(l, top); return 1; }, [&](int result) { return check_village(top); }, ss.str(), [&] { allocate_village(&top, NULL, NULL, sim_level, 0); } ); return 0; }