int main(int argc, char **argv) { apex_init(argv[0], 0, 1); num_threads = apex_hardware_concurrency(); total_iterations = num_threads * ITERATIONS; apex_set_throttle_concurrency(true); apex_set_throttle_energy(true); apex_setup_timer_throttling(APEX_FUNCTION_ADDRESS, &foo, APEX_MINIMIZE_ACCUMULATED, APEX_ACTIVE_HARMONY, 1000000); int original_cap = apex_get_thread_cap(); apex_profiler_handle p = apex_start(APEX_FUNCTION_ADDRESS, &main); printf("PID of this process: %d\n", getpid()); int i; pthread_t * thread = (pthread_t*)calloc(num_threads, sizeof(pthread_t)); int * ids = (int*)calloc(num_threads, sizeof(int)); for (i = 0 ; i < num_threads ; i++) { ids[i] = i; pthread_create(&(thread[i]), NULL, someThread, &(ids[i])); } for (i = 0 ; i < num_threads ; i++) { pthread_join(thread[i], NULL); } apex_stop(p); int final_cap = apex_get_thread_cap(); if (final_cap < original_cap) { printf ("Test passed.\n"); } apex_finalize(); free(thread); return(0); }
int main (int argc, char** argv) { apex_init("apex_resume unit test", 0, 1); apex_set_use_screen_output(1); apex_profiler_handle profiler = apex_start(APEX_FUNCTION_ADDRESS, &main); int i,j = 0; for (i = 0 ; i < 3 ; i++) j += foo(i); apex_stop(profiler); apex_finalize(); apex_cleanup(); return 0; }
int main(int argc, char *argv[]) { apex_init("apex_fibonacci_pthreads unit test", 0, 1); #if defined(APEX_HAVE_TAU) || defined(DEBUG) int i = 5; #else int i = 10; #endif if (argc != 2) { fprintf(stderr,"usage: pthreads <integer value>\n"); fprintf(stderr,"Using default value of %d\n", i); } else { i = atoi(argv[1]); } if (i < 1) { fprintf(stderr,"%d must be>= 1\n", i); return -1; } //int result = (int)fib((void*)i); scratchpad_t scratch; scratch.x = i; scratch.f_x = 0; pthread_attr_t attr; pthread_attr_init(&attr); size_t oldStackSize; pthread_attr_getstacksize(&attr, &oldStackSize); //pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); pthread_t thread; pthread_create(&thread,&attr,fib,(void*)&scratch); pthread_attr_destroy(&attr); printf("Default stack: %ld\n", oldStackSize); printf("Min stack: %d\n", PTHREAD_STACK_MIN); pthread_join(thread,NULL); printf("fib of %d is %d (valid value: %d)\n", i, scratch.f_x, fib_results[i]); apex_finalize(); apex_cleanup(); return 0; }
int hpx_init(int *argc, char ***argv) { int status = HPX_SUCCESS; // Start the internal clock libhpx_time_start(); here = malloc(sizeof(*here)); if (!here) { status = log_error("failed to allocate a locality.\n"); goto unwind0; } here->rank = -1; here->ranks = 0; here->epoch = 0; sigset_t set; sigemptyset(&set); dbg_check(pthread_sigmask(SIG_BLOCK, &set, &here->mask)); here->config = config_new(argc, argv); if (!here->config) { status = log_error("failed to create a configuration.\n"); goto unwind1; } // check to see if everyone is waiting if (config_dbg_waitat_isset(here->config, HPX_LOCALITY_ALL)) { dbg_wait(); } // bootstrap here->boot = boot_new(here->config->boot); if (!here->boot) { status = log_error("failed to bootstrap.\n"); goto unwind1; } here->rank = boot_rank(here->boot); here->ranks = boot_n_ranks(here->boot); // initialize the debugging system // @todo We would like to do this earlier but MPI_init() for the bootstrap // network overwrites our segv handler. if (LIBHPX_OK != dbg_init(here->config)) { goto unwind1; } // Now that we know our rank, we can be more specific about waiting. if (config_dbg_waitat_isset(here->config, here->rank)) { // Don't wait twice. if (!config_dbg_waitat_isset(here->config, HPX_LOCALITY_ALL)) { dbg_wait(); } } // see if we're supposed to output the configuration, only do this at rank 0 if (config_log_level_isset(here->config, HPX_LOG_CONFIG)) { if (here->rank == 0) { config_print(here->config, stdout); } } // topology discovery and initialization here->topology = topology_new(here->config); if (!here->topology) { status = log_error("failed to discover topology.\n"); goto unwind1; } // Initialize our instrumentation. if (inst_init(here->config)) { log_dflt("error detected while initializing instrumentation\n"); } // Allocate the global heap. here->gas = gas_new(here->config, here->boot); if (!here->gas) { status = log_error("failed to create the global address space.\n"); goto unwind1; } HPX_HERE = HPX_THERE(here->rank); here->percolation = percolation_new(); if (!here->percolation) { status = log_error("failed to activate percolation.\n"); goto unwind1; } int cores = system_get_available_cores(); dbg_assert(cores > 0); if (!here->config->threads) { here->config->threads = cores; } log_dflt("HPX running %d worker threads on %d cores\n", here->config->threads, cores); here->net = network_new(here->config, here->boot, here->gas); if (!here->net) { status = log_error("failed to create network.\n"); goto unwind1; } // thread scheduler here->sched = scheduler_new(here->config); if (!here->sched) { status = log_error("failed to create scheduler.\n"); goto unwind1; } #ifdef HAVE_APEX // initialize APEX, give this main thread a name apex_init("HPX WORKER THREAD"); apex_set_node_id(here->rank); #endif action_registration_finalize(); inst_start(); // start the scheduler, this will return after scheduler_shutdown() if (scheduler_startup(here->sched, here->config) != LIBHPX_OK) { log_error("scheduler shut down with error.\n"); goto unwind1; } if ((here->ranks > 1 && here->config->gas != HPX_GAS_AGAS) || !here->config->opt_smp) { status = hpx_run(&_hpx_143_fix); } return status; unwind1: _stop(here); _cleanup(here); unwind0: return status; }
int main (int argc, char** argv) { apex_init("apex_get_idle_rate unit test", 0, 1); apex_set_use_screen_output(1); printf("APEX Version : %s\n", apex_version()); apex_profiler_handle main_profiler = apex_start(APEX_FUNCTION_ADDRESS,(void*)(main)); int i = 0; // Call "foo" 30 times for(i = 0; i < 30; ++i) { apex_profiler_handle p = apex_start(APEX_NAME_STRING,"foo"); apex_stop(p); } // Call "bar" 40 times for(i = 0; i < 40; ++i) { apex_profiler_handle p = apex_start(APEX_NAME_STRING,"bar"); apex_stop(p); } // suspend measurement apex_set_papi_suspend(true); usleep(100); // Call "foo" 3 times for(i = 0; i < 3; ++i) { apex_profiler_handle p = apex_start(APEX_NAME_STRING,"foo"); apex_stop(p); } // Call "bar" 4 times for(i = 0; i < 4; ++i) { apex_profiler_handle p = apex_start(APEX_NAME_STRING,"bar"); apex_stop(p); } // The profile should show "foo" was called 3 times // and bar was called 4 times. // Call "Test Timer" 100 times for(i = 0; i < 100; ++i) { apex_profiler_handle p = apex_start(APEX_NAME_STRING,"Test Timer"); apex_stop(p); } // resume measurement apex_set_papi_suspend(false); usleep(100); // Call "Test Timer" 25 times for(i = 0; i < 25; ++i) { apex_profiler_handle p = apex_start(APEX_NAME_STRING,"Test Timer"); apex_stop(p); } bool passed = true; // The profile should show special "APEX Idle Time" counter. apex_profile * profile = apex_get_profile(APEX_NAME_STRING,APEX_IDLE_TIME); if (profile) { printf("Idle time reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } // The profile should show special "APEX Non-Idle Time" counter. profile = apex_get_profile(APEX_NAME_STRING,APEX_NON_IDLE_TIME); if (profile) { printf("Non-Idle time reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } // The profile should show special "APEX Idle Rate" counter. profile = apex_get_profile(APEX_NAME_STRING,APEX_IDLE_RATE); if (profile) { printf("Idle rate reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } apex_stop(main_profiler); // The profile should show special "APEX Idle Time" counter. profile = apex_get_profile(APEX_NAME_STRING,APEX_IDLE_TIME); if (profile) { printf("Idle time reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } // The profile should show special "APEX Non-Idle Time" counter. profile = apex_get_profile(APEX_NAME_STRING,APEX_NON_IDLE_TIME); if (profile) { printf("Non-Idle time reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } profile = apex_get_profile(APEX_NAME_STRING,APEX_IDLE_RATE); if (profile) { printf("Idle rate reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } apex_finalize(); // The profile should show special "APEX Idle Time" counter. profile = apex_get_profile(APEX_NAME_STRING,APEX_IDLE_TIME); if (profile) { printf("Idle time reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } // The profile should show special "APEX Non-Idle Time" counter. profile = apex_get_profile(APEX_NAME_STRING,APEX_NON_IDLE_TIME); if (profile) { printf("Non-Idle time reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } profile = apex_get_profile(APEX_NAME_STRING,APEX_IDLE_RATE); if (profile) { printf("Idle rate reported : %f\n", profile->accumulated); if (profile->accumulated >= 0.0) { // might be less, some calls might have been missed } else { passed = false; } } profile = apex_get_profile(APEX_NAME_STRING,"Test Timer"); if (profile) { printf("Value Reported : %f\n", profile->calls); if (profile->calls > 25) { // might be less, some calls might have been missed passed = false; } } profile = apex_get_profile(APEX_NAME_STRING,"foo"); if (profile) { printf("Value Reported : %f\n", profile->calls); if (profile->calls > 30) { // might be less, some calls might have been missed passed = false; } } profile = apex_get_profile(APEX_NAME_STRING,"bar"); if (profile) { printf("Value Reported : %f\n", profile->calls); if (profile->calls > 40) { // might be less, some calls might have been missed passed = false; } } if (passed) { printf("Test passed.\n"); } apex_cleanup(); return 0; }