OpenMP-Validation-and-Verification / OpenMP_VV

OpenMP Offloading Validation & Verification Suite; Official repository. We have migrated from bitbucket!! For documentation, results, publication and presentations, please check out our website ->
https://crpl.cis.udel.edu/ompvvsollve/
Other
54 stars 19 forks source link

Add new_test/5.1/metadirective/test_metadirective_nothing.F90 #771

Closed seyonglee closed 10 months ago

seyonglee commented 1 year ago

[Results on Summit]

andrewkallai commented 1 year ago

This test should consider the actual number of threads in a parallel region since omp_in_parallel() will return true only if it is enclosed by an active parallel region, which is executed by a team consisting of more than one thread (I assume this applies to Fortran as well). Otherwise, if the nothing directive is not executed, the parallel for will be executed, but this fact will not be verified with single threaded execution (as omp_in_parallel() returns false).

seyonglee commented 1 year ago

This test should consider the actual number of threads in a parallel region since omp_in_parallel() will return true only if it is enclosed by an active parallel region, which is executed by a team consisting of more than one thread (I assume this applies to Fortran as well). Otherwise, if the nothing directive is not executed, the parallel for will be executed, but this fact will not be verified with single threaded execution (as omp_in_parallel() returns false).

As you said, omp_in_parallel() will return true only if it is enclosed by an active parallel region. However, checking the actual number of threads in a parallel region does not help since we cannot know whether the nothing directive is executed or parallel for directive is executed. (i.e., even if the actual number of threads is 1, we don't know it is because nothing directive is selected or because parallel for construct is executed by a single thread.)

andrewkallai commented 1 year ago

It is true that it is not clear if parallel for was exectued single threaded or the nothing directive was executed. For that reason, I think it makes sense to still add a check for the number of threads to state that the results of the test cannot be verified if the test is running single threaded. Adding this code after the variable definitions of each function could achieve this:

!beginning of function metadirectiveOnTYPE
INTEGER :: num_threads
!$omp parallel
IF(omp_get_thread_num() .EQ. 0) THEN
  num_threads = omp_get_num_threads()
END IF
!$omp end parallel

IF (num_threads .EQ. 1) THEN
  OMPVV_WARNING("test is running single threaded, results cannot be verified")
ELSE
  !code for test here
ENDIF
!return with errors count
spophale commented 11 months ago

@seyonglee will add checks for omp_get_max_threads and set num_threads for parallel regions.

seyonglee commented 11 months ago

Now, the C test uses thread-limit-var ICV and omp_get_thread_limit() API, while the Fortran test uses nthreads-var ICV and omp_get_max_threads() API; each approach has its limit. We should decide which one to use.

seyonglee commented 10 months ago

Now, the C test uses thread-limit-var ICV and omp_get_thread_limit() API, while the Fortran test uses nthreads-var ICV and omp_get_max_threads() API; each approach has its limit. We should decide which one to use.

OpenMP Version 5.1, Section 2.4.4.1 How the Per-Data Environment ICVs Work says the following:

If a teams construct with a thread_limit clause is encountered, the thread-limit-var ICV from the data environment of the initial task for each team is instead set to an implementation defined value between one and the value specified in the clause.

This means that the actual value of thread-limit-var can be smaller than the value in the thread_limit clause, in which case, we may not be able to check whether the thread_limit clause is applied or not.