int AUTO(AutoData *Data) { struct timeval *time0,*time1; integer icp[NPARX2]; doublereal par[NPARX2], thl[NPARX]; iap_type *iap; rap_type *rap; doublereal *thu; integer *iuz; doublereal *vuz; function_list list; integer i, j, k; // Initialize structures and constants gData = Data; iap = &(Data->iap); rap = &(Data->rap); Data->sp_len = Data->num_sp + (1 + floor(iap->nmx/iap->npr)); Data->sp_inc = 5; #ifdef USAGE struct rusage *init_usage,*total_usage; usage_start(&init_usage); usage_start(&total_usage); #endif #ifdef FLOATING_POINT_TRAP trapfpe(); #endif #ifdef PTHREADS global_conpar_type = CONPAR_PTHREADS; global_setubv_type = SETUBV_PTHREADS; global_reduce_type = REDUCE_PTHREADS; #endif fp9 = fopen("fort.9","w"); if(fp9 == NULL) { fprintf(stderr,"Error: Could not open fort.9\n"); exit(1); } /* Initialization : */ iap->mynode = mynode(); iap->numnodes = numnodes(); if (iap->numnodes > 1) { iap->parallel_flag = 1; } else { iap->parallel_flag = 0; } /* NOTE: thu is allocated inside this function, and the pointer is passed back. I know this is ugly, but this function does a bit of work to get thu setup correctly, as well as figuring out the size the array should be. What really should happen is to have one function which reads fort.2 and another fuction which initializes the array. That way the allocation could happen between the two calls. */ init0(iap, rap, par, icp, thl, &thu, &iuz, &vuz); /* Find restart label and determine type of restart point. */ if (iap->irs > 0) { logical found = FALSE_; findlb(iap, rap, iap->irs, &(iap->nfpr), &found); if (! found) { if (iap->mynode == 0) { fprintf(stderr,"\nRestart label %4ld not found\n",iap->irs); } exit(0); } } set_function_pointers(*iap,&list); init1(iap, rap, icp, par); chdim(iap); /* Create the allocations for the global structures used in autlib3.c and autlib5.c. These are purely an efficiency thing. The allocation and deallocation of these scratch areas takes up a nontrivial amount of time if done directly in the wrapper functions in autlib3.c*/ allocate_global_memory(*iap); /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ /* One-parameter continuations */ /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ #ifdef USAGE usage_end(init_usage,"main initialization"); #endif if (Data->print_input) PrintInput(Data, par, icp); // Initialize output variables if(list.type==AUTOAE) Data->u = DMATRIX(iap->nmx, iap->ndim); else { // Solution measures Data->usm = (doublereal ***)MALLOC((2+(int)(log2(Data->nsm)))*sizeof(doublereal **)); Data->usm[0] = DMATRIX(iap->nmx, iap->ndim); // MAX Data->usm[1] = DMATRIX(iap->nmx, iap->ndim); // MIN for (i=0; i<(int)(log2(Data->nsm)); i++) Data->usm[2+i] = DMATRIX(iap->nmx, iap->ndim); // Jacobian of flow if (Data->sjac) { Data->c0 = DMATRIX_3D(iap->nmx, iap->ndim, iap->ndim); Data->c1 = DMATRIX_3D(iap->nmx, iap->ndim, iap->ndim); } // Jacobian of flow along cycles (temporary storage) if (Data->sflow) { Data->a1 = DMATRIX_3D(iap->ntst, iap->ndim, iap->ndim); Data->a2 = DMATRIX_3D(iap->ntst, iap->ndim, iap->ndim); } } Data->par = DMATRIX(iap->nmx, iap->nicp); if (iap->isp >= 1) { Data->ev = DCMATRIX(iap->nmx, iap->ndim); for (i=0; i<iap->nmx; i++) { for (j=0; j<iap->ndim; j++) { Data->ev[i][j].r = NAN; // This is a flag for bad floquet multipliers Data->ev[i][j].i = NAN; } } } Data->num_u = 0; if (Data->sp == NULL) Data->num_sp = 0; Data->sp = (AutoSPData *)REALLOC(Data->sp, (Data->sp_len)*sizeof(AutoSPData)); for (i=Data->num_sp; i<Data->sp_len; i++) { Data->sp[i].u = NULL; Data->sp[i].icp = NULL; Data->sp[i].ups = NULL; Data->sp[i].udotps = NULL; Data->sp[i].rldot = NULL; Data->sp[i].a1 = NULL; Data->sp[i].a2 = NULL; } if(list.type==AUTOAE) autoae(iap, rap, par, icp, list.aelist.funi, list.aelist.stpnt, list.aelist.pvli, thl, thu, iuz, vuz); if(list.type==AUTOBV) autobv(iap, rap, par, icp, list.bvlist.funi, list.bvlist.bcni, list.bvlist.icni, list.bvlist.stpnt, list.bvlist.pvli, thl, thu, iuz, vuz); // Testing output if (Data->print_output) PrintOutput(Data); #ifdef USAGE usage_end(total_usage,"total"); #endif //time_end(time0,"Total Time ",fp9); fprintf(fp9,"----------------------------------------------"); fprintf(fp9,"----------------------------------------------\n"); //time_end(time1,"",stdout); //} FREE(thu); FREE(iuz); FREE(vuz); fclose(fp9); // Clean up special solution points that were allocated and not used Data->sp = (AutoSPData *)REALLOC(Data->sp, (Data->num_sp)*sizeof(AutoSPData)); assert(Data->sp); Data->sp_len = Data->num_sp; return 1; }
int go_go_auto() /* this is the entry at this point, xAuto has been set */ { doublereal time0, time1; integer icp[NPARX2]; doublereal par[NPARX2], thl[NPARX]; doublereal *thu; integer iuz[100]; doublereal vuz[100]; iap_type iap; rap_type rap; function_list list; int irs=xAuto.irs; if(irs>0){ fp3 = fopen(fort3,"r"); } else { fp3 = fopen(fort3,"w+"); } fp7 = fopen(fort7,"w"); fp9 = fopen(fort9,"w"); /* Initialization : */ iap.mynode = mynode(); iap.numnodes = numnodes(); if (iap.numnodes > 1) { iap.parallel_flag = 1; } else { iap.parallel_flag = 0; } /* here is the feeder code from xAuto structure */ init(&iap, &rap, par, icp, thl, &thu, iuz, vuz); /* Find restart label and determine type of restart point. */ if (iap.irs > 0) { logical found = FALSE_; findlb(&iap, &rap, iap.irs, &(iap.nfpr), &found); if (! found) { if (iap.mynode == 0) { fprintf(stderr,"\nRestart label %4ld not found\n",iap.irs); } return(0);/* bad retrun */ } } /* dump_params(iap,rap,icp,thl); */ /* this is good for debugging and writes all the auto parameters */ set_function_pointers(iap,&list); init1(&iap, &rap, icp, par); chdim(&iap); /* Create the allocations for the global structures used in autlib3.c and autlib5.c. There are purely an efficiency thing. The allocation and deallocation of these scratch areas takes up a nontrivial amount of time if done directly in the wrapper functions in autlib3.c*/ allocate_global_memory(iap); /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ /* One-parameter continuations */ /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ if(list.type==AUTOAE) autoae(&iap, &rap, par, icp, list.aelist.funi, list.aelist.stpnt, list.aelist.pvli, thl, thu, iuz, vuz); if(list.type==AUTOBV) autobv(&iap, &rap, par, icp, list.bvlist.funi, list.bvlist.bcni, list.bvlist.icni, list.bvlist.stpnt, list.bvlist.pvli, thl, thu, iuz, vuz); free(thu); /* free(iuz); free(vuz); */ fclose(fp3); fclose(fp7); fclose(fp9); return 1; /* normal return */ }
int main(int argc, char *argv[]) { int r; char *data_file = NULL; char *save_file = NULL; int screen_width = DEFAULT_SCREEN_WIDTH; int screen_height = DEFAULT_SCREEN_HEIGHT; int fullscreen = 0; int game_map = 1; int map_generator = 0; int preserve_map_bugs = 0; int log_level = DEFAULT_LOG_LEVEL; int opt; while (1) { opt = getopt(argc, argv, "d:fg:hl:m:pr:t:"); if (opt < 0) break; switch (opt) { case 'd': { int d = atoi(optarg); if (d >= 0 && d < LOG_LEVEL_MAX) { log_level = d; } } break; case 'f': fullscreen = 1; break; case 'g': data_file = malloc(strlen(optarg)+1); if (data_file == NULL) exit(EXIT_FAILURE); strcpy(data_file, optarg); break; case 'h': fprintf(stdout, HELP, argv[0]); exit(EXIT_SUCCESS); break; case 'l': save_file = malloc(strlen(optarg)+1); if (save_file == NULL) exit(EXIT_FAILURE); strcpy(save_file, optarg); break; case 'm': game_map = atoi(optarg); break; case 'p': preserve_map_bugs = 1; break; case 'r': { char *hstr = strchr(optarg, 'x'); if (hstr == NULL) { fprintf(stderr, USAGE, argv[0]); exit(EXIT_FAILURE); } screen_width = atoi(optarg); screen_height = atoi(hstr+1); } break; case 't': map_generator = atoi(optarg); break; default: fprintf(stderr, USAGE, argv[0]); exit(EXIT_FAILURE); break; } } /* Set up logging */ log_set_file(stdout); log_set_level(log_level); LOGI("main", "freeserf %s", FREESERF_VERSION); r = load_data_file(data_file); if (r < 0) { LOGE("main", "Could not load game data."); exit(EXIT_FAILURE); } free(data_file); gfx_data_fixup(); LOGI("main", "SDL init..."); r = sdl_init(); if (r < 0) exit(EXIT_FAILURE); /* TODO move to right place */ midi_play_track(MIDI_TRACK_0); audio_set_volume(75); /*gfx_set_palette(DATA_PALETTE_INTRO);*/ gfx_set_palette(DATA_PALETTE_GAME); LOGI("main", "SDL resolution %ix%i...", screen_width, screen_height); r = sdl_set_resolution(screen_width, screen_height, fullscreen); if (r < 0) exit(EXIT_FAILURE); game.mission_level = game_map - 1; /* set game map */ game.map_generator = map_generator; game.map_preserve_bugs = preserve_map_bugs; /* Init globals */ allocate_global_memory(); player_interface_init(); /* Initialize global lookup tables */ init_spiral_pattern(); game_init(); /* Either load a save game if specified or start a new game. */ if (save_file != NULL) { int r = game_load_save_game(save_file); if (r < 0) exit(EXIT_FAILURE); free(save_file); } else { game_load_random_map(); } /* Move viewport to initial position */ viewport_move_to_map_pos(&interface.viewport, interface.map_cursor_pos); /* Start game loop */ game_loop(); LOGI("main", "Cleaning up..."); /* Clean up */ audio_cleanup(); sdl_deinit(); gfx_unload(); return EXIT_SUCCESS; }
/** * Initializes the model */ void init_model(fixedgrid_t* G) { /* Iterators */ uint32_t i, j, k; /* Loop blocking */ uint32_t block; /* Chemistry buffer */ real_t chemBuff[NSPEC]; /* Initialize metrics */ metrics_init(&G->ppe_metrics, "PPE"); /* Allocate memory */ printf("\nAllocating memory... "); allocate_global_memory(G); printf("done.\n"); /* Initialize time frame */ /* FIXME: year is ignored */ G->tstart = day2sec(START_DOY) + hour2sec(START_HOUR) + minute2sec(START_MIN); G->tend = day2sec(END_DOY) + hour2sec(END_HOUR) + minute2sec(END_MIN); G->dt = STEP_SIZE; G->time = G->tstart; /* Pack model parameters to be collected by SPEs */ block = NROWS / G->nprocs; for(i=0; i<G->nprocs; i++) { G->threads[i].argv.arg[0].u64 = (uint32_t)(&G->conc(0, 0, 0)); G->threads[i].argv.arg[1].u64 = (uint32_t)(&G->wind_u(0, 0)); G->threads[i].argv.arg[2].u64 = (uint32_t)(&G->wind_v(0, 0)); G->threads[i].argv.arg[3].u64 = (uint32_t)(&G->diff(0, 0)); G->threads[i].argv.arg[4].dbl = G->tstart; G->threads[i].argv.arg[5].dbl = G->tend; G->threads[i].argv.arg[6].dbl = G->dt; G->threads[i].argv.arg[7].dbl = TEMP_INIT; G->threads[i].argv.arg[8].u32[0] = (i == G->nprocs - 1 ? block + NROWS - G->nprocs*block : block); //FIXME: Potential load imbalance } /* Initialize chemistry and concentration data */ printf("Loading chemistry and concentration data... "); timer_start(&G->ppe_metrics.array_init); #if DO_CHEMISTRY == 1 saprc99_Initialize(chemBuff); for(k=0; k<NSPEC; k++) { for(i=0; i<NROWS; i++) { for(j=0; j<NCOLS; j++) { G->conc(k, i, j) = chemBuff[k]; } } } #else for(i=0; i<NROWS; i++) { for(j=0; j<NCOLS; j++) { G->conc(ind_O3, i, j) = O3_INIT; } } #endif timer_stop(&G->ppe_metrics.array_init); printf("done.\n"); /* Initialize wind field */ printf("Loading wind field data... "); timer_start(&G->ppe_metrics.array_init); for(i=0; i<NROWS; i++) { for(j=0; j<NCOLS; j++) { G->wind_u(i, j) = WIND_U_INIT; G->wind_v(i, j) = WIND_V_INIT; } } timer_stop(&G->ppe_metrics.array_init); printf("done.\n"); /* Initialize diffusion field */ printf("Loading diffusion field data... "); timer_start(&G->ppe_metrics.array_init); for(i=0; i<NROWS; i++) { for(j=0; j<NCOLS; j++) { G->diff(i, j) = DIFF_INIT; } } timer_stop(&G->ppe_metrics.array_init); printf("done.\n"); }