Esempio n. 1
0
int main (int argc, char** argv) {
  apex_init_args(argc, argv, "apex_version unit test");
  printf("APEX Version : %s\n", apex_version());
  apex_finalize();
  apex_cleanup();
  return 0;
}
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);
}
Esempio n. 3
0
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_start unit test");
    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;
}
Esempio n. 5
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;
}
Esempio n. 6
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 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;
}
Esempio n. 8
0
/// Cleanup utility function.
///
/// This will delete the global objects, if they've been allocated.
static void _cleanup(locality_t *l) {
  if (!l)
    return;

#ifdef HAVE_APEX
  apex_finalize();
#endif

  if (l->percolation) {
    percolation_delete(l->percolation);
    l->percolation = NULL;
  }

  if (l->gas) {
    gas_dealloc(l->gas);
    l->gas = NULL;
  }

  dbg_fini();

  if (l->boot) {
    boot_delete(l->boot);
    l->boot = NULL;
  }

  if (l->topology) {
    topology_delete(l->topology);
    l->topology = NULL;
  }

  action_table_finalize();
  inst_fini();

  if (l->config) {
    config_delete(l->config);
  }

  free(l);
}
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;
}
Esempio n. 10
0
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);
}