int main( int argc, char *argv[] ) { int c; dumpheap(); if( argc < 2 ) { printf( "Usage: testpp filename\n" ); exit( 1 ); } if( argv[2] != NULL ) { PreProcChar = argv[2][0]; } if( PP_Init( argv[1], PPFLAG_EMIT_LINE, NULL ) != 0 ) { printf( "Unable to open '%s'\n", argv[1] ); exit( 1 ); } for( ;; ) { c = PP_Char(); if( c == EOF ) break; putchar( c ); } dumpheap(); PP_Fini(); dumpheap(); return( 0 ); }
PyObject * PP_Load_Attribute(const char *modname, const char *attrname) { PyObject *module; /* fetch "module.attr" */ modname = PP_Init(modname); /* use before PyEval_CallObject */ module = PP_Load_Module(modname); /* not incref'd, may reload */ if (module == NULL) return NULL; return PyObject_GetAttrString(module, attrname); /* func, class, var,.. */ } /* caller must xdecref */
int main( int argc, char *argv[] ) { if( argc < 2 ) { cprintf( "Usage: mkmk filename\r\n" ); exit( 1 ); } if( argv[2] != NULL ) { PreProcChar = argv[2][0]; } if( PP_Init( argv[1], PPFLAG_DEPENDENCIES, NULL ) != 0 ) { cprintf( "Unable to open '%s'\r\n", argv[1] ); exit( 1 ); } // call PP_Define here to predefine any desired macros PP_Dependency_List( MkMkDependency ); PP_Fini(); return( 0 ); }
PyObject * /* returns module object named modname */ PP_Load_Module(const char *modname) /* modname can be "package.module" form */ { /* reload just resets C extension mods */ /* * 4 cases: * - module "__main__" has no file, and not prebuilt: fetch or make * - dummy modules have no files: don't try to reload them * - reload=on and already loaded (on sys.modules): "reload()" before use * - not loaded yet, or loaded but reload=off: "import" to fetch or load */ PyObject *module, *sysmods; modname = PP_Init(modname); /* default to __main__ */ if (strcmp(modname, "__main__") == 0) /* main: no file */ return PyImport_AddModule(modname); /* not increfd */ sysmods = PyImport_GetModuleDict(); /* get sys.modules dict */ module = PyDict_GetItemString(sysmods, modname); /* mod in sys.modules? */ if (module != NULL && /* dummy: no file */ PyModule_Check(module) && PyDict_GetItemString(PyModule_GetDict(module), "__dummy__")) { return module; /* not increfd */ } else if (PP_RELOAD && module != NULL && PyModule_Check(module)) { module = PyImport_ReloadModule(module); /* reload file,run code */ Py_XDECREF(module); /* still on sys.modules */ return module; /* not increfd */ } else { module = PyImport_ImportModule(modname); /* fetch or load module */ Py_XDECREF(module); /* still on sys.modules */ return module; /* not increfd */ } }
int main(int argc, char *argv[]) { int rc, i, done, do_put_answer, all_ranks_put, work_unit_size, time_for_fake_work; int my_world_rank, nranks, num_work_units, num_answers, provided; int work_type, work_handle[HANDLE_SIZE], work_len, answer_rank; int num_handled_by_me; int max_message_size = 50; int req_types[4]; int num_types = 3; int type_vect[4] = { WORK, ANSWER }; int num_types_in_req; int final_rc; char thread_type[32]; char *work_unit_buf; char *findbuf = (char *)malloc(75); char *getbuf = (char *)malloc(75); char *ansbuf = (char *)malloc(75); double temptime; double start_job_time, end_put_time, start_work_time, end_work_time; double total_work_time, total_loop_time; double total_reserve_time, total_get_time; double total_put_time = 0.0; do_put_answer = DEFAULT_DO_PUT_ANSWER; /* will halt by exhaustion */ all_ranks_put = DEFAULT_ALL_RANKS_PUT; work_unit_size = DEFAULT_WORK_UNIT_SIZE; num_work_units = DEFAULT_NUM_WORK_UNITS; time_for_fake_work = DEFAULT_NSECS_FAKE_WORK; total_work_time = 0.0; total_loop_time = 0.0; total_reserve_time = 0.0; total_get_time = 0.0; for (i=1; i < argc; i++) { if (strcmp(argv[i],"-dpa") == 0) do_put_answer = 1; else if (strcmp(argv[i], "-alt") == 0) all_ranks_put = 1; else if (strcmp(argv[i],"-n") == 0) num_work_units = atoi(argv[++i]); else if (strcmp(argv[i],"-s") == 0) work_unit_size = atoi(argv[++i]); else if (strcmp(argv[i],"-t") == 0) time_for_fake_work = atoi(argv[++i]); else { printf("unrecognized cmd-line arg at %d :%s:\n", my_world_rank, i, argv[i]); exit(-1); } } rc = MPI_Init_thread(NULL,NULL,MPI_THREAD_MULTIPLE,&provided); if (rc != MPI_SUCCESS) { printf("MPI_Init_thread failed with rc=%d\n", rc); exit(-1); } MPI_Comm_size(MPI_COMM_WORLD,&nranks); MPI_Comm_rank(MPI_COMM_WORLD,&my_world_rank); num_handled_by_me = 0; work_unit_buf = (char *)malloc(work_unit_size); rc = PP_Init(SRVR_MAX_MALLOC_AMT,num_types,type_vect); if (rc != PP_SUCCESS) { MPI_Abort(MPI_COMM_WORLD, -1); exit(-1); } // print out info chart if (my_world_rank == 0) { printf("------------------------------------------------------------------------------\n"); printf("%1s%30s%2s%23s%2s%18s%2s\n", "|", "ARGUMENTS", "|", "RETURN CODES", "|", "WORK UNITS", "|"); printf("%1s%20s%3s%7d%2s%16s%3s%4d%2s%10s%3s%5d%2s\n", "|", "do_put_answer", "=", do_put_answer, "|", "PP_FAIL", "=", PP_FAIL, "|", "WORK", "=", WORK, "|"); printf("%1s%20s%3s%7d%2s%16s%3s%4d%2s%10s%3s%5d%2s\n", "|", "all_ranks_put", "=", all_ranks_put, "|", "PP_SUCCESS", "=", PP_SUCCESS, "|", "ANSWER", "=", ANSWER, "|"); printf("%1s%20s%3s%7d%2s%16s%3s%4d%2s%20s\n", "|", "num_work_units", "=", num_work_units, "|", "PP_NO_MORE_WORK", "=", PP_NO_MORE_WORK, "|", "|"); printf("%1s%20s%3s%7d%2s%16s%3s%4d%2s%20s\n", "|", "work_unit_size", "=", work_unit_size, "|", "PP_EXHAUSTION", "=", PP_EXHAUSTION, "|", "|"); printf("%1s%20s%3s%7d%2s%25s%20s\n", "|", "time_for_fake_work", "=", time_for_fake_work, "|", "|", "|"); printf("%1s%20s%3s%7d%2s%25s%20s\n", "|", "num_ranks", "=", nranks, "|", "|", "|"); printf("------------------------------------------------------------------------------\n"); printf("***\n"); } rc = MPI_Barrier( MPI_COMM_WORLD ); start_job_time = end_work_time = MPI_Wtime(); /* dummy val until set below */ int my_put_count = 0; if (all_ranks_put == 1) { num_answers = 0; for (i = 0; i < num_work_units; i++) { memset(work_unit_buf, 'X', work_unit_size); if (work_unit_size >= 20) sprintf(work_unit_buf, "workunit:r%d:u%d", my_world_rank, i); rc = PP_Put(work_unit_buf, work_unit_size, WORK, -1, 0, work_handle); my_put_count++; printf("rank=%2d PUT rc=%d data=%s handle_key=%d:%d\n", my_world_rank, rc, work_unit_buf, work_handle[0], work_handle[1]); } total_put_time = MPI_Wtime() - start_job_time; num_work_units *= nranks; } else { if (my_world_rank == 0) { /* if master app, put work */ num_answers = 0; for (i=0; i < num_work_units; i++) { memset(work_unit_buf, 'X', work_unit_size); if (work_unit_size >= 20) sprintf(work_unit_buf,"workunit:r%d:u%d", my_world_rank, i); rc = PP_Put( work_unit_buf, work_unit_size, WORK, -1, -1, work_handle); my_put_count++; printf("rank=%2d PUT rc=%d DATA=%s handle_key=%d:%d\n", my_world_rank, rc, work_unit_buf, work_handle[0], work_handle[1]); } total_put_time = MPI_Wtime() - start_job_time; } } rc = MPI_Barrier( MPI_COMM_WORLD ); end_put_time = start_work_time = MPI_Wtime(); done = 0; while ( !done ) { if (do_put_answer) { if (my_world_rank == 0) { req_types[0] = ANSWER; req_types[1] = WORK; num_types_in_req = 2; } else { req_types[0] = WORK; num_types_in_req = 1; } } else { req_types[0] = WORK; num_types_in_req = 1; } temptime = MPI_Wtime(); memset(findbuf, ' ', max_message_size); memset(getbuf, ' ', max_message_size); memset(ansbuf, ' ', max_message_size); // if all ranks put data targeted to rank 0, rank 0 should do a "find" rather than find and reserve if (all_ranks_put) { //printf("Before find on Rank %d\n", my_world_rank); rc = PP_Find(num_types_in_req, req_types, &work_len, &work_type, work_handle); //printf("Find rc=%d\n", rc); if (rc == PP_SUCCESS) { sprintf(findbuf, "FIND: rc=%d h_key=%d:%d type=%d size=%d", rc, work_handle[0], work_handle[1], work_type, work_len); } else { sprintf(findbuf, "FIND: rc=%d", rc); } } else { rc = PP_FindAndReserve(num_types_in_req, req_types, &work_len, &work_type, work_handle); if (rc == PP_SUCCESS) { sprintf(findbuf, "FIND: rc=%d h_key=%d:%d type=%d size=%d", rc, work_handle[0], work_handle[1], work_type, work_len); } else { sprintf(findbuf, "FIND: rc=%d", rc); } } if (rc == PP_EXHAUSTION) { MPI_Barrier(MPI_COMM_WORLD); printf("rank=%2d Terminated by EXHAUSTION\n", my_world_rank); final_rc = rc; break; } else if ( rc == PP_NO_MORE_WORK ) { MPI_Barrier(MPI_COMM_WORLD); printf("rank=%2d Terminated by NO_MORE_WORK\n", my_world_rank); final_rc = rc; break; } if (work_type == WORK) { total_reserve_time += MPI_Wtime() - temptime; /* only count for work */ temptime = MPI_Wtime(); //if(my_world_rank ==1) // printf("Starting Get on rank1\n"); rc = PP_Get(work_unit_buf, work_handle); total_get_time += (MPI_Wtime() - temptime); if (rc == PP_SUCCESS) { sprintf(getbuf, "GET: rc=%d h_key=%d:%d data=%s", rc, work_handle[0], work_handle[1], work_unit_buf); } else { sprintf(getbuf, "GET: rc=%d", rc); } /* got good work, do dummy/fake work */ num_handled_by_me++; temptime = MPI_Wtime(); while (1) { for (i=0; i < 1000000; i++) ; if (((MPI_Wtime() - temptime) * 1000) > time_for_fake_work) break; } if (do_put_answer) { rc = PP_Put(NULL, 0, ANSWER, -1, -1, work_handle); sprintf(ansbuf, "PUT_ANS: rc=%d h_key=%d:%d", rc, work_handle[0], work_handle[1]); } end_work_time = MPI_Wtime(); /* chgs on each work unit */ } else if (work_type == ANSWER) { num_answers++; sprintf(getbuf, "FOUND_ANS: num_answers: %d", num_answers); if (all_ranks_put) { rc = PP_Get(work_unit_buf, work_handle); } if (num_answers >= num_work_units) { PP_Set_problem_done(); } } else { printf("rank=%2d ERROR UNEXPECTED_WORK_TYPE=%d\n", my_world_rank, work_type ); PP_Abort(-1); } printf("rank=%2d %-45s %-45s %-45s\n", my_world_rank, findbuf, getbuf, ansbuf); if (work_type == ANSWER && num_answers >= num_work_units) { printf("rank=%2d PP_Set_problem_done() has been called\n", my_world_rank); } } rc = MPI_Barrier( MPI_COMM_WORLD ); total_loop_time = MPI_Wtime() - start_work_time; float avg_work_time, avg_reserve_time, avg_get_time; avg_work_time = ((float)total_loop_time) / ((float)num_handled_by_me); int *ar_num_handled_by_rank = NULL; int *ar_final_rc = NULL; int *ar_put_counts = NULL; double *ar_total_reserve_time = NULL; double *ar_total_get_time = NULL; double *ar_total_put_time = NULL; if (my_world_rank == 0) { ar_num_handled_by_rank = (int *)malloc(nranks * sizeof(int)); ar_final_rc = (int *)malloc(nranks * sizeof(int)); ar_put_counts = (int *)malloc(nranks * sizeof(int)); ar_total_reserve_time = (double *)malloc(nranks * sizeof(double)); ar_total_get_time = (double *)malloc(nranks * sizeof(double)); ar_total_put_time = (double *)malloc(nranks * sizeof(double)); } MPI_Gather(&num_handled_by_me, 1, MPI_INT, ar_num_handled_by_rank, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Gather(&final_rc, 1, MPI_INT, ar_final_rc, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Gather(&my_put_count, 1, MPI_INT, ar_put_counts, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Gather(&total_reserve_time, 1, MPI_DOUBLE, ar_total_reserve_time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Gather(&total_get_time, 1, MPI_DOUBLE, ar_total_get_time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Gather(&total_put_time, 1, MPI_DOUBLE, ar_total_put_time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); int grand_total_work = 0; int grand_total_puts = 0; double grand_total_resv = 0; double grand_total_get = 0; double grand_total_put = 0; if (my_world_rank == 0) { printf("***\n"); printf("----Stats:----\n"); printf("%10s%15s%15s%20s%20s%20s%15s%20s%20s\n", "RANK", "NUM_PUTS", "WORK_UNITS", "TOTAL_PUT_TIME", "TOTAL_RESV_TIME", "TOTAL_GET_TIME", "FINAL_RC", "AVG_WORK_TIME", "WORK_PER_SECOND"); for (i=0; i < nranks; i++) { printf("%10d%15d%15d%20.5f%20.5f%20.5f%15d%20.5f%20.5f\n", i, ar_put_counts[i], ar_num_handled_by_rank[i], ar_total_put_time[i], ar_total_reserve_time[i], ar_total_get_time[i], ar_final_rc[i], ((double)total_loop_time / (double)ar_num_handled_by_rank[i]), (((double)ar_num_handled_by_rank[i]) / total_loop_time)); grand_total_work += ar_num_handled_by_rank[i]; grand_total_puts += ar_put_counts[i]; grand_total_resv += ar_total_reserve_time[i]; grand_total_get += ar_total_get_time[i]; grand_total_put += ar_total_put_time[i]; } printf("%10s%15s%15s%20s%20s%20s\n", "-", "-", "-", "-", "-", "-"); printf("%10s%15d%15d%20.5f%20.5f%20.5f\n", "TOTALS:", grand_total_puts, grand_total_work, grand_total_put, grand_total_resv, grand_total_get); printf("%11s%.5f\n", "TIME: ", total_loop_time); } PP_Finalize(); rc = MPI_Finalized(&i); if ( ! i) MPI_Finalize(); return 0; }
static char *WRELoadSymbols( WRHashTable **table, char *file_name, bool prompt ) { char *name; int c; unsigned flags; char *inc_path; WREGetFileStruct gf; unsigned pp_count; unsigned busy_count; char busy_str[2]; bool ret; bool ok; name = NULL; ok = (table != NULL); if( ok ) { WRESetStatusText( NULL, "", FALSE ); WRESetStatusByID( WRE_LOADINGSYMBOLS, -1 ); } if( ok ) { if( file_name == NULL || prompt ) { gf.file_name = file_name; gf.title = WRESymLoadTitle; gf.filter = WRESymSaveFilter; gf.save_ext = FALSE; name = WREGetOpenFileName( &gf ); } else { name = WREStrDup( file_name ); } ok = (name != NULL); } WRESetWaitCursor( TRUE ); if( ok ) { flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE; inc_path = NULL; ret = setjmp( SymEnv ); if( ret ) { PP_Fini(); WREDisplayErrorMsg( WRE_SYMOUTOFMEM ); ok = false; } } if( ok ) { ok = !PP_Init( name, flags, inc_path ); if( !ok ) { WREDisplayErrorMsg( WRE_NOLOADHEADERFILE ); } } if( ok ) { pp_count = 0; busy_count = 0; busy_str[1] = '\0'; do { pp_count++; c = PP_Char(); if( pp_count == MAX_PP_CHARS ) { busy_count++; busy_str[0] = WREBusyChars[busy_count % 4]; WRESetStatusText( NULL, busy_str, TRUE ); pp_count = 0; } } while( c != EOF ); if( *table == NULL ) { *table = WRInitHashTable(); } WREAddSymbols( *table ); WRMakeHashTableClean( *table ); PP_Fini(); WRESetStatusText( NULL, " ", TRUE ); } if( !ok ) { if( name != NULL ) { WRMemFree( name ); name = NULL; } } WRESetWaitCursor( FALSE ); WRESetStatusReadyText(); return( name ); }
int main( int argc, char **argv ) //******************************* { static char *fname; #ifndef __WATCOMC__ _argv = argv; _argc = argc; #endif MemInit(); if( !AsMsgInit() ) { return( EXIT_FAILURE ); } if( argc == 1 ) { Banner(); Usage(); } else if( OptionsInit( --argc, ++argv ) ) { Banner(); if( _IsOption( PRINT_HELP ) ) { Usage(); *argv = NULL; } else if( !*argv ) { AsOutMessage( stderr, AS_MSG_ERROR ); AsOutMessage( stderr, NO_FILENAME_SPECIFIED ); fputc( '\n', stderr ); } while( *argv ) { fname = MakeAsmFilename( *argv ); if( PP_Init( fname, PPFLAG_ASM_COMMENT | PPFLAG_EMIT_LINE, NULL ) != 0 ) { AsOutMessage( stderr, UNABLE_TO_OPEN, fname ); fputc( '\n', stderr ); } else { OptionsPPDefine(); SymInit(); InsInit(); DirInit(); if( ObjInit( fname ) ) { if( setjmp( AsmParse ) == 0 ) { ErrorCountsReset(); DoReport = TRUE; if( !yyparse() ) { CurrLineno--; // This is the total # of lines ObjRelocsFini(); // Must be done before ErrorReport // and other finis } else { DoReport = FALSE; } } else { // AbortParse() was invoked DoReport = FALSE; } ErrorReport(); AsLexerFini(); ObjFini(); } DirFini(); InsFini(); SymFini(); } PP_Fini(); ++argv; } } OptionsFini(); AsMsgFini(); MemFini(); return( ExitStatus ); }
char *WLoadSymbols( WRHashTable **table, char *file_name, HWND parent, bool prompt ) { char *name; int c; unsigned flags; char *inc_path; WGetFileStruct gf; bool ret; bool ok; name = NULL; ok = (table != NULL); if( ok ) { if( file_name == NULL || prompt ) { gf.file_name = file_name; gf.title = AllocRCString( W_LOADSYMTITLE ); gf.filter = AllocRCString( W_SYMFILTER ); WMassageFilter( gf.filter ); name = WGetOpenFileName( parent, &gf ); if( gf.title != NULL ) { FreeRCString( gf.title ); } if( gf.filter != NULL ) { FreeRCString( gf.filter ); } } else { name = WStrDup( file_name ); } ok = (name != NULL); } WSetWaitCursor( parent, TRUE ); if( ok ) { flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE; inc_path = NULL; ret = setjmp( SymEnv ) != 0; if( ret ) { PP_Fini(); WDisplayErrorMsg( W_SYMOUTOFMEM ); ok = false; } } if( ok ) { ok = !PP_Init( name, flags, inc_path ); if( !ok ) { WDisplayErrorMsg( W_NOOPENSYMFILE ); } } if( ok ) { do { c = PP_Char(); } while( c != EOF ); if( *table == NULL ) { *table = WRInitHashTable(); } addSymbols( *table ); WRMakeHashTableClean( *table ); PP_Fini(); } if( !ok ) { if( name != NULL ) { WRMemFree( name ); name = NULL; } } WSetWaitCursor( parent, FALSE ); return( name ); }
int main(int argc, char *argv[]) { int rc, i, j, done, num_servers, work_unit_size, am_server_flag; int num_world_ranks, num_work_units, num_answers; int work_type, work_handle[PP_HANDLE_SIZE], work_len; int num_handled_by_me, num_app_ranks, num_req_types_used; // int num_user_types, user_types[PP_MAX_USER_TYPES]; int req_types[128]; int num_user_types; int user_types[128]; char *work_unit_buf; double temptime, time_for_fake_work; double start_job_time, end_put_time, start_work_time, end_work_time; double total_work_time, total_reserve_time, total_get_time; num_servers = 1; work_unit_size = 0; /* default */ num_work_units = 4; /* default */ time_for_fake_work = 0.0; /* default */ total_work_time = 0.0; total_get_time = 0.0; total_reserve_time = 0.0; num_handled_by_me = 0; num_answers = 0; for (i=1; i < argc; i++) /* start at 1 */ { if (strcmp(argv[i],"-nservers") == 0) num_servers = atof(argv[++i]); else if (strcmp(argv[i],"-n") == 0) num_work_units = atoi(argv[++i]); else if (strcmp(argv[i],"-s") == 0) work_unit_size = atoi(argv[++i]); else if (strcmp(argv[i],"-t") == 0) time_for_fake_work = atof(argv[++i]); else { printf("unrecognized cmd-line arg at %d :%s:\n",i,argv[i]); exit(-1); } } work_unit_buf = (char *) malloc(work_unit_size); rc = MPI_Init(NULL,NULL); rc = MPI_Comm_rank(MPI_COMM_WORLD,&my_world_rank); rc = MPI_Comm_size(MPI_COMM_WORLD,&num_world_ranks); num_app_ranks = num_world_ranks - num_servers; num_user_types = num_app_ranks; for (i=0; i < num_app_ranks; i++) user_types[i] = i; if (my_world_rank >= (num_world_ranks-num_servers)) am_server_flag = 1; else am_server_flag = 0; rc = PP_Init(num_user_types,user_types,am_server_flag); // servers stay until end if (am_server_flag) { PP_Finalize(); MPI_Finalize(); exit(0); } start_job_time = MPI_Wtime(); end_work_time = MPI_Wtime(); /* dummy val until set below */ for (i=0; i < num_work_units; i++) { memset(work_unit_buf,'X',work_unit_size); if (work_unit_size >= 25) sprintf(work_unit_buf,"workunit %d by %d\n",i); rc = PP_Put( work_unit_buf, work_unit_size, my_world_rank, -1 ); // type==myrank if (rc != PP_SUCCESS) { dbgprintf( 1, "**** failed: put work_unit %d rc %d\n", i, rc ); PP_Abort(-1); } } dbgprintf(1,"all work submitted after %f secs\n",MPI_Wtime()-start_job_time); end_put_time = start_work_time = MPI_Wtime(); done = 0; while ( !done ) { num_req_types_used = 0; for (i=0,j=0; i < num_app_ranks; i++) { if ((i % 2) == 0) { if ((my_world_rank % 2) == 0) { req_types[j++] = i; // NOTE USING j num_req_types_used++; } } else { if ((my_world_rank % 2) != 0) { req_types[j++] = i; // NOTE USING j num_req_types_used++; } } } // for (i=0; i<num_req_types_used; i++) // printf("rank %d types %d\n", my_world_rank, req_types[i]); if (my_world_rank == MASTER_RANK) { req_types[num_req_types_used] = ANSWER; num_req_types_used++; } rc = PP_Reserve(num_req_types_used,req_types,&work_len,&work_type,work_handle); if ( rc == PP_EXHAUSTION ) { dbgprintf( 1, "done by exhaustion\n" ); break; } else if ( rc == PP_NO_MORE_WORK ) { // dbgprintf( 1, "done by no more work\n" ); break; } else if (rc < 0) { dbgprintf( 1, "** reserve failed, rc = %d\n", rc ); PP_Abort(-1); } else if ( work_type == ANSWER) { num_answers++; if (num_answers >= (num_app_ranks * num_work_units)) PP_Set_problem_done(); } else { temptime = MPI_Wtime(); rc = PP_Get( work_unit_buf, work_handle ); total_get_time += MPI_Wtime() - temptime; if (rc == PP_NO_MORE_WORK) { // dbgprintf( 1, "no more work on get_reserved\n" ); break; } else /* got good work */ { /* do dummy/fake work */ num_handled_by_me++; if (time_for_fake_work == 0.0) { // dbgprintf(1,"worktime 0.0\n"); } else { temptime = MPI_Wtime(); while (1) { for (i=0; i < 1000000; i++) ; if (MPI_Wtime()-temptime > time_for_fake_work) break; } // dbgprintf(1,"worktime %f\n",MPI_Wtime()-temptime); } rc = PP_Put( NULL, 0, ANSWER, MASTER_RANK ); } end_work_time = MPI_Wtime(); /* chgs on each work unit */ } // else // { // dbgprintf( 1, "** unexpected work type %d\n", work_type ); // PP_Abort( -1 ); // } } total_work_time = end_work_time - start_work_time; dbgprintf(1,"num handled by me %d\n",num_handled_by_me); // dbgprintf(1,"total work_time %f ; avg work time %f\n", // total_work_time,total_work_time/((float)num_handled_by_me)); PP_Finalize(); // printf("calling mpi_finalize\n"); MPI_Finalize(); // printf("past mpi_finalize\n"); return 0; }
static bool scanEnvVarOrFile( const char *name ) /**********************************************/ { /* * Pass nofilenames and analysis of getenv(name) into argc and argv * to doScanParams. Return view on usability of data. (true is usable.) * * Recursion is supported but circularity is rejected. */ typedef struct VarInfo { struct VarInfo *next; char *name; char **argv; /* points into buf */ char buf[1]; /* dynamic array */ } VarInfo; int argc; VarInfo *info; static VarInfo *stack = NULL; // Needed to detect recursion. size_t argvsize; size_t argbufsize; const char *optstring; size_t varlen; // size to hold name copy. bool result; // doScanParams Result. char fbuf[512]; optstring = PP_GetEnv( name ); if( optstring == NULL ) { FILE *fh; fh = fopen( name, "rt" ); if( fh == NULL ) { // RcWarning( ERR_ENV_VAR_NOT_FOUND, name ); return( true ); } fgets( fbuf, sizeof( fbuf ), fh ); fclose( fh ); optstring = fbuf; } // This used to cause stack overflow: set foo=@foo && wrc @foo. for( info = stack; info != NULL; info = info->next ) { #if defined( __UNIX__ ) if( strcmp( name, info->name ) == 0 ) { // Case-sensitive #else if( stricmp( name, info->name ) == 0 ) { // Case-insensitive #endif // RcFatalError( ERR_RCVARIABLE_RECURSIVE, name ); } } argc = ParseVariable( optstring, NULL, NULL ); // count parameters. argbufsize = strlen( optstring ) + 1 + argc; // inter-parameter spaces map to 0 argvsize = argc * sizeof( char * ); // sizeof argv[argc+1] varlen = strlen( name ) + 1; // Copy taken to detect recursion. info = malloc( sizeof( *info ) + argbufsize + argvsize + varlen ); info->next = stack; stack = info; // push info on stack info->argv = (char **)info->buf; ParseVariable( optstring, info->argv, info->buf + argvsize ); info->name = info->buf + argvsize + argbufsize; strcpy( info->name, name ); result = doScanParams( argc, info->argv ); stack = info->next; // pop stack free( info ); return( result ); } static bool doScanParams( int argc, char *argv[] ) /************************************************/ { const char *arg; int switchchar; bool contok; /* continue with main execution */ int currarg; contok = true; switchchar = _dos_switch_char(); for( currarg = 0; currarg < argc && contok; currarg++ ) { arg = argv[currarg]; if( *arg == switchchar || *arg == '-' ) { contok = ScanOptionsArg( arg + 1 ) && contok; } else if( *arg == '@' ) { contok = scanEnvVarOrFile( arg + 1 ) && contok; } else if( *arg == '?' ) { wcpp_quit( usageMsg, NULL ); // contok = false; } else { filenames = realloc( (void *)filenames, ( nofilenames + 1 ) * sizeof( char * ) ); filenames[nofilenames++] = my_strdup( arg ); } } return( contok ); } int main( int argc, char *argv[] ) { int ch; int i; int j; int rc; FILE *fo; if( argc < 2 ) { wcpp_quit( usageMsg, "No filename specified\n" ); } else if( argc == 2 ) { if( !strcmp( argv[1], "?" ) ) { wcpp_quit( usageMsg, NULL ); } } PP_IncludePathInit(); rc = EXIT_FAILURE; if( doScanParams( argc - 1, argv + 1 ) && nofilenames != 0 ) { PP_Init( '#' ); fo = stdout; if( out_filename != NULL ) { fo = fopen( out_filename, "wb" ); } rc = EXIT_SUCCESS; for( i = 0; i < nofilenames; ++i ) { if( PP_FileInit( filenames[i], flags, NULL ) != 0 ) { fprintf( stderr, "Unable to open '%s'\n", filenames[i] ); rc = EXIT_FAILURE; break; } for( j = 0; j < numdefs; j++ ) { PP_Define( defines[j] ); } for( ;; ) { ch = PP_Char(); if( ch == EOF ) break; #ifndef __UNIX__ if( ch == '\n' ) fputc( '\r', fo ); #endif fputc( ch, fo ); } PP_FileFini(); } if( fo == stdout ) { fflush( fo ); } else if( fo != NULL ) { fclose( fo ); } PP_Fini(); } if( out_filename != NULL ) { free( out_filename ); } for( i = 0; i < nofilenames; ++i ) { free( filenames[i] ); } free( (void *)filenames ); for( i = 0; i < numdefs; i++ ) { free( defines[i] ); } free( (void *)defines ); PP_IncludePathFini(); if( rc == EXIT_FAILURE && nofilenames == 0 ) { wcpp_quit( usageMsg, "No filename specified\n" ); } return( rc ); }
int main(int argc, char *argv[]) { int rc, i, done, do_put_answer, work_unit_size; int my_world_rank, nranks, num_work_units, num_answers, provided; int work_prio, work_type, work_handle[PP_HANDLE_SIZE], work_len, answer_rank; int *num_handled_by_rank, num_handled_by_me; int dbgprintf_flag = 1, use_prio_for_reserve_flag = 0; int req_types[4]; int num_types = 2; int type_vect[4] = {WORK,ANSWER}; int num_type_in_req; char thread_type[32]; char *work_unit_buf; double temptime, time_for_fake_work; double start_job_time, end_put_time, start_work_time, end_work_time; double total_work_time, total_loop_time; double total_reserve_time, total_get_time; do_put_answer = DEFAULT_DO_PUT_ANSWER; /* will halt by exhaustion after 5 secs */ work_unit_size = DEFAULT_WORK_UNIT_SIZE; num_work_units = DEFAULT_NUM_WORK_UNITS; time_for_fake_work = DEFAULT_NSECS_FAKE_WORK; total_work_time = 0.0; total_loop_time = 0.0; total_reserve_time = 0.0; total_get_time = 0.0; for (i=1; i < argc; i++) { // printf("av %s\n",argv[i]); if (strcmp(argv[i],"-a") == 0) do_put_answer = 1; else if (strcmp(argv[i],"-n") == 0) num_work_units = atoi(argv[++i]); else if (strcmp(argv[i],"-s") == 0) work_unit_size = atoi(argv[++i]); else if (strcmp(argv[i],"-t") == 0) time_for_fake_work = atof(argv[++i]); else { printf("st1: unrecognized cmd-line arg at %d :%s:\n",i,argv[i]); exit(-1); } } rc = MPI_Init_thread(NULL,NULL,MPI_THREAD_MULTIPLE,&provided); if (rc != MPI_SUCCESS) { printf("st1: MPI_Init_thread failed with rc=%d\n",rc); exit(-1); } switch (provided) { case MPI_THREAD_SINGLE: strcpy(thread_type,"MPI_THREAD_SINGLE"); break; case MPI_THREAD_FUNNELED: strcpy(thread_type,"MPI_THREAD_FUNNELED"); break; case MPI_THREAD_SERIALIZED: strcpy(thread_type,"MPI_THREAD_SERIALIZED"); break; case MPI_THREAD_MULTIPLE: strcpy(thread_type,"MPI_THREAD_MULTIPLE"); break; default: strcpy(thread_type,"UNKNOWN"); break; } printf("st1: MPI provides %s\n",thread_type); MPI_Comm_size(MPI_COMM_WORLD,&nranks); MPI_Comm_rank(MPI_COMM_WORLD,&my_world_rank); num_handled_by_me = 0; if (my_world_rank == 0) num_handled_by_rank = malloc(nranks * sizeof(int)); else num_handled_by_rank = NULL; work_unit_buf = malloc(work_unit_size); rc = PP_Init(SRVR_MAX_MALLOC_AMT,num_types,type_vect); rc = MPI_Barrier( MPI_COMM_WORLD ); start_job_time = MPI_Wtime(); end_work_time = MPI_Wtime(); /* dummy val until set below */ if ( my_world_rank == 0 ) /* if master app, put work */ { num_answers = 0; for (i=0; i < num_work_units; i++) { memset(work_unit_buf,'X',work_unit_size); if (work_unit_size >= 18) sprintf(work_unit_buf,"workunit %d",i); rc = PP_Put( work_unit_buf, work_unit_size, WORK, -1, -1, &work_handle ); // dbgprintf( 1, "put work_unit %d rc %d\n", i, rc ); } // dbgprintf(1,"st1: all work submitted after %f secs\n",MPI_Wtime()-start_job_time); printf("st1: all work submitted after %f secs\n",MPI_Wtime()-start_job_time); } rc = MPI_Barrier( MPI_COMM_WORLD ); end_put_time = start_work_time = MPI_Wtime(); done = 0; while ( !done ) { if (do_put_answer) { if (my_world_rank == 0) { req_types[0] = ANSWER; req_types[1] = WORK; num_types_in_req = 2; } else { req_types[0] = WORK; num_types_in_req = 1; } } else { num_types_in_req = 0; } // dbgprintf( 1, "st1: reserving work\n" ); temptime = MPI_Wtime(); rc = PP_FindAndReserve(num_types_in_req,req_types,&work_len, &work_type,&answer_rank,work_handle); // dbgprintf( 1, "st1: after reserve rc %d len %d type %d\n", rc, work_len, work_type ); if ( rc == PP_EXHAUSTION ) { // dbgprintf( 1, "st1: done by exhaustion\n" ); printf( "st1: done by exhaustion\n" ); break; } else if ( rc == PP_NO_MORE_WORK ) { // dbgprintf( 1, "st1: done by no more work\n" ); printf( "st1: done by no more work\n" ); break; } else if (rc < 0) { // dbgprintf( 1, "st1: ** reserve failed, rc = %d\n", rc ); printf( "st1: ** reserve failed, rc = %d\n", rc ); ADLB_Abort(-1); } else if (work_type == WORK) { total_reserve_time += MPI_Wtime() - temptime; /* only count for work */ temptime = MPI_Wtime(); rc = PP_Get( work_unit_buf, work_handle ); total_get_time += MPI_Wtime() - temptime; if (rc == PP_NO_MORE_WORK) { // dbgprintf( 1, "st1: no more work on get_reserved\n" ); printf( "st1: no more work on get_reserved\n" ); break; } else /* got good work */ { /* do dummy/fake work */ num_handled_by_me++; if (time_for_fake_work == 0.0) { // dbgprintf(1,"st1: worktime 0.0\n"); } else { temptime = MPI_Wtime(); while (1) { for (i=0; i < 1000000; i++) ; if (MPI_Wtime()-temptime > time_for_fake_work) break; } // dbgprintf(1,"st1: worktime %f\n",MPI_Wtime()-temptime); } if (do_put_answer) { rc = PP_Put( NULL, 0, ANSWER, -1, 0, handle ); } } end_work_time = MPI_Wtime(); /* chgs on each work unit */ } else if ( work_type == ANSWER) { num_answers++; // dbgprintf(1111,"GENBATCH: GOT ANSWER %d\n",num_answers); if (num_answers >= num_work_units) PP_Set_problem_done(); } else { // dbgprintf( 1, "st1: ** unexpected work type %d\n", work_type ); printf( "st1: ** unexpected work type %d\n", work_type ); PP_Abort( -1 ); } } rc = MPI_Barrier( MPI_COMM_WORLD ); // total_loop_time can be misleading since we have to wait for exhaustion // total_loop_time = MPI_Wtime() - start_work_time; // dbgprintf(1,"st1: total loop time %f\n",total_loop_time); /**** total_work_time = end_work_time - start_work_time; dbgprintf(1,"st1: num handled by me %d\n",num_handled_by_me); dbgprintf(1,"st1: last end_work_time %f\n",end_work_time); dbgprintf(1,"st1: total work_time %f ; avg work time %f\n", total_work_time,total_work_time/((float)num_handled_by_me)); dbgprintf(1,"st1: total reserve time %f ; avg reserve time %f\n", total_reserve_time,total_reserve_time/((float)num_handled_by_me)); dbgprintf(1,"st1: total get time %f ; avg get time %f\n", total_get_time,total_get_time/((float)num_handled_by_me)); ****/ printf("st1: num handled by me %d\n",num_handled_by_me); printf("st1: last end_work_time %f\n",end_work_time); printf("st1: total work_time %f ; avg work time %f\n", total_work_time,total_work_time/((float)num_handled_by_me)); printf("st1: total reserve time %f ; avg reserve time %f\n", total_reserve_time,total_reserve_time/((float)num_handled_by_me)); printf("st1: total get time %f ; avg get time %f\n", total_get_time,total_get_time/((float)num_handled_by_me)); MPI_Gather(&num_handled_by_me,1,MPI_INT, num_handled_by_rank,1,MPI_INT, 0,MPI_COMM_WORLD); if (my_world_rank == 0) { for (i=0; i < nranks; i++) // dbgprintf(1,"st1: num handled by rank %d : total %d per sec %.0f\n", printf("st1: num handled by rank %d : total %d per sec %.0f\n", i,num_handled_by_rank[i], ((float)num_handled_by_rank[i])/total_work_time); } PP_Finalize(); // printf("st1: calling mpi_finalize\n"); rc = MPI_Finalized(&i); if ( ! i) MPI_Finalize(); // printf("st1: past mpi_finalize\n"); return 0; }