[Openmp-commits] [PATCH] D95820: [OpenMP] Add bounds to num_teams clause (OpenMP 5.1)

Johannes Doerfert via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Feb 2 14:59:19 PST 2021


jdoerfert added inline comments.


================
Comment at: openmp/runtime/src/kmp_runtime.cpp:7537
+      num_teams = __kmp_teams_max_nth;
+    }
+  } else if (num_teams_lb == num_teams_ub) { // required exact number of teams
----------------
Nawrin wrote:
> jdoerfert wrote:
> > IIRC, this is not correct anymore in 5.1. We cannot cap the number of teams. We need to implement a loop if the number of physical teams is smaller than the number requested teams to basically emulate as many as have been requested.
> According to the spec, when num_teams clause is not present, the number of teams created should be implementation defined, but it will be greater or equal to 1.
> 
> 5.1 spec - "If the num_teams clause is not specified and the value of the nteams-var ICV is greater than zero, the number of teams created is less or equal to the value of the nteams-var ICV. Otherwise, the number of teams created is implementation defined, but it will be greater than or equal to 1."
I'm not arguing against that. What I'm trying to say is that we cannot cap the number of teams. So we cannot do `nteams = min(nteams, __kmp_teams_max_nth)`.

OpenMP 5.1 says, you get a number between the lower and upper bound. So if the lower bound is not smaller or equal than `__kmp_teams_max_nth`, we cannot cap at `__kmp_teams_max_nth`. This is explicitly different from num_threads on a parallel. For example, to implement N teams with a single thread, e.g., if `__kmp_teams_max_nth` was `1`, you would do something like this:
```
for (unsigned team_no = 0; team_no < num_teams_requested; ++team_no) {
  set_team_no_for_thread(team_no);
  execute_team_body();
}
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95820/new/

https://reviews.llvm.org/D95820



More information about the Openmp-commits mailing list