Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion MAPL/MAPL.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module MAPL
use MAPL_ESMFFieldBundleRead
use MAPL_ESMFFieldBundleWrite
use MAPL_OpenMP_Support, only : MAPL_get_current_thread => get_current_thread
use MAPL_OpenMP_Support, only : MAPL_get_num_threads => get_num_threads
use MAPL_OpenMP_Support, only : MAPL_find_bounds => find_bounds
use MAPL_OpenMP_Support, only : MAPL_Interval => Interval
use MAPL_Profiler, initialize_profiler =>initialize, finalize_profiler =>finalize
Expand Down
7 changes: 6 additions & 1 deletion Tests/GetHorzIJIndex/GridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module GridComp

use ESMF
use MAPL
!$ use omp_lib

implicit none
private
Expand All @@ -29,6 +30,10 @@ subroutine setservices(gc,rc)
call ESMF_GridCompGet(gc, config=cf, _RC)
call ESMF_ConfigGetAttribute(cf, use_threads, label='use_threads:', default=.FALSE., _RC)
call MAPL%set_use_threads(use_threads)
call ESMF_ConfigGetAttribute(cf, num_threads, label='num_threads:', default=1, _RC)
num_threads = 1
!$ if (use_threads) num_threads = omp_get_max_threads()
call MAPL%set_num_threads(num_threads)

call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_INITIALIZE, initialize, _RC)
call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_RUN, run, _RC)
Expand All @@ -51,7 +56,7 @@ subroutine initialize(gc, import, export, clock, rc)

call MAPL_GridCreate(gc, _RC)
call MAPL_GetObjectFromGC (gc, MAPL, _RC)
print *, 'Num threads = ', MAPL_get_num_threads(), ' for this run'
print *, 'Num threads = ', MAPL%get_num_threads(), ' for this run'
call MAPL_GenericInitialize(gc, import, export, clock, _RC)

_RETURN(_SUCCESS)
Expand Down
7 changes: 4 additions & 3 deletions generic/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ end subroutine capture

! !INTERFACE:
subroutine omp_driver(GC, import, export, clock, RC)
use MAPL_OpenMP_Support, only : get_current_thread, get_num_threads
use MAPL_OpenMP_Support, only : get_current_thread

type (ESMF_GridComp), intent(inout) :: GC ! Gridded component
type (ESMF_State), intent(inout) :: import ! Import state
Expand Down Expand Up @@ -2037,7 +2037,7 @@ subroutine omp_driver(GC, import, export, clock, RC)
_VERIFY(userRC)
else
!call start_global_time_profiler('activate_threads')
num_threads = get_num_threads()
num_threads = MAPL%get_num_threads()
call MAPL%activate_threading(num_threads, _RC)
!call stop_global_time_profiler('activate_threads')
!call start_global_time_profiler('parallel')
Expand All @@ -2048,7 +2048,8 @@ subroutine omp_driver(GC, import, export, clock, RC)
user_statuses=0
!$omp parallel default(none), &
!$omp& private(thread, subimport, subexport, thread_gc), &
!$omp& shared(gc, statuses, user_statuses, clock, PHASE, MAPL)
!$omp& shared(gc, statuses, user_statuses, clock, PHASE, MAPL), &
!$omp& num_threads(num_threads)

thread = get_current_thread()

Expand Down
19 changes: 19 additions & 0 deletions generic/MaplGenericComponent.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ end subroutine UserMethod

logical :: threading_active = .FALSE.
logical :: use_threads = .FALSE.
integer :: num_threads = 1


contains
Expand All @@ -76,6 +77,8 @@ end subroutine UserMethod
procedure :: set_logger
procedure :: set_use_threads
procedure :: get_use_threads
procedure :: set_num_threads
procedure :: get_num_threads
procedure :: is_threading_active
procedure :: get_internal_state
procedure :: get_import_state
Expand Down Expand Up @@ -219,6 +222,14 @@ subroutine set_use_threads(this, use_threads)

end subroutine set_use_threads

subroutine set_num_threads(this, num_threads)
class(MaplGenericComponent), intent(inout) :: this
integer, intent(in) :: num_threads

this%num_threads = num_threads

end subroutine set_num_threads

function get_use_threads(this) result(use_threads)
class(MaplGenericComponent), intent(in) :: this
logical :: use_threads
Expand All @@ -227,6 +238,14 @@ function get_use_threads(this) result(use_threads)

end function get_use_threads

function get_num_threads(this) result(num_threads)
class(MaplGenericComponent), intent(in) :: this
integer :: num_threads

num_threads = this%num_threads

end function get_num_threads

function is_threading_active(this) result(threading_active)
class(MaplGenericComponent), intent(in) :: this
logical :: threading_active
Expand Down
6 changes: 0 additions & 6 deletions generic/OpenMP_Support.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module MAPL_OpenMP_Support
public :: find_bounds
public :: subset_array
public :: get_current_thread
public :: get_num_threads
public :: get_callbacks

type :: Interval
Expand Down Expand Up @@ -55,11 +54,6 @@ integer function get_current_thread() result(current_thread)
!$ current_thread = omp_get_thread_num() ! get the actual thread id if OpenMP is used
end function get_current_thread

integer function get_num_threads() result(num_threads)
num_threads = 1 ! default if OpenMP is not used
!$ num_threads = omp_get_max_threads() ! get the actual number of threads if OpenMP is used
end function get_num_threads

function make_subgrids_from_num_grids(primary_grid, num_grids, unusable, rc) result(subgrids)
type(ESMF_Grid), allocatable :: subgrids(:)
type(ESMF_Grid), intent(inout) :: primary_grid
Expand Down
Loading