EXPORT DEBUG_PARAMS *default_debug( const DEBUG_MODE dbmode) { int i; if (debug_output == NULL) debug_output = stdout; num_of_debug_names = 0; debug_input = stdin; for(i=0; i<MAX_TRACE; ++i) /* Create Circular List: */ { (void) strcpy(ftrace[i].fname,NOTHING); ftrace[i].prev = ftrace+i-1; ftrace[i].next = ftrace+i+1; } head = ftrace[0].prev = ftrace+MAX_TRACE-1; ftrace[MAX_TRACE-1].next = ftrace; (void) strcpy(head->fname,NOTHING); db_mode = SOME; remember = NULL; debug_output = stdout; num_of_debug_names = 0; return debug_params(&DbParams); } /*end default_debug*/
void cliente(int mi_serv_rank, t_params params) { MPI_Status status; int i; int cant_ops = INSTR_POR_SECCION_CRITICA; double mseg_por_op = (double) params.mseg_seccion_critica / cant_ops; debug_params(¶ms); while(params.cant_iteraciones-- > 0) { debug("\tComputando de todo un poco ..."); computar(params.mseg_computo_previo); debug("\t¡Necesito mutex!"); //fprintf(stderr, "SOY %d PIDO MUTEX\n", mi_serv_rank/2); MPI_Send(NULL, 0, MPI_INT, mi_serv_rank, TAG_PEDIDO, COMM_WORLD); //debug("\tEsperando respuesta de mi servidor"); MPI_Recv(NULL, 0, MPI_INT, mi_serv_rank, TAG_OTORGADO, COMM_WORLD, &status); //fprintf(stderr, "SOY %d ME FUE OTORGADO\n", mi_serv_rank/2); debug("\tEntrando en sección crítica"); for(i = 0; i < cant_ops; ++i) { /* `Ejecutamos' una instrucción crítica. */ fprintf(stderr, "%c", mi_char); /* Si fue la última mandamos un \n a stderr. */ if(cant_ops == i + 1) { fprintf(stderr, "\n"); if(mseg_por_op < MSEG_MIN_TRAS_NEWLINE) { /* Cuando el delay artificial es cero (o casi cero) inyectamos un épsilon de demora (sólo tras el \n) para reducir el riesgo de que, al mergear stderrs de muchos procesos, mpiexec muestre el primer char del siguiente proceso antes que nuestro \n. */ computar((double)MSEG_MIN_TRAS_NEWLINE - mseg_por_op); } } computar(mseg_por_op); } //debug("\tSaliendo de sección crítica"); MPI_Send(NULL, 0, MPI_INT, mi_serv_rank, TAG_LIBERO, COMM_WORLD); } debug("\tAvisandole a mi servidor que voy a terminar"); MPI_Ssend(NULL, 0, MPI_INT, mi_serv_rank, TAG_TERMINE, COMM_WORLD); }
EXPORT DEBUG_PARAMS *init_debug( const DEBUG_MODE dbmode) { int i; char s[Gets_BUF_SIZE]; #if defined(DEB_FILE) char filename[15]; #endif /* defined(DEB_FILE) */ int status; char *string; if (debug_output == NULL) debug_output = stdout; if (dbmode != PROMPT_FOR_DEBUG) { db_mode = dbmode; return debug_params(&DbParams); } db_mode = NONE; num_of_debug_names = 0; debug_input = stdin; for(i=0; i<MAX_TRACE; ++i) /* Create Circular List: */ { (void) strcpy(ftrace[i].fname,NOTHING); ftrace[i].prev = ftrace+i-1; ftrace[i].next = ftrace+i+1; } head = ftrace[0].prev = ftrace+MAX_TRACE-1; ftrace[MAX_TRACE-1].next = ftrace; (void) strcpy(head->fname,NOTHING); screen("Type debug to Turn On Debugging: "); (void) Gets(s); if (s[0] == 'd') { db_mode = SOME; remember = NULL; #if defined(DEB_FILE) /* Look for a Filename */ screen("Enter Optional Debug Input Filename: "); (void) Gets(s); if (sscanf(s,"%s",filename) == 1) { if (strcmp(filename,REMEMBER_FILENAME) != 0) remember = fopen(REMEMBER_FILENAME,"w"); if ((debug_input = fopen(filename,"r")) == NULL) { screen("NO DEBUG FILE CALLED: %s\n",filename); debug_input = stdin; if (remember == NULL) remember = fopen(REMEMBER_FILENAME,"w"); } } if (debug_input == stdin) remember = fopen(REMEMBER_FILENAME,"w"); #endif /* defined(DEB_FILE) */ screen("Specify Debugging Destination, screen or file: "); (void) Gets(s); debug_output = (s[0] == 's') ? stderr : stdout; screen("List Functions to Debug - or all - end ends list\n" "Names following all will not be debugged - end ends\n"); get_names: for(i=0; ;++i) { screen("\t: "); status = fscanf(debug_input,"%s",s); (void) printf("%s\n",s); (void) strncpy(debug_names[i],s,MAX_CHARS);/* Read next Name */ if (remember != NULL) /* Put in Remember */ (void) fprintf(remember,"%s\n",debug_names[i]); if (strcmp(debug_names[i],"all")==0) { db_mode = ALL; goto get_names; /* Restart Loop */ } if (strcmp(debug_names[i],"end")==0) break; if (((int) strlen(debug_names[i])) >= MAX_CHARS) { debug_names[i][MAX_CHARS] = '\0'; } } num_of_debug_names = i; /* Remove any residual whitespace */ string = fgets(s,Gets_BUF_SIZE-2,debug_input); if (remember != NULL) (void) fclose(remember); } else { screen("Type 't' to obtain traceback of debug lines upon "); screen("error termination: "); if (db_mode == NONE) { (void) Gets(s); if (s[0] == 't') db_mode = TRACE_ONLY; } else screen("\n"); } return debug_params(&DbParams); } /*end init_debug*/