Skip to content

Commit

Permalink
Merge pull request #371 from SOLLVE/fix_issue_81_pt4
Browse files Browse the repository at this point in the history
Adding 3 new .F90 tests per issue #81 and fixing related .c files - pt 4
  • Loading branch information
tmh97 authored Jan 24, 2022
2 parents 0fc2bfa + 341a132 commit 4078a7c
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 6 deletions.
55 changes: 55 additions & 0 deletions tests/4.5/target_parallel/test_target_parallel.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
!===--- test_target_parallel.F90 --------------------------------------------===//
!
! OpenMP API Version 4.5 Nov 2015
!
! This test checks for the combined construct target and parallel. It
! creates a parallel region inside of the target devices.
!
!===-------------------------------------------------------------------------===//

#include "ompvv.F90"

#define N 1024

PROGRAM test_target_parallel
USE iso_fortran_env
USE ompvv_lib
USE omp_lib
implicit none

OMPVV_TEST_OFFLOADING

OMPVV_TEST_VERBOSE(target_parallel() .ne. 0)

OMPVV_REPORT_AND_RETURN()

CONTAINS
INTEGER FUNCTION target_parallel()
INTEGER :: errors, i, summation
INTEGER, DIMENSION(OMPVV_NUM_THREADS_DEVICE) :: thread_id
CHARACTER(len=400) :: threadMsg
errors = 0

DO i = 1, OMPVV_NUM_THREADS_DEVICE
thread_id(i) = 0
END DO

!$omp target parallel num_threads(OMPVV_NUM_THREADS_DEVICE) map(from: summation, thread_id)
thread_id(omp_get_thread_num() + 1) = omp_get_num_threads()
!$omp end target parallel


