Program x06ajfe
! X06AJF Example Program Text
! Mark 30.2 Release. NAG Copyright 2024.
! .. Use Statements ..
Use nag_library, Only: x06aaf, x06abf, x06ajf, x06akf
! .. Implicit None Statement ..
Implicit None
! .. Local Scalars ..
Integer :: ifail, inner_num, inner_threads, &
max_active_levels, outer_threads, &
total, total_2, total_3
! .. Executable Statements ..
! Initialise totals
total = 0
total_2 = 0
total_3 = 0
! Set number of threads for inner and outer parallel regions
inner_threads = 7
outer_threads = 3
ifail = 0
Call x06aaf(outer_threads,ifail)
! Testing implementation default behaviour
!$Omp Parallel Shared (inner_threads,total,inner_num,ifail), &
!$Omp Default (None)
!$Omp Master
Write (*,99997) 'Implementation max active levels default:', &
x06akf()
Write (*,99998) 'No. threads in 1st parallel region:', x06abf()
!$Omp End Master
ifail = 0
!$Omp Barrier
Call x06aaf(inner_threads,ifail)
!$Omp Parallel Shared (total,inner_num), Default (None)
! Get max number of threads inside second active parallel region
inner_num = x06abf()
!$Omp Atomic
total = total + 1
!$Omp End Atomic
!$Omp End Parallel
!$Omp Master
Write (*,99998) 'No. threads in 2nd parallel region:', inner_num
!$Omp End Master
!$Omp End Parallel
Write (*,99999) 'Total threads:', total
Write (*,*)
Write (*,*)
! Set max active parallel regions
max_active_levels = 2
ifail = 0
Call x06ajf(max_active_levels,ifail)
! Set number of threads for inner and outer parallel regions
inner_threads = 7
outer_threads = 3
ifail = 0
Call x06aaf(outer_threads,ifail)
! Testing with max active levels set to 2
!$Omp Parallel Shared (inner_threads,total_2,inner_num,ifail, &
!$Omp max_active_levels), Default (None)
!$Omp Master
Write (*,99996) 'Max active levels set to:', max_active_levels
Write (*,99995) 'x06ak return value:', x06akf()
Write (*,99998) 'No. threads in 1st parallel region:', x06abf()
!$Omp End Master
ifail = 0
!$Omp Barrier
Call x06aaf(inner_threads,ifail)
!$Omp Parallel Shared (total_2,inner_num), Default (None)
! Get max number of threads inside second active parallel region
inner_num = x06abf()
!$Omp Atomic
total_2 = total_2 + 1
!$Omp End Atomic
!$Omp End Parallel
!$Omp Master
Write (*,99998) 'No. threads in 2nd parallel region:', inner_num
!$Omp End Master
!$Omp End Parallel
Write (*,99999) 'Total threads:', total_2
Write (*,*)
Write (*,*)
! Set max active parallel regions
max_active_levels = 1
ifail = 0
Call x06ajf(max_active_levels,ifail)
! Testing with max active levels set to 1
!$Omp Parallel Shared (inner_threads,total_3,inner_num,ifail, &
!$Omp max_active_levels), Default (None)
!$Omp Master
Write (*,99996) 'Max active levels set to:', max_active_levels
Write (*,99995) 'x06ak return value:', x06akf()
Write (*,99998) 'No. threads in 1st parallel region:', x06abf()
!$Omp End Master
ifail = 0
!$Omp Barrier
Call x06aaf(inner_threads,ifail)
!$Omp Parallel Shared (total_3,inner_num), Default (None)
! Get max number of threads inside second active parallel region
inner_num = x06abf()
!$Omp Atomic
total_3 = total_3 + 1
!$Omp End Atomic
!$Omp End Parallel
!$Omp Master
Write (*,99998) 'No. threads in 2nd parallel region:', inner_num
!$Omp End Master
!$Omp End Parallel
Write (*,99999) 'Total threads:', total_3
99999 Format (4X,A,I35)
99998 Format (4X,A,I14)
99997 Format (1X,A,I11)
99996 Format (4X,A,I24)
99995 Format (4X,A,I30)
End Program x06ajfe