@@ -768,6 +768,14 @@ struct gomp_thread
/* User pthread thread pool */
struct gomp_thread_pool *thread_pool;
+#ifdef LIBGOMP_USE_PTHREADS
+ /* omp_get_num_teams () - 1. */
+ unsigned int num_teams;
+
+ /* omp_get_team_num (). */
+ unsigned int team_num;
+#endif
+
#if defined(LIBGOMP_USE_PTHREADS) \
&& (!defined(HAVE_TLS) \
|| !defined(__GLIBC__) \
@@ -56,6 +56,8 @@ struct gomp_thread_start_data
struct gomp_task *task;
struct gomp_thread_pool *thread_pool;
unsigned int place;
+ unsigned int num_teams;
+ unsigned int team_num;
bool nested;
pthread_t handle;
};
@@ -88,6 +90,8 @@ gomp_thread_start (void *xdata)
thr->ts = data->ts;
thr->task = data->task;
thr->place = data->place;
+ thr->num_teams = data->num_teams;
+ thr->team_num = data->team_num;
#ifdef GOMP_NEEDS_THREAD_HANDLE
thr->handle = data->handle;
#endif
@@ -645,6 +649,8 @@ gomp_team_start (void (*fn) (void *), vo
nthr->ts.single_count = 0;
#endif
nthr->ts.static_trip = 0;
+ nthr->num_teams = thr->num_teams;
+ nthr->team_num = thr->team_num;
nthr->task = &team->implicit_task[i];
nthr->place = place;
gomp_init_task (nthr->task, task, icv);
@@ -833,6 +839,8 @@ gomp_team_start (void (*fn) (void *), vo
start_data->ts.single_count = 0;
#endif
start_data->ts.static_trip = 0;
+ start_data->num_teams = thr->num_teams;
+ start_data->team_num = thr->team_num;
start_data->task = &team->implicit_task[i];
gomp_init_task (start_data->task, task, icv);
team->implicit_task[i].icv.nthreads_var = nthreads_var;
@@ -28,14 +28,12 @@
#include "libgomp.h"
#include <limits.h>
-static unsigned gomp_num_teams = 1, gomp_team_num = 0;
-
void
GOMP_teams_reg (void (*fn) (void *), void *data, unsigned int num_teams,
unsigned int thread_limit, unsigned int flags)
{
+ struct gomp_thread *thr = gomp_thread ();
(void) flags;
- (void) num_teams;
unsigned old_thread_limit_var = 0;
if (thread_limit == 0)
thread_limit = gomp_teams_thread_limit_var;
@@ -48,11 +46,11 @@ GOMP_teams_reg (void (*fn) (void *), voi
}
if (num_teams == 0)
num_teams = gomp_nteams_var ? gomp_nteams_var : 3;
- gomp_num_teams = num_teams;
- for (gomp_team_num = 0; gomp_team_num < num_teams; gomp_team_num++)
+ thr->num_teams = num_teams - 1;
+ for (thr->team_num = 0; thr->team_num < num_teams; thr->team_num++)
fn (data);
- gomp_num_teams = 1;
- gomp_team_num = 0;
+ thr->num_teams = 0;
+ thr->team_num = 0;
if (thread_limit)
{
struct gomp_task_icv *icv = gomp_icv (true);
@@ -63,13 +61,15 @@ GOMP_teams_reg (void (*fn) (void *), voi
int
omp_get_num_teams (void)
{
- return gomp_num_teams;
+ struct gomp_thread *thr = gomp_thread ();
+ return thr->num_teams + 1;
}
int
omp_get_team_num (void)
{
- return gomp_team_num;
+ struct gomp_thread *thr = gomp_thread ();
+ return thr->team_num;
}
ialias (omp_get_num_teams)
@@ -0,0 +1,30 @@
+#include <omp.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ if (omp_get_num_teams () != 1 || omp_get_team_num () != 0)
+ abort ();
+ #pragma omp parallel num_threads (2)
+ if (omp_get_num_teams () != 1 || omp_get_team_num () != 0)
+ abort ();
+ #pragma omp teams num_teams (4)
+ {
+ int team = omp_get_team_num ();
+ if (omp_get_num_teams () != 4 || (unsigned) team >= 4U)
+ abort ();
+ #pragma omp parallel num_threads (3)
+ if (omp_get_num_teams () != 4 || omp_get_team_num () != team)
+ abort ();
+ #pragma omp parallel if (0)
+ #pragma omp target
+ #pragma omp teams num_teams (2)
+ if (omp_get_num_teams () > 2
+ || (unsigned) omp_get_team_num () >= 2U)
+ abort ();
+ if (omp_get_num_teams () != 4 || (unsigned) team >= 4U)
+ abort ();
+ }
+ return 0;
+}