OMPVV_WARNING_IF(thread_id(1) .eq. 1, "The number of threads in the parallel region was 1. &
&This is not a specifications error but we could not confirm the parallel region.")

DO i = 1, thread_id(1)
OMPVV_TEST_AND_SET(errors, thread_id(i) .ne. thread_id(1))
WRITE (threadMsg, *) "The number of threads recorded by thread", i, &
& " was", thread_id(i), ". Expected was", thread_id(1)
OMPVV_INFOMSG(threadMsg)
END DO

target_parallel = errors
END FUNCTION target_parallel
END PROGRAM test_target_parallel

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
!===-- test_target_teams_distribute_parallel_for_num_teams.F90 ------------===//
!
! OpenMP API Version 4.5 Nov 2015
!
! Test to check the num_teams clause. This clause changes the upper limit of
! the number of teams inside the target teams region.
!
!===-------------------------------------------------------------------------===//

#include "ompvv.F90"
#define N 1024

PROGRAM test_target_teams_distribute_parallel_for_num_teams
USE iso_fortran_env
USE ompvv_lib
USE omp_lib
implicit none

OMPVV_TEST_VERBOSE(target_teams_distribute_parallel_for_num_teams() .ne. 0)

OMPVV_REPORT_AND_RETURN()

CONTAINS
INTEGER FUNCTION target_teams_distribute_parallel_for_num_teams()
INTEGER :: errors, i, nt, raiseWarningOneTeam, raiseWarningDifNum, prevNumTeams
INTEGER, DIMENSION(4) :: tested_num_teams = (/1, 10, 100, 10000/)
INTEGER, DIMENSION(N) :: num_teams
CHARACTER(len=400) :: numTeamsMsg, difNumReportedMsg, difNumTeamsMsg
errors = 0
i = 0
raiseWarningOneTeam = 0

DO nt = 1, 4
WRITE(numTeamsMsg, *) "Testing for num_teams(", tested_num_teams(nt), ")"
OMPVV_INFOMSG(numTeamsMsg)

! initialize the num_teams array
DO i = 1, N
num_teams(i) = -1
END DO

!$omp target teams distribute parallel do map(tofrom: num_teams) num_teams(tested_num_teams(nt))
DO i = 1, N
num_teams(i) = omp_get_num_teams()
END DO

raiseWarningDifNum = 0
prevNumTeams = -1

DO i = 1, N
WRITE(difNumReportedMsg, *) num_teams(i), "teams reported"
OMPVV_INFOMSG_IF(prevNumTeams .ne. num_teams(i), difNumReportedMsg)
prevNumTeams = num_teams(i)
OMPVV_TEST_AND_SET(errors, num_teams(i) .le. 0 .or. (num_teams(i) .gt. tested_num_teams(nt)))
IF (num_teams(i) .ne. tested_num_teams(nt)) THEN
raiseWarningDifNum = 1
END IF
IF (num_teams(i) == 1) THEN
raiseWarningOneTeam = raiseWarningOneTeam + 1
END IF
END DO

!We want to raise a warning when the number of teams does not match the desired value
WRITE(difNumTeamsMsg, *) "When testing for num_teams(", tested_num_teams(nt), "), the actual &
&number of teams was different. Not a compliance error with the specification."
OMPVV_WARNING_IF(raiseWarningDifNum .ne. 0, difNumTeamsMsg)
END DO

OMPVV_WARNING_IF(raiseWarningOneTeam .eq. 4*N, "The num_teams clause always resulted in a single team. Although &
&this is compliant with the specification, it is not expected.")

target_teams_distribute_parallel_for_num_teams = errors
END FUNCTION target_teams_distribute_parallel_for_num_teams
END PROGRAM test_target_teams_distribute_parallel_for_num_teams

Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include "ompvv.h"
#include <stdio.h>

#define SIZE_N 1024
#define N 1024

int test_target_teams_distribute_parallel_for_num_teams() {
OMPVV_INFOMSG("test_target_teams_distribute_parallel_for_num_teams");

int tested_num_teams[] = {1, 10, 100, 10000};
int num_teams[SIZE_N]; // num_teams = 1 is not technically an error
int num_teams[N]; // num_teams = 1 is not technically an error
int errors = 0;
int i, nt;

Expand All @@ -28,19 +28,19 @@ int test_target_teams_distribute_parallel_for_num_teams() {

OMPVV_INFOMSG("Testing for num_teams(%d)", tested_num_teams[nt]);
// Initializing the num_teams array
for (i = 0; i < SIZE_N; i++) {
for (i = 0; i < N; i++) {
num_teams[i] = -1;
}
#pragma omp target teams distribute parallel for \
map(tofrom: num_teams) num_teams(tested_num_teams[nt])
for (i = 0; i < SIZE_N; i++) {
for (i = 0; i < N; i++) {
num_teams[i] = omp_get_num_teams();
}

int raiseWarningDifNum = 0;
int prevNumTeams = -1;

for (i = 0; i < SIZE_N; i++) {
for (i = 0; i < N; i++) {
OMPVV_INFOMSG_IF(prevNumTeams != num_teams[i], " %d teams reported", num_teams[i]);
prevNumTeams = num_teams[i];
// If the number of teams is larger than the specified, this is an error
Expand All @@ -55,7 +55,7 @@ int test_target_teams_distribute_parallel_for_num_teams() {
OMPVV_WARNING_IF(raiseWarningDifNum != 0, "When testing for num_teams(%d), the actual number of teams was different. Not a compliance error with the specs", tested_num_teams[nt]);
}

OMPVV_WARNING_IF(raiseWarningOneTeam == 4*SIZE_N, "The num_teams clause always resulted in a single team. Although this is complant with the specs, it is not expected");
OMPVV_WARNING_IF(raiseWarningOneTeam == 4*N, "The num_teams clause always resulted in a single team. Although this is complant with the specs, it is not expected");

return errors;
}
Expand Down
68 changes: 68 additions & 0 deletions tests/4.5/target_update/test_target_update_from.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
!===--- test_target_update_from.F90 -----------------------------------------===//
!
! OpenMP API Version 4.5 Nov 2015
!
! This test checks the target update motion clause 'from' by mapping an array
! to the device with map-type 'to', changing the values of array on the device,
! and finally using the update 'from' motion clause to assign the value of the
! list item. Back on the host, measures are taken to ensure the value was properly
! updated.
!
!===-------------------------------------------------------------------------===//

#include "ompvv.F90"

#define N 1024

PROGRAM test_target_update_from
USE iso_fortran_env
USE ompvv_lib
USE omp_lib
implicit none

OMPVV_TEST_OFFLOADING

OMPVV_TEST_VERBOSE(target_update_from() .ne. 0)

OMPVV_REPORT_AND_RETURN()

CONTAINS
INTEGER FUNCTION target_update_from()
INTEGER :: errors, i
INTEGER, DIMENSION(N) :: a, b, c
errors = 0
i = 0

DO i = 1, N
a(i) = 10
b(i) = 2
c(i) = 0
END DO

!$omp target enter data map(to: a, b)
!$omp target
DO i = 1, N
b(i) = (a(i) + b(i))
END DO
!$omp end target

!$omp target update from(b)

DO i = 1, N
OMPVV_TEST_AND_SET_VERBOSE(errors, b(i) .ne. 12)
END DO

!$omp target
DO i = 1, N
c(i) = (2 * b(i))
END DO
!$omp end target

DO i = 1, N
OMPVV_TEST_AND_SET_VERBOSE(errors, c(i) .ne. 24)
END DO

target_update_from = errors

END FUNCTION target_update_from
END PROGRAM test_target_update_from

0 comments on commit 4078a7c

Please sign in to comment.