[Openmp-commits] [openmp] [OpenMP] add loop collapse tests (PR #86243)
via Openmp-commits
openmp-commits at lists.llvm.org
Thu Mar 21 21:37:33 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 7c460c6205eedaa24f77d5de272dfd94dc3e9a38 d8655f4ffed2b3e9c99c4a9e1f7e0c567ff8920f -- openmp/runtime/test/worksharing/for/collapse_many_GELTGT_int.c openmp/runtime/test/worksharing/for/collapse_many_GTGEGT_int.c openmp/runtime/test/worksharing/for/collapse_many_LTLEGE_int.c openmp/runtime/test/worksharing/for/collapse_many_int.c openmp/runtime/test/worksharing/for/collapse_one_int.c openmp/runtime/test/worksharing/for/collapse_test.inc openmp/runtime/src/kmp_collapse.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/openmp/runtime/test/worksharing/for/collapse_test.inc b/openmp/runtime/test/worksharing/for/collapse_test.inc
index 8c88dc9860..7e9022cda0 100644
--- a/openmp/runtime/test/worksharing/for/collapse_test.inc
+++ b/openmp/runtime/test/worksharing/for/collapse_test.inc
@@ -65,127 +65,123 @@ LOOP_STYPE2 kA1, kB1, kStep;
#define COMPARE2 >
#endif
-
-typedef struct
-{
- LOOP_IV_TYPE0 i;
- LOOP_IV_TYPE1 j;
- LOOP_IV_TYPE2 k;
+typedef struct {
+ LOOP_IV_TYPE0 i;
+ LOOP_IV_TYPE1 j;
+ LOOP_IV_TYPE2 k;
} spaceType;
-spaceType* AllocSpace(unsigned size)
-{
+spaceType *AllocSpace(unsigned size) {
- spaceType *p = (spaceType*) malloc(size * sizeof(spaceType));
- memset(p, 0, size * sizeof(spaceType));
- return p;
+ spaceType *p = (spaceType *)malloc(size * sizeof(spaceType));
+ memset(p, 0, size * sizeof(spaceType));
+ return p;
}
-void FreeSpace(spaceType* space)
-{
- free(space);
-}
+void FreeSpace(spaceType *space) { free(space); }
// record an iteration
-void Set(spaceType* space, unsigned count, unsigned trueCount, LOOP_IV_TYPE0 i, LOOP_IV_TYPE1 j, LOOP_IV_TYPE0 k)
-{
- if (count > trueCount) {
- // number of iterations exceeded
- // will be reported with checks
- return;
- }
- space[count-1].i = i;
- space[count-1].j = j;
- space[count-1].k = k;
+void Set(spaceType *space, unsigned count, unsigned trueCount, LOOP_IV_TYPE0 i,
+ LOOP_IV_TYPE1 j, LOOP_IV_TYPE0 k) {
+ if (count > trueCount) {
+ // number of iterations exceeded
+ // will be reported with checks
+ return;
+ }
+ space[count - 1].i = i;
+ space[count - 1].j = j;
+ space[count - 1].k = k;
}
-int test()
-{
- int pass = 1;
- LOOP_IV_TYPE0 i;
- LOOP_IV_TYPE1 j;
- LOOP_IV_TYPE2 k;
-
- spaceType* openmpSpace;
- spaceType* scalarSpace;
-
- unsigned trueCount = 0;
- unsigned openmpCount = 0;
- unsigned scalarCount = 0;
- unsigned uselessThreadsOpenMP = 0;
- unsigned usefulThreadsOpenMP = 0;
- unsigned chunkSizesOpenmp[MAX_THREADS] = {0};
-
- unsigned num_threads = omp_get_max_threads();
- if (num_threads > MAX_THREADS) num_threads = MAX_THREADS;
- omp_set_num_threads(num_threads);
-
- // count iterations and allocate space
- LOOP {
- ++trueCount;
- }
-
- openmpSpace = AllocSpace(trueCount);
- scalarSpace = AllocSpace(trueCount);
-
- // fill the scalar (compare) space
- LOOP {
- ++scalarCount;
- Set(scalarSpace, scalarCount, trueCount, i, j, k);
- }
-
- // test run body:
- // perform and record OpenMP iterations and thread use
+int test() {
+ int pass = 1;
+ LOOP_IV_TYPE0 i;
+ LOOP_IV_TYPE1 j;
+ LOOP_IV_TYPE2 k;
+
+ spaceType *openmpSpace;
+ spaceType *scalarSpace;
+
+ unsigned trueCount = 0;
+ unsigned openmpCount = 0;
+ unsigned scalarCount = 0;
+ unsigned uselessThreadsOpenMP = 0;
+ unsigned usefulThreadsOpenMP = 0;
+ unsigned chunkSizesOpenmp[MAX_THREADS] = {0};
+
+ unsigned num_threads = omp_get_max_threads();
+ if (num_threads > MAX_THREADS)
+ num_threads = MAX_THREADS;
+ omp_set_num_threads(num_threads);
+
+ // count iterations and allocate space
+ LOOP { ++trueCount; }
+
+ openmpSpace = AllocSpace(trueCount);
+ scalarSpace = AllocSpace(trueCount);
+
+ // fill the scalar (compare) space
+ LOOP {
+ ++scalarCount;
+ Set(scalarSpace, scalarCount, trueCount, i, j, k);
+ }
+
+ // test run body:
+ // perform and record OpenMP iterations and thread use
#pragma omp parallel num_threads(num_threads)
- {
-#pragma omp for collapse(3) private (i, j, k)
- LOOP
- {
- unsigned count;
- unsigned gtid = omp_get_thread_num();
+ {
+#pragma omp for collapse(3) private(i, j, k)
+ LOOP {
+ unsigned count;
+ unsigned gtid = omp_get_thread_num();
#pragma omp atomic update
- ++chunkSizesOpenmp[gtid];
+ ++chunkSizesOpenmp[gtid];
#pragma omp atomic capture
- count = ++openmpCount;
- Set(openmpSpace, count, trueCount, i, j, k);
- }
- }
-
- // check for the right number of iterations processed
- // (only need to check for less, greater is checked when recording)
- if (openmpCount < trueCount) {
- PRINTF("OpenMP FAILURE: Openmp processed fewer iterations: %d vs %d\n", openmpCount, trueCount);
- pass = 0;
- } else if (openmpCount > trueCount) {
- PRINTF("OpenMP FAILURE: Openmp processed more iterations: %d vs %d\n", openmpCount, trueCount);
- pass = 0;
+ count = ++openmpCount;
+ Set(openmpSpace, count, trueCount, i, j, k);
}
-
- // check openMP for iteration correctnes against scalar
- for (unsigned i = 0; i < trueCount; i++) {
- unsigned j;
- for (j = 0; j < openmpCount; j++) {
- if ((scalarSpace[i].i == openmpSpace[j].i) && (scalarSpace[i].j == openmpSpace[j].j) && (scalarSpace[i].k == openmpSpace[j].k)) {
- break;
- }
- }
- if (j == openmpCount) {
- PRINTF("OpenMP FAILURE: (%d %d %d) not processed\n", scalarSpace[i].i, scalarSpace[i].j, scalarSpace[i].k);
- pass = 0;
+ }
+
+ // check for the right number of iterations processed
+ // (only need to check for less, greater is checked when recording)
+ if (openmpCount < trueCount) {
+ PRINTF("OpenMP FAILURE: Openmp processed fewer iterations: %d vs %d\n",
+ openmpCount, trueCount);
+ pass = 0;
+ } else if (openmpCount > trueCount) {
+ PRINTF("OpenMP FAILURE: Openmp processed more iterations: %d vs %d\n",
+ openmpCount, trueCount);
+ pass = 0;
+ }
+
+ // check openMP for iteration correctnes against scalar
+ for (unsigned i = 0; i < trueCount; i++) {
+ unsigned j;
+ for (j = 0; j < openmpCount; j++) {
+ if ((scalarSpace[i].i == openmpSpace[j].i) &&
+ (scalarSpace[i].j == openmpSpace[j].j) &&
+ (scalarSpace[i].k == openmpSpace[j].k)) {
+ break;
}
}
-
- // check for efficient thread use
- for (unsigned i = 0; i < num_threads; ++i) {
- if (chunkSizesOpenmp[i] == 0) {
- ++uselessThreadsOpenMP;
- }
+ if (j == openmpCount) {
+ PRINTF("OpenMP FAILURE: (%d %d %d) not processed\n", scalarSpace[i].i,
+ scalarSpace[i].j, scalarSpace[i].k);
+ pass = 0;
}
+ }
- // a check to see if at least more than one thread was used (weakish)
- if ((uselessThreadsOpenMP == num_threads - 1) && (trueCount > 1)) {
- PRINTF("OpenMP FAILURE: threads are not used\n");
- pass = 0;
+ // check for efficient thread use
+ for (unsigned i = 0; i < num_threads; ++i) {
+ if (chunkSizesOpenmp[i] == 0) {
+ ++uselessThreadsOpenMP;
}
+ }
+
+ // a check to see if at least more than one thread was used (weakish)
+ if ((uselessThreadsOpenMP == num_threads - 1) && (trueCount > 1)) {
+ PRINTF("OpenMP FAILURE: threads are not used\n");
+ pass = 0;
+ }
#if 0
// a check to see if the load was spread more or less evenly so that
@@ -197,8 +193,8 @@ int test()
}
#endif
- // clean up space
- FreeSpace(openmpSpace);
- FreeSpace(scalarSpace);
- return pass;
+ // clean up space
+ FreeSpace(openmpSpace);
+ FreeSpace(scalarSpace);
+ return pass;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/86243
More information about the Openmp-commits
mailing list