int main () { if (omp_get_level ()) abort (); #pragma omp target if (0) if (omp_get_level ()) abort (); #pragma omp target if (0) #pragma omp teams if (omp_get_level ()) abort (); return 0; }
int main ( int argc, char **argv ) { int result = 0; int i; nanos_wd_props_t props = { .mandatory_creation = true, .tied = false }; int level = omp_get_level(); int ancestor_num = omp_get_ancestor_thread_num( level ); int team_size = omp_get_team_size(level); int active_level = omp_get_active_level(); int in_final = omp_in_final(); printf ( " OpenMP API calls simple test:\n" ); printf ( "\tomp_get_level() = %d\n", level ); printf ( "\tomp_get_ancestor_thread_num(%d) = %d\n", level, ancestor_num ); printf ( "\tomp_get_team_size(%d) = %d\n", level, team_size ); printf ( "\tomp_get_active_level() = %d\n", active_level ); printf ( "\tomp_in_final() = %d\n", in_final ); if ( in_final != 0 ) result = 1; if ( active_level != 0 ) result = 2; if ( level != 0 ) result = 3; if ( ancestor_num != 0 ) result = 4; return result; }
inline bool OpenMP::in_parallel( OpenMP const& ) noexcept { //t_openmp_instance is only non-null on a master thread return !Impl::t_openmp_instance || Impl::t_openmp_instance->m_level < omp_get_level() ; }
int main() { // printf("max thread num is %d\n", omp_get_max_threads()); omp_set_nested(1); omp_set_dynamic(0); #pragma omp parallel num_threads(3) { fib(N+3); report_num_threads(omp_get_level()); } #pragma omp parallel num_threads(3) { fib(N+3); report_num_threads(omp_get_level()); } return(0); }
void mergesortstat(I b, I e, I bb) { if(!mergesortstat_debug(-1)) return; char buf[128]; sprintf(buf,"Start-End %08d-%08d Team %02d Thread/Max %02d/%02d Level %02d Parent %02d\n", (int)(b-bb),(int)(e-bb), omp_get_team_num(), omp_get_thread_num(), omp_get_num_threads(), omp_get_level(), omp_get_ancestor_thread_num (omp_get_level()) ); #pragma omp critical (io) { std::cout << buf << std::flush; } }
static void called_function(const int& kk) { const int third = rand(); #if defined(OPENMP_FOUND) #pragma omp critical std::cout << " funct " << omp_get_thread_num() << " " << omp_get_level() << " " << third << " " << kk << std::endl; #endif }
/** * \brief returns the team size of a thread at a given level * * \param level the level to consider * * \returns number of threads in the team * * * The omp_get_team_size routine returns the size of the thread team to which the * ancestor or the current thread belongs. If the requested nested level is outside * the range of 0 and the nested level of the current thread, as returned by the * omp_get_level routine, the routine returns -1. Inactive parallel regions are * regarded like active parallel regions executed with one thread. */ int omp_get_team_size(int level) { int my_level = omp_get_level(); if (level > my_level || level < 0) { return -1; } else { /* TODO */ assert(!"NYI"); return 0; } }
/** * \brief returns the ancestor thread number of a thread at a given level * * \param level the level of the ancestor * * \returns thread number of ancestor thread * * The omp_get_ancestor_thread_num routine returns the thread number of the * ancestor at a given nest level of the current thread or the thread number of * the current thread. If the requested nest level is outside the range of 0 and * the nest level of the current thread, as returned by the omp_get_level routine, * the routine returns -1. */ int omp_get_ancestor_thread_num(int level) { int my_level = omp_get_level(); if (level > my_level || level < 0) { return -1; } else if (my_level == level) { return omp_get_thread_num(); } else { /* TODO */ assert(!"NYI"); return 0; } }
int test_random_generator() { #if !defined(NDEBUG) std::cout << std::hex; { const int first = rand(); const int second = rand(); std::cout << first << " " << second << std::endl; } { int random_buffer[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; std::random_shuffle(random_buffer, random_buffer+10); for (size_t kk=0; kk<10; kk++) std::cout << random_buffer[kk] << " "; std::cout << std::endl; } int total_good = 0; int total_bad = 0; #pragma omp parallel default(none) shared(std::cout, total_good, total_bad) { const int first = rand(); #pragma omp critical std::cout << "thread " << omp_get_thread_num() << "/" << omp_get_team_size(1) << " " << omp_get_level() << " " << first << std::endl; #pragma omp for for (size_t kk=0; kk<10; kk++) { const int second = rand(); #pragma omp critical std::cout << " in for " << omp_get_thread_num() << " " << omp_get_level() << " " << second << " " << kk << std::endl; called_function(kk); #pragma omp atomic update total_good++; total_bad++; } } std::cout << std::dec; std::cout << "good " << total_good << " bad " << total_bad << std::endl; #endif return rand(); }
void ompt_event_parallel_end_fn ( ompt_task_id_t parent_task_id, /* id of the parent task */ ompt_frame_t *parent_task_frame, /* frame data of parent task */ ompt_parallel_id_t parallel_id, /* id of parallel region */ void *parallel_function) /* outlined function */ { int level = omp_get_level(); #if 0 printf("%d region %8lx: exit " "ompt_event_parallel_exit_fn(parent_task_id=%8lx, parent_task_frame=%8lx, " "parallel_id=%8lx par_fn=%p)\n", omp_get_thread_num(), parallel_id, parent_task_id, parent_task_frame, parallel_id, parallel_function); #else printf("%d region %8lx: end %*s[level=%d, parent_parallel_id=%8lx]\n", omp_get_thread_num(), parallel_id, level+1, " ", level, ompt_get_parallel_id(0)); #endif fflush(stdout); }
int get_level () { return omp_get_level (); }
int32_t omp_get_level_ (void) { return omp_get_level (); }
int main () { omp_set_dynamic (0); omp_set_nested (1); if (omp_in_parallel ()) abort (); #pragma omp parallel num_threads (3) if (omp_get_thread_num () == 2) { if (!omp_in_parallel ()) abort (); #pragma omp parallel num_threads (3) if (omp_get_thread_num () == 1) { if (!omp_in_parallel () || omp_get_level () != 2 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != 2 || omp_get_ancestor_thread_num (2) != 1 || omp_get_ancestor_thread_num (3) != -1) abort (); #pragma omp target if (0) { if (omp_in_parallel () || omp_get_level () != 0 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != -1) abort (); #pragma omp parallel num_threads (2) { if (!omp_in_parallel () || omp_get_level () != 1 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != omp_get_thread_num () || omp_get_ancestor_thread_num (2) != -1) abort (); } } #pragma omp target if (0) { #pragma omp teams thread_limit (2) { if (omp_in_parallel () || omp_get_level () != 0 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != -1) abort (); #pragma omp parallel num_threads (2) { if (!omp_in_parallel () || omp_get_level () != 1 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != omp_get_thread_num () || omp_get_ancestor_thread_num (2) != -1) abort (); } } } } } return 0; }
int main (void) { int e[3]; memset (e, '\0', sizeof (e)); omp_set_nested (1); omp_set_dynamic (0); if (omp_in_parallel () || omp_get_level () != 0 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (-1) != -1 || omp_get_ancestor_thread_num (1) != -1 || omp_get_team_size (0) != 1 || omp_get_team_size (-1) != -1 || omp_get_team_size (1) != -1 || omp_get_active_level () != 0) abort (); #pragma omp parallel num_threads (4) { int tn1 = omp_get_thread_num (); if (omp_in_parallel () != 1 || omp_get_num_threads () != 4 || tn1 >= 4 || tn1 < 0 || omp_get_level () != 1 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != tn1 || omp_get_ancestor_thread_num (-1) != -1 || omp_get_ancestor_thread_num (2) != -1 || omp_get_team_size (0) != 1 || omp_get_team_size (1) != omp_get_num_threads () || omp_get_team_size (-1) != -1 || omp_get_team_size (2) != -1 || omp_get_active_level () != 1) #pragma omp atomic e[0] += 1; #pragma omp parallel if (0) num_threads(5) firstprivate(tn1) { int tn2 = omp_get_thread_num (); if (omp_in_parallel () != 1 || omp_get_num_threads () != 1 || tn2 != 0 || omp_get_level () != 2 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != tn1 || omp_get_ancestor_thread_num (2) != tn2 || omp_get_ancestor_thread_num (-1) != -1 || omp_get_ancestor_thread_num (3) != -1 || omp_get_team_size (0) != 1 || omp_get_team_size (1) != 4 || omp_get_team_size (2) != 1 || omp_get_team_size (-1) != -1 || omp_get_team_size (3) != -1 || omp_get_active_level () != 1) #pragma omp atomic e[1] += 1; #pragma omp parallel num_threads(2) firstprivate(tn1, tn2) { int tn3 = omp_get_thread_num (); if (omp_in_parallel () != 1 || omp_get_num_threads () != 2 || tn3 > 1 || tn3 < 0 || omp_get_level () != 3 || omp_get_ancestor_thread_num (0) != 0 || omp_get_ancestor_thread_num (1) != tn1 || omp_get_ancestor_thread_num (2) != tn2 || omp_get_ancestor_thread_num (3) != tn3 || omp_get_ancestor_thread_num (-1) != -1 || omp_get_ancestor_thread_num (4) != -1 || omp_get_team_size (0) != 1 || omp_get_team_size (1) != 4 || omp_get_team_size (2) != 1 || omp_get_team_size (3) != 2 || omp_get_team_size (-1) != -1 || omp_get_team_size (4) != -1 || omp_get_active_level () != 2) #pragma omp atomic e[2] += 1; } } } if (e[0] || e[1] || e[2]) abort (); return 0; }
OpenMPExec( int arg_pool_size ) : m_pool_size{ arg_pool_size } , m_level{ omp_get_level() } , m_pool() {}
inline HostThreadTeamData * get_thread_data() const noexcept { return m_pool[ m_level == omp_get_level() ? 0 : omp_get_thread_num() ]; }
void foo (int f) { int d = f ? omp_get_num_devices () : omp_get_default_device (); int h = 5; #pragma omp target device (d) if (omp_get_level () != 0) abort (); #pragma omp target if (v > 1) if (omp_get_level () != 0 || !omp_is_initial_device ()) abort (); #pragma omp target device (d) if (v > 1) if (omp_get_level () != 0 || !omp_is_initial_device ()) abort (); #pragma omp target if (v <= 1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ())) abort (); #pragma omp target device (d) if (v <= 1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ())) abort (); #pragma omp target if (0) if (omp_get_level () != 0 || !omp_is_initial_device ()) abort (); #pragma omp target device (d) if (0) if (omp_get_level () != 0 || !omp_is_initial_device ()) abort (); #pragma omp target if (1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ())) abort (); #pragma omp target device (d) if (1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ())) abort (); #pragma omp target data device (d) map (to: h) { #pragma omp target device (d) if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 5) abort (); #pragma omp target update device (d) from (h) } #pragma omp target data if (v > 1) map (to: h) { #pragma omp target if (v > 1) if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 6) abort (); #pragma omp target update if (v > 1) from (h) } #pragma omp target data device (d) if (v > 1) map (to: h) { #pragma omp target device (d) if (v > 1) if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 7) abort (); #pragma omp target update device (d) if (v > 1) from (h) } #pragma omp target data if (v <= 1) map (to: h) { #pragma omp target if (v <= 1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 8) abort (); #pragma omp target update if (v <= 1) from (h) } #pragma omp target data device (d) if (v <= 1) map (to: h) { #pragma omp target device (d) if (v <= 1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 9) abort (); #pragma omp target update device (d) if (v <= 1) from (h) } #pragma omp target data if (0) map (to: h) { #pragma omp target if (0) if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 10) abort (); #pragma omp target update if (0) from (h) } #pragma omp target data device (d) if (0) map (to: h) { #pragma omp target device (d) if (0) if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 11) abort (); #pragma omp target update device (d) if (0) from (h) } #pragma omp target data if (1) map (to: h) { #pragma omp target if (1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 12) abort (); #pragma omp target update if (1) from (h) } #pragma omp target data device (d) if (1) map (to: h) { #pragma omp target device (d) if (1) if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 13) abort (); #pragma omp target update device (d) if (1) from (h) } if (h != 14) abort (); }