int main (int argc, char** argv) { apex_init_args(argc, argv, "apex_reset unit test"); apex_set_use_screen_output(1); printf("APEX Version : %s\n", apex_version()); apex_set_node_id(0); 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); } // Reset everything apex_reset(APEX_FUNCTION_ADDRESS, APEX_NULL_FUNCTION_ADDRESS); 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); } // Reset "Test Timer" apex_reset(APEX_NAME_STRING, "Test Timer"); 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); } // The profile should show "Test Timer" was called 25 times. apex_stop(main_profiler); apex_finalize(); apex_profile * 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 printf("Test passed.\n"); } } apex_cleanup(); return 0; }
int main(int argc, char **argv) { apex_init_args(argc, argv, "apex_exit_thread unit test"); apex_set_node_id(0); apex_profiler_handle profiler = apex_start(APEX_FUNCTION_ADDRESS,(void*)&main); pthread_t * thread = (pthread_t*)(malloc(sizeof(pthread_t) * NUM_THREADS)); int i; for (i = 0 ; i < NUM_THREADS ; i++) { pthread_create(&(thread[i]), NULL, someThread, NULL); } for (i = 0 ; i < NUM_THREADS ; i++) { pthread_join(thread[i], NULL); } apex_stop(profiler); apex_finalize(); 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_policy_handle * on_startup = apex_register_policy(APEX_STARTUP, startup_policy); apex_policy_handle * on_shutdown = apex_register_policy(APEX_SHUTDOWN, policy_event); apex_policy_handle * on_new_node = apex_register_policy(APEX_NEW_NODE, policy_event); apex_policy_handle * on_new_thread = apex_register_policy(APEX_NEW_THREAD, policy_event); apex_init_args(argc, argv, NULL); apex_set_node_id(0); apex_policy_handle * on_start_event = apex_register_policy(APEX_START_EVENT, policy_event); apex_policy_handle * on_stop_event = apex_register_policy(APEX_STOP_EVENT, policy_event); apex_policy_handle * on_resume_event = apex_register_policy(APEX_RESUME_EVENT, policy_event); apex_policy_handle * on_yield_event = apex_register_policy(APEX_YIELD_EVENT, policy_event); apex_policy_handle * on_sample_value = apex_register_policy(APEX_SAMPLE_VALUE, policy_event); custom_type_1 = apex_register_custom_event("CUSTOM 1"); custom_type_2 = apex_register_custom_event("CUSTOM 2"); apex_policy_handle * on_custom_event_1 = apex_register_policy(custom_type_1, policy_event); apex_policy_handle * on_custom_event_2 = apex_register_policy(custom_type_2, policy_event); apex_policy_handle * on_periodic = apex_register_periodic_policy(1000000, policy_periodic); apex_profiler_handle my_profiler = apex_start(APEX_FUNCTION_ADDRESS, &main); pthread_t thread[NUM_THREADS]; int i; for (i = 0 ; i < NUM_THREADS ; i++) { pthread_create(&(thread[i]), NULL, someThread, NULL); } for (i = 0 ; i < NUM_THREADS ; i++) { pthread_join(thread[i], NULL); } // now un-register the policies printf("Deregistering %d...\n", on_startup->id); printf("Deregistering %d...\n", on_shutdown->id); printf("Deregistering %d...\n", on_new_node->id); printf("Deregistering %d...\n", on_new_thread->id); printf("Deregistering %d...\n", on_start_event->id); printf("Deregistering %d...\n", on_stop_event->id); printf("Deregistering %d...\n", on_resume_event->id); printf("Deregistering %d...\n", on_yield_event->id); printf("Deregistering %d...\n", on_sample_value->id); printf("Deregistering %d...\n", on_custom_event_1->id); printf("Deregistering %d...\n", on_custom_event_2->id); printf("Deregistering %d...\n", on_periodic->id); apex_deregister_policy(on_startup); apex_deregister_policy(on_shutdown); apex_deregister_policy(on_new_node); apex_deregister_policy(on_new_thread); apex_deregister_policy(on_start_event); apex_deregister_policy(on_stop_event); apex_deregister_policy(on_resume_event); apex_deregister_policy(on_yield_event); apex_deregister_policy(on_sample_value); apex_deregister_policy(on_custom_event_1); apex_deregister_policy(on_custom_event_2); apex_deregister_policy(on_periodic); printf("Running without policies now...\n"); for (i = 0 ; i < NUM_THREADS ; i++) { pthread_create(&(thread[i]), NULL, someThread, NULL); } for (i = 0 ; i < NUM_THREADS ; i++) { pthread_join(thread[i], NULL); } apex_stop(my_profiler); apex_finalize(); return(0); }