Created
February 25, 2020 16:23
-
-
Save jdoerfert/d0014c88d8a522a61b40771c5a5003d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class BindKind { | |
teams, | |
parallel, | |
thread, | |
}; | |
typedef void (*body_t)(int); | |
void loop_init_teams(int lb, int ub, body_t body, bool HasInnerLoop) { | |
if (HasInnerLoop) { | |
#pragma omp distribute | |
for (int i = lb; i < ub; ++i) | |
body(i); | |
} else { | |
#pragma omp distribute parallel for simd | |
for (int i = lb; i < ub; ++i) | |
body(i); | |
} | |
} | |
void loop_init_parallel(int lb, int ub, body_t body, bool HasInnerLoop) { | |
#pragma omp for simd | |
for (int i = lb; i < ub; ++i) | |
body(i); | |
} | |
void loop_init_thread(int lb, int ub, body_t body, bool HasInnerLoop) { | |
if (HasInnerLoop) { | |
#pragma omp parallel for simd num_threads(some_heuristic()) | |
for (int i = lb; i < ub; ++i) | |
body(i); | |
} else { | |
#pragma omp parallel for simd | |
for (int i = lb; i < ub; ++i) | |
body(i); | |
} | |
} | |
void loop_init(BindKind kind, int lb, int ub, body_t body, bool HasInnerLoop) { | |
switch (kind) { | |
case BindKind::teams: | |
return loop_init_teams(lb, ub, body, HasInnerLoop); | |
case BindKind::parallel: | |
return loop_init_parallel(lb, ub, body, HasInnerLoop); | |
default: | |
return loop_init_thread(lb, ub, body, HasInnerLoop); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment