Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test for assume directive with no_openmp_constructs clause. #846

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions tests/6.0/assume/test_assume_noopenmpconstructs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//--------------test_assume_noopenmpconstructs.c----------------------------------//
// OpenMP API Version 6.0 November 2024
// Pg. 900, line 22
// ***********
// DIRECTIVE:assume
// CLAUSE:no_openmp_constructs
// ***********
// The no_openmp_constructs clause is used to guarantee that the section of code
// which applies to the assumes directive does not contain any OpenMP
// constructs. The argument supplied to the clause is the "can_assume" int
// variable. If the variable is 1, the no_openmp_constructs assumes that the
// assumption is true. If the variable is 0, the clause assumes that the
// assumption is false. If the argument is not specified (empty) then the default
// assumption is true. If the clause is working correctly, then the array A will
// be updated with the expected values and the sum of those values will be
// checked for correctness.
//---------------------------------------------------------------------------------//
#include "ompvv.h"

#define N 10

int test_assumes_no_openmp_constructs() {
int A[N] = {0};
int errors = 0, sum = 0, can_assume = 0;
int i;

#pragma omp assume no_openmp_constructs(can_assume)
{
#pragma omp parallel for
for (i = 0; i < N; ++i) {
A[i] = i + 1;
}
}

for (i = 0; i < N; ++i) {
sum += A[i];
A[i] = 0;
}

if (sum != N * (N + 1) / 2)
++errors;

sum = 0;
can_assume = 1;
#pragma omp assume no_openmp_constructs(can_assume)
{
for (i = 0; i < N; ++i) {
A[i] = 2 * (i + 1);
}
}

for (i = 0; i < N; ++i) {
sum += A[i];
A[i] = 0;
}
if (sum != 2 * N * (N + 1) / 2)
++errors;

sum = 0;
#pragma omp assume no_openmp_constructs()
{
for (i = 0; i < N; ++i) {
A[i] = 3 * (i + 1);
}
}

for (i = 0; i < N; ++i) {
sum += A[i];
}

if (sum != 3 * N * (N + 1) / 2)
++errors;

return errors;
}

int main() {
int errors = 0;
OMPVV_TEST_AND_SET(errors, test_assumes_no_openmp_constructs() != 0);
OMPVV_REPORT_AND_RETURN(errors);
return errors;
}