int main (int argc, char *argv[]){ FILE *f = NULL; Maze *pmaze = NULL; Point *ppoint = NULL; Stack *pila = NULL; /*Pila donde guardaremos el camino*/ f = fopen(argv[1], "r"); /*Abrimos el archivo en escritura para no modificar su contenido*/ if(!f){ printf("Error de apertura de fichero\n"); return -1; } pmaze = maze_ini(); if(!pmaze){ printf("Error reserva pmaze\n"); fclose(f); return -1; } if(!maze_read(f, pmaze)){ /*Leemos el archivo para guardar el laberinto*/ fclose(f); printf("Error lectura maze\n"); maze_free(pmaze); return -1; } fclose(f); ppoint = maze_getInput(pmaze); /*Conseguimos el input de nuestro laberinto*/ if(!ppoint){ printf("Error ppoint input\n"); maze_free(pmaze); return -1; } pila = Recorrer(pmaze, ppoint); if (!pila){ /*Si la pila esta vacía es porque no ha encontrado camino o ha ocurrido algún error*/ printf("No es posible encontrar un camino\n"); } else{ printf("Es posible encontrar un camino\n"); stack_print(stdout, pila); } stack_free(pila); maze_free(pmaze); return 0; }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); maze_t* mazePtr = maze_alloc(); assert(mazePtr); long numPathToRoute = maze_read(mazePtr, global_inputFile); router_t* routerPtr = router_alloc(global_params[PARAM_XCOST], global_params[PARAM_YCOST], global_params[PARAM_ZCOST], global_params[PARAM_BENDCOST]); assert(routerPtr); list_t* pathVectorListPtr = list_alloc(NULL); assert(pathVectorListPtr); /* * Run transactions */ router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr}; TIMER_T startTime; TIMER_READ(startTime); GOTO_SIM(); #ifdef OTM #pragma omp parallel { router_solve((void *)&routerArg); } #else thread_start(router_solve, (void*)&routerArg); #endif GOTO_REAL(); TIMER_T stopTime; TIMER_READ(stopTime); long numPathRouted = 0; list_iter_t it; list_iter_reset(&it, pathVectorListPtr); while (list_iter_hasNext(&it, pathVectorListPtr)) { vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it, pathVectorListPtr); numPathRouted += vector_getSize(pathVectorPtr); } printf("Paths routed = %li\n", numPathRouted); printf("Elapsed time = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution and clean up */ assert(numPathRouted <= numPathToRoute); bool_t status = maze_checkPaths(mazePtr, pathVectorListPtr, global_doPrint); assert(status == TRUE); puts("Verification passed."); maze_free(mazePtr); router_free(routerPtr); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); maze_t* mazePtr = maze_alloc(); assert(mazePtr); long numPathToRoute = maze_read(mazePtr, global_inputFile); router_t* routerPtr = router_alloc(global_params[PARAM_XCOST], global_params[PARAM_YCOST], global_params[PARAM_ZCOST], global_params[PARAM_BENDCOST]); assert(routerPtr); list_t* pathVectorListPtr = list_alloc(NULL); assert(pathVectorListPtr); /* * Run transactions */ router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr}; // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using // wallclock time, we want to be sure we read time inside the // simulator, or else we report native cycles spent on the benchmark // instead of simulator cycles. GOTO_SIM(); TIMER_T startTime; TIMER_READ(startTime); #ifdef OTM #pragma omp parallel { router_solve((void *)&routerArg); } #else thread_start(router_solve, (void*)&routerArg); #endif TIMER_T stopTime; TIMER_READ(stopTime); // NB: As above, timer reads must be done inside of the simulated region // for PTLSim/ASF GOTO_REAL(); long numPathRouted = 0; list_iter_t it; list_iter_reset(&it, pathVectorListPtr); while (list_iter_hasNext(&it, pathVectorListPtr)) { vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it, pathVectorListPtr); numPathRouted += vector_getSize(pathVectorPtr); } printf("Paths routed = %li\n", numPathRouted); printf("Elapsed time = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution and clean up */ assert(numPathRouted <= numPathToRoute); bool status = maze_checkPaths(mazePtr, pathVectorListPtr, global_doPrint); assert(status); puts("Verification passed."); maze_free(mazePtr); router_free(routerPtr); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }