[Openmp-commits] [openmp] [OpenMP] Add num_threads clause list format and strict modifier support (PR #85466)
via Openmp-commits
openmp-commits at lists.llvm.org
Fri Mar 29 19:12:59 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff e963d0740e64fc70b4018f39325469d204f6217a e34c994d1b16d369dde5b210f44bd16416137929 -- openmp/runtime/test/parallel/omp_parallel_num_threads_list.c openmp/runtime/test/parallel/omp_parallel_num_threads_strict.c openmp/runtime/src/kmp.h openmp/runtime/src/kmp_csupport.cpp openmp/runtime/src/kmp_runtime.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/openmp/runtime/test/parallel/omp_parallel_num_threads_list.c b/openmp/runtime/test/parallel/omp_parallel_num_threads_list.c
index 1c1771c255..7afc3a3caf 100644
--- a/openmp/runtime/test/parallel/omp_parallel_num_threads_list.c
+++ b/openmp/runtime/test/parallel/omp_parallel_num_threads_list.c
@@ -9,27 +9,27 @@ extern "C" {
#endif
int __kmpc_global_thread_num(void *loc);
-void __kmpc_push_num_threads_list(void *loc, int gtid, unsigned length, int *list);
+void __kmpc_push_num_threads_list(void *loc, int gtid, unsigned length,
+ int *list);
#if defined(__cplusplus)
}
#endif
-int test_omp_parallel_num_threads_list()
-{
+int test_omp_parallel_num_threads_list() {
int num_failed;
// Initially, 5 levels specified via OMP_NUM_THREADS with 2 threads per level
// Check top 3 levels
-#pragma omp parallel reduction(+:num_failed) // 1st level
+#pragma omp parallel reduction(+ : num_failed) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
@@ -38,15 +38,15 @@ int test_omp_parallel_num_threads_list()
} // end 1st level parallel
// Make sure that basic single element num_threads clause works
-#pragma omp parallel reduction(+:num_failed) num_threads(4) // 1st level
+#pragma omp parallel reduction(+ : num_failed) num_threads(4) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 4);
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2); // Unaffected
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2); // Unaffected
@@ -55,15 +55,15 @@ int test_omp_parallel_num_threads_list()
} // end 1st level parallel
// Check that basic single element num_threads clause works on second level
-#pragma omp parallel reduction(+:num_failed) // 1st level
+#pragma omp parallel reduction(+ : num_failed) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2); // Unaffected
-#pragma omp parallel reduction(+:num_failed) num_threads(4) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) num_threads(4) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 4);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2); // Unaffected
@@ -73,17 +73,18 @@ int test_omp_parallel_num_threads_list()
// Try a short list. It should completely overwrite the old settings.
// We need to use the compiler interface for now.
- int threads[2] = {3,3};
- __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2, threads);
-#pragma omp parallel reduction(+:num_failed) //num_threads(3,3) // 1st level
+ int threads[2] = {3, 3};
+ __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2,
+ threads);
+#pragma omp parallel reduction(+ : num_failed) // num_threads(3,3) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
// NOTE: should just keep using last element in list, to nesting depth
#pragma omp single
@@ -93,17 +94,18 @@ int test_omp_parallel_num_threads_list()
} // end 1st level parallel
// Similar, but at a lower level.
-#pragma omp parallel reduction(+:num_failed) // 1st level
+#pragma omp parallel reduction(+ : num_failed) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2); // Unaffected
- int threads[2] = {3,3};
- __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2, threads);
-#pragma omp parallel reduction(+:num_failed) // num_clause(3,3) // 2nd level
+ int threads[2] = {3, 3};
+ __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2,
+ threads);
+#pragma omp parallel reduction(+ : num_failed) // num_clause(3,3) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
// NOTE: just keep using last element in list, to nesting depth
#pragma omp single
@@ -111,11 +113,11 @@ int test_omp_parallel_num_threads_list()
} // end 3rd level parallel
} // end 2nd level parallel
// Make sure a second inner parallel is NOT affected by the clause
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2); // Unaffected
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
// NOTE: just keep using last element in list, to nesting depth
@@ -125,49 +127,51 @@ int test_omp_parallel_num_threads_list()
} // end 1st level parallel
// Test lists at multiple levels
- int threads2[2] = {4,3};
- __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2, threads2);
-#pragma omp parallel reduction(+:num_failed) // num_clause(4,3) // 1st level
+ int threads2[2] = {4, 3};
+ __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2,
+ threads2);
+#pragma omp parallel reduction(+ : num_failed) // num_clause(4,3) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 4);
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
- int threads3[2] = {2,5};
- __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2, threads3);
-#pragma omp parallel reduction(+:num_failed) //num_clause(2,5) // 4th level
+ int threads3[2] = {2, 5};
+ __kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2,
+ threads3);
+#pragma omp parallel reduction(+ : num_failed) // num_clause(2,5) // 4th level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
-#pragma omp parallel reduction(+:num_failed) // 5th level
+#pragma omp parallel reduction(+ : num_failed) // 5th level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 5);
-#pragma omp parallel reduction(+:num_failed) // 6th level
+#pragma omp parallel reduction(+ : num_failed) // 6th level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 5);
} // end 6th level parallel
} // end 5th level parallel
} // end 4th level parallel
-#pragma omp parallel reduction(+:num_failed) // 4th level
+#pragma omp parallel reduction(+ : num_failed) // 4th level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
} // end 4th level parallel
} // end 3rd level parallel
} // end 2nd level parallel
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 3);
@@ -176,15 +180,15 @@ int test_omp_parallel_num_threads_list()
} // end 1st level parallel
// Now we should be back to the way we started.
-#pragma omp parallel reduction(+:num_failed) // 1st level
+#pragma omp parallel reduction(+ : num_failed) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
-#pragma omp parallel reduction(+:num_failed) // 2nd level
+#pragma omp parallel reduction(+ : num_failed) // 2nd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
-#pragma omp parallel reduction(+:num_failed) // 3rd level
+#pragma omp parallel reduction(+ : num_failed) // 3rd level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
@@ -195,13 +199,12 @@ int test_omp_parallel_num_threads_list()
return (!num_failed);
}
-int main()
-{
+int main() {
int i;
- int num_failed=0;
+ int num_failed = 0;
- for(i = 0; i < REPETITIONS; i++) {
- if(!test_omp_parallel_num_threads_list()) {
+ for (i = 0; i < REPETITIONS; i++) {
+ if (!test_omp_parallel_num_threads_list()) {
num_failed++;
}
}
diff --git a/openmp/runtime/test/parallel/omp_parallel_num_threads_strict.c b/openmp/runtime/test/parallel/omp_parallel_num_threads_strict.c
index 358ac915c1..c1c697ca64 100644
--- a/openmp/runtime/test/parallel/omp_parallel_num_threads_strict.c
+++ b/openmp/runtime/test/parallel/omp_parallel_num_threads_strict.c
@@ -1,4 +1,5 @@
-// RUN: %libomp-compile && env OMP_NUM_THREADS=2,2,2,2,2 OMP_THREAD_LIMIT=16 %libomp-run
+// RUN: %libomp-compile && env OMP_NUM_THREADS=2,2,2,2,2 OMP_THREAD_LIMIT=16
+// %libomp-run
#include <stdio.h>
#include "omp_testsuite.h"
@@ -9,16 +10,18 @@ extern "C" {
#endif
int __kmpc_global_thread_num(void *loc);
-void __kmpc_push_num_threads_list(void *loc, int gtid, unsigned length, int *list);
-void __kmpc_push_num_threads_strict(void *loc, int gtid, int nth, int sev, const char *msg);
-void __kmpc_push_num_threads_list_strict(void *loc, int gtid, unsigned length, int *list, int sev, const char *msg);
+void __kmpc_push_num_threads_list(void *loc, int gtid, unsigned length,
+ int *list);
+void __kmpc_push_num_threads_strict(void *loc, int gtid, int nth, int sev,
+ const char *msg);
+void __kmpc_push_num_threads_list_strict(void *loc, int gtid, unsigned length,
+ int *list, int sev, const char *msg);
#if defined(__cplusplus)
}
#endif
-int test_omp_parallel_num_threads_strict()
-{
+int test_omp_parallel_num_threads_strict() {
int num_failed;
// Test regular runtime warning about exceeding thread limit.
@@ -28,15 +31,15 @@ int test_omp_parallel_num_threads_strict()
num_failed = num_failed + !(omp_get_num_threads() <= 22);
// Test with 4 threads and strict -- no problem, no warning.
- __kmpc_push_num_threads_strict(NULL, __kmpc_global_thread_num(NULL), 4,
- 1, "This warning shouldn't happen.");
-#pragma omp parallel //num_threads(strict:4)
+ __kmpc_push_num_threads_strict(NULL, __kmpc_global_thread_num(NULL), 4, 1,
+ "This warning shouldn't happen.");
+#pragma omp parallel // num_threads(strict:4)
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 4);
// Exceed limit, specify user warning message. Tolerate whatever was given.
- __kmpc_push_num_threads_strict(NULL, __kmpc_global_thread_num(NULL), 20,
- 1, "User-supplied warning for strict.");
+ __kmpc_push_num_threads_strict(NULL, __kmpc_global_thread_num(NULL), 20, 1,
+ "User-supplied warning for strict.");
#pragma omp parallel //num_threads(strict:20) severity(warning) \
message("User-supplied warning for strict.")
#pragma omp single
@@ -44,15 +47,14 @@ int test_omp_parallel_num_threads_strict()
// Exceed limit, no user message, use runtime default message for strict.
// Tolerate whatever value was given.
- __kmpc_push_num_threads_strict(NULL, __kmpc_global_thread_num(NULL), 21,
- 1, NULL);
-#pragma omp parallel //num_threads(strict:21)
+ __kmpc_push_num_threads_strict(NULL, __kmpc_global_thread_num(NULL), 21, 1,
+ NULL);
+#pragma omp parallel // num_threads(strict:21)
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() <= 21);
-
// Exceed limit in nested level. Should see user warning message.
- int threads3[2] = {2,24};
+ int threads3[2] = {2, 24};
__kmpc_push_num_threads_list_strict(NULL, __kmpc_global_thread_num(NULL), 2,
threads3, 1,
"User-supplied warning on strict list.");
@@ -71,7 +73,7 @@ int test_omp_parallel_num_threads_strict()
// No strict limit in nested level. Regular runtime limiting applies.
__kmpc_push_num_threads_list(NULL, __kmpc_global_thread_num(NULL), 2,
threads3);
-#pragma omp parallel //num_threads(2,24) // 1st level
+#pragma omp parallel // num_threads(2,24) // 1st level
{
#pragma omp single
num_failed = num_failed + !(omp_get_num_threads() == 2);
@@ -85,13 +87,12 @@ int test_omp_parallel_num_threads_strict()
return (!num_failed);
}
-int main()
-{
+int main() {
int i;
- int num_failed=0;
+ int num_failed = 0;
- for(i = 0; i < REPETITIONS; i++) {
- if(!test_omp_parallel_num_threads_strict()) {
+ for (i = 0; i < REPETITIONS; i++) {
+ if (!test_omp_parallel_num_threads_strict()) {
num_failed++;
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/85466
More information about the Openmp-commits
mailing list