setup.f90 Source File


This file depends on

sourcefile~~setup.f90~~EfferentGraph sourcefile~setup.f90 setup.f90 sourcefile~allocator.f90 allocator.f90 sourcefile~setup.f90->sourcefile~allocator.f90 sourcefile~allocator.f90~2 allocator.f90 sourcefile~setup.f90->sourcefile~allocator.f90~2 sourcefile~allocator.f90~3 allocator.f90 sourcefile~setup.f90->sourcefile~allocator.f90~3 sourcefile~backend.f90 backend.f90 sourcefile~setup.f90->sourcefile~backend.f90 sourcefile~backend.f90~2 backend.f90 sourcefile~setup.f90->sourcefile~backend.f90~2 sourcefile~backend.f90~3 backend.f90 sourcefile~setup.f90->sourcefile~backend.f90~3 sourcefile~backend.f90~4 backend.f90 sourcefile~setup.f90->sourcefile~backend.f90~4 sourcefile~common.f90 common.f90 sourcefile~setup.f90->sourcefile~common.f90 sourcefile~common.f90~2 common.f90 sourcefile~setup.f90->sourcefile~common.f90~2 sourcefile~common.f90~3 common.f90 sourcefile~setup.f90->sourcefile~common.f90~3 sourcefile~common.f90~4 common.f90 sourcefile~setup.f90->sourcefile~common.f90~4 sourcefile~errors.f90 errors.f90 sourcefile~setup.f90->sourcefile~errors.f90 sourcefile~logger.f90 logger.f90 sourcefile~setup.f90->sourcefile~logger.f90 sourcefile~mesh.f90 mesh.f90 sourcefile~setup.f90->sourcefile~mesh.f90 sourcefile~allocator.f90->sourcefile~allocator.f90~2 sourcefile~allocator.f90->sourcefile~common.f90~3 sourcefile~allocator.f90->sourcefile~mesh.f90 sourcefile~field.f90 field.f90 sourcefile~allocator.f90->sourcefile~field.f90 sourcefile~allocator.f90~2->sourcefile~common.f90~3 sourcefile~allocator.f90~2->sourcefile~field.f90 sourcefile~allocator.f90~3->sourcefile~allocator.f90~2 sourcefile~allocator.f90~3->sourcefile~common.f90~3 sourcefile~allocator.f90~3->sourcefile~logger.f90 sourcefile~allocator.f90~3->sourcefile~mesh.f90 sourcefile~allocator.f90~3->sourcefile~field.f90 sourcefile~backend.f90->sourcefile~allocator.f90~2 sourcefile~backend.f90->sourcefile~backend.f90~3 sourcefile~backend.f90->sourcefile~common.f90~2 sourcefile~backend.f90->sourcefile~common.f90~3 sourcefile~backend.f90->sourcefile~logger.f90 sourcefile~backend.f90->sourcefile~mesh.f90 sourcefile~exec_dist.f90~3 exec_dist.f90 sourcefile~backend.f90->sourcefile~exec_dist.f90~3 sourcefile~exec_thom.f90~3 exec_thom.f90 sourcefile~backend.f90->sourcefile~exec_thom.f90~3 sourcefile~backend.f90->sourcefile~field.f90 sourcefile~ordering.f90 ordering.f90 sourcefile~backend.f90->sourcefile~ordering.f90 sourcefile~poisson_fft.f90~3 poisson_fft.f90 sourcefile~backend.f90->sourcefile~poisson_fft.f90~3 sourcefile~sendrecv.f90~2 sendrecv.f90 sourcefile~backend.f90->sourcefile~sendrecv.f90~2 sourcefile~tdsops.f90~2 tdsops.f90 sourcefile~backend.f90->sourcefile~tdsops.f90~2 sourcefile~backend.f90~2->sourcefile~allocator.f90~2 sourcefile~backend.f90~2->sourcefile~backend.f90~3 sourcefile~backend.f90~2->sourcefile~common.f90~3 sourcefile~backend.f90~2->sourcefile~common.f90~4 sourcefile~backend.f90~2->sourcefile~logger.f90 sourcefile~backend.f90~2->sourcefile~mesh.f90 sourcefile~device_info.f90 device_info.f90 sourcefile~backend.f90~2->sourcefile~device_info.f90 sourcefile~exec_dist.f90 exec_dist.f90 sourcefile~backend.f90~2->sourcefile~exec_dist.f90 sourcefile~exec_thom.f90~2 exec_thom.f90 sourcefile~backend.f90~2->sourcefile~exec_thom.f90~2 sourcefile~backend.f90~2->sourcefile~field.f90 sourcefile~fieldops.f90~2 fieldops.f90 sourcefile~backend.f90~2->sourcefile~fieldops.f90~2 sourcefile~sendrecv.f90 sendrecv.f90 sourcefile~backend.f90~2->sourcefile~sendrecv.f90 sourcefile~backend.f90~2->sourcefile~tdsops.f90~2 sourcefile~tdsops.f90~3 tdsops.f90 sourcefile~backend.f90~2->sourcefile~tdsops.f90~3 sourcefile~backend.f90~3->sourcefile~allocator.f90~2 sourcefile~backend.f90~3->sourcefile~common.f90~3 sourcefile~backend.f90~3->sourcefile~logger.f90 sourcefile~backend.f90~3->sourcefile~mesh.f90 sourcefile~backend.f90~3->sourcefile~field.f90 sourcefile~poisson_fft.f90~2 poisson_fft.f90 sourcefile~backend.f90~3->sourcefile~poisson_fft.f90~2 sourcefile~backend.f90~3->sourcefile~tdsops.f90~2 sourcefile~backend.f90~4->sourcefile~allocator.f90 sourcefile~backend.f90~4->sourcefile~allocator.f90~2 sourcefile~backend.f90~4->sourcefile~backend.f90~3 sourcefile~backend.f90~4->sourcefile~common.f90 sourcefile~backend.f90~4->sourcefile~common.f90~3 sourcefile~backend.f90~4->sourcefile~errors.f90 sourcefile~backend.f90~4->sourcefile~logger.f90 sourcefile~backend.f90~4->sourcefile~mesh.f90 sourcefile~distributed.f90~3 distributed.f90 sourcefile~backend.f90~4->sourcefile~distributed.f90~3 sourcefile~exec_dist.f90~2 exec_dist.f90 sourcefile~backend.f90~4->sourcefile~exec_dist.f90~2 sourcefile~exec_thom.f90 exec_thom.f90 sourcefile~backend.f90~4->sourcefile~exec_thom.f90 sourcefile~backend.f90~4->sourcefile~field.f90 sourcefile~fieldops.f90 fieldops.f90 sourcefile~backend.f90~4->sourcefile~fieldops.f90 sourcefile~poisson_fft.f90 poisson_fft.f90 sourcefile~backend.f90~4->sourcefile~poisson_fft.f90 sourcefile~reorder.f90 reorder.f90 sourcefile~backend.f90~4->sourcefile~reorder.f90 sourcefile~sendrecv.f90~3 sendrecv.f90 sourcefile~backend.f90~4->sourcefile~sendrecv.f90~3 sourcefile~tdsops.f90 tdsops.f90 sourcefile~backend.f90~4->sourcefile~tdsops.f90 sourcefile~backend.f90~4->sourcefile~tdsops.f90~2 sourcefile~common.f90~3->sourcefile~logger.f90 sourcefile~common.f90~4->sourcefile~common.f90~3 sourcefile~common.f90~4->sourcefile~logger.f90 sourcefile~errors.f90->sourcefile~logger.f90 sourcefile~mesh.f90->sourcefile~common.f90~3 sourcefile~mesh.f90->sourcefile~logger.f90 sourcefile~decomp_dummy.f90 decomp_dummy.f90 sourcefile~mesh.f90->sourcefile~decomp_dummy.f90 sourcefile~mesh.f90->sourcefile~field.f90 sourcefile~mesh_content.f90 mesh_content.f90 sourcefile~mesh.f90->sourcefile~mesh_content.f90 sourcefile~decomp_dummy.f90->sourcefile~logger.f90 sourcefile~decomp_dummy.f90->sourcefile~mesh_content.f90 sourcefile~distributed.f90~3->sourcefile~common.f90~3 sourcefile~exec_dist.f90->sourcefile~common.f90~3 sourcefile~exec_dist.f90->sourcefile~common.f90~4 sourcefile~exec_dist.f90->sourcefile~logger.f90 sourcefile~exec_dist.f90->sourcefile~sendrecv.f90 sourcefile~exec_dist.f90->sourcefile~tdsops.f90~3 sourcefile~distributed.f90 distributed.f90 sourcefile~exec_dist.f90->sourcefile~distributed.f90 sourcefile~exec_dist.f90~2->sourcefile~common.f90 sourcefile~exec_dist.f90~2->sourcefile~common.f90~3 sourcefile~exec_dist.f90~2->sourcefile~distributed.f90~3 sourcefile~exec_dist.f90~2->sourcefile~sendrecv.f90~3 sourcefile~exec_dist.f90~2->sourcefile~tdsops.f90 sourcefile~exec_dist.f90~3->sourcefile~common.f90~2 sourcefile~exec_dist.f90~3->sourcefile~common.f90~3 sourcefile~exec_dist.f90~3->sourcefile~sendrecv.f90~2 sourcefile~exec_dist.f90~3->sourcefile~tdsops.f90~2 sourcefile~distributed.f90~2 distributed.f90 sourcefile~exec_dist.f90~3->sourcefile~distributed.f90~2 sourcefile~exec_thom.f90->sourcefile~common.f90~3 sourcefile~exec_thom.f90->sourcefile~tdsops.f90 sourcefile~thomas.f90~2 thomas.f90 sourcefile~exec_thom.f90->sourcefile~thomas.f90~2 sourcefile~exec_thom.f90~2->sourcefile~common.f90~3 sourcefile~exec_thom.f90~2->sourcefile~tdsops.f90~3 sourcefile~thomas.f90 thomas.f90 sourcefile~exec_thom.f90~2->sourcefile~thomas.f90 sourcefile~exec_thom.f90~3->sourcefile~common.f90~3 sourcefile~exec_thom.f90~3->sourcefile~tdsops.f90~2 sourcefile~thomas.f90~3 thomas.f90 sourcefile~exec_thom.f90~3->sourcefile~thomas.f90~3 sourcefile~field.f90->sourcefile~common.f90~3 sourcefile~fieldops.f90->sourcefile~common.f90 sourcefile~fieldops.f90->sourcefile~common.f90~3 sourcefile~fieldops.f90~2->sourcefile~common.f90~3 sourcefile~fieldops.f90~2->sourcefile~common.f90~4 sourcefile~mesh_content.f90->sourcefile~common.f90~3 sourcefile~mesh_content.f90->sourcefile~logger.f90 sourcefile~ordering.f90->sourcefile~common.f90~3 sourcefile~poisson_fft.f90->sourcefile~allocator.f90 sourcefile~poisson_fft.f90->sourcefile~common.f90~3 sourcefile~poisson_fft.f90->sourcefile~errors.f90 sourcefile~poisson_fft.f90->sourcefile~logger.f90 sourcefile~poisson_fft.f90->sourcefile~mesh.f90 sourcefile~poisson_fft.f90->sourcefile~field.f90 sourcefile~poisson_fft.f90->sourcefile~poisson_fft.f90~2 sourcefile~poisson_fft.f90->sourcefile~sendrecv.f90~3 sourcefile~poisson_fft.f90->sourcefile~tdsops.f90~2 sourcefile~spectral_processing.f90 spectral_processing.f90 sourcefile~poisson_fft.f90->sourcefile~spectral_processing.f90 sourcefile~poisson_fft.f90~2->sourcefile~common.f90~3 sourcefile~poisson_fft.f90~2->sourcefile~logger.f90 sourcefile~poisson_fft.f90~2->sourcefile~mesh.f90 sourcefile~poisson_fft.f90~2->sourcefile~field.f90 sourcefile~poisson_fft.f90~2->sourcefile~tdsops.f90~2 sourcefile~poisson_fft.f90~3->sourcefile~common.f90~3 sourcefile~poisson_fft.f90~3->sourcefile~logger.f90 sourcefile~poisson_fft.f90~3->sourcefile~mesh.f90 sourcefile~poisson_fft.f90~3->sourcefile~field.f90 sourcefile~poisson_fft.f90~3->sourcefile~poisson_fft.f90~2 sourcefile~poisson_fft.f90~3->sourcefile~tdsops.f90~2 sourcefile~spectral_processing.f90~2 spectral_processing.f90 sourcefile~poisson_fft.f90~3->sourcefile~spectral_processing.f90~2 sourcefile~reorder.f90->sourcefile~common.f90 sourcefile~reorder.f90->sourcefile~common.f90~3 sourcefile~sendrecv.f90->sourcefile~common.f90~3 sourcefile~sendrecv.f90->sourcefile~common.f90~4 sourcefile~sendrecv.f90~2->sourcefile~common.f90~3 sourcefile~sendrecv.f90~2->sourcefile~logger.f90 sourcefile~sendrecv.f90~3->sourcefile~common.f90~3 sourcefile~sendrecv.f90~3->sourcefile~errors.f90 sourcefile~sendrecv.f90~3->sourcefile~logger.f90 sourcefile~tdsops.f90->sourcefile~common.f90~3 sourcefile~tdsops.f90->sourcefile~tdsops.f90~2 sourcefile~tdsops.f90~2->sourcefile~common.f90~3 sourcefile~tdsops.f90~2->sourcefile~logger.f90 sourcefile~tdsops.f90~3->sourcefile~common.f90~3 sourcefile~tdsops.f90~3->sourcefile~common.f90~4 sourcefile~tdsops.f90~3->sourcefile~tdsops.f90~2 sourcefile~distributed.f90->sourcefile~common.f90~3 sourcefile~distributed.f90->sourcefile~common.f90~4 sourcefile~distributed.f90~2->sourcefile~common.f90~2 sourcefile~distributed.f90~2->sourcefile~common.f90~3 sourcefile~spectral_processing.f90->sourcefile~common.f90~3 sourcefile~spectral_processing.f90~2->sourcefile~common.f90~3 sourcefile~spectral_processing.f90~2->sourcefile~logger.f90 sourcefile~thomas.f90->sourcefile~common.f90~3 sourcefile~thomas.f90->sourcefile~common.f90~4 sourcefile~thomas.f90~2->sourcefile~common.f90~3 sourcefile~thomas.f90~3->sourcefile~common.f90~2 sourcefile~thomas.f90~3->sourcefile~common.f90~3

Files dependent on this one

sourcefile~~setup.f90~~AfferentGraph sourcefile~setup.f90 setup.f90 sourcefile~xcompact.f90 xcompact.f90 sourcefile~xcompact.f90->sourcefile~setup.f90

Source Code

module m_backend_setup
  !! Creates the backend and allocators for the backend this build targets,
  !! so that the solver driver (xcompact.f90) needs no backend-specific code.
  use m_mpi, only: MPI_COMM_WORLD, MPI_Comm_rank

  use m_allocator, only: allocator_t
  use m_base_backend, only: base_backend_t
  use m_common, only: VERT
  use m_logger, only: log_info, abort_run
  use m_mesh, only: mesh_t

#ifdef CUDA
  use cudafor
  use m_cuda_allocator, only: cuda_allocator_t
  use m_cuda_backend, only: cuda_backend_t
  use m_cuda_common, only: SZ
  use m_cuda_errors, only: check_cuda
#elif defined(OMP_TGT)
  use omp_lib, only: omp_get_num_devices, omp_set_default_device
  use m_omptgt_allocator, only: omptgt_allocator_t
  use m_omptgt_backend, only: omptgt_backend_t
  use m_omptgt_common, only: SZ
#else
  use m_omp_backend, only: omp_backend_t
  use m_omp_common, only: SZ
#endif

  implicit none

  private
  public :: backend_setup_t, backend_name

#ifdef CUDA
  character(len=*), parameter :: backend_name = 'CUDA'
#elif defined(OMP_TGT)
  character(len=*), parameter :: backend_name = 'OMP_TGT'
#else
  character(len=*), parameter :: backend_name = 'OMP'
#endif

  type :: backend_setup_t
    !! Owns the backend and allocators.  The pointer components alias
    !! concrete members of this same object, so instances must be declared
    !! with the TARGET attribute and must never be copied or assigned.
    class(base_backend_t), pointer :: backend => null()
    class(allocator_t), pointer :: allocator => null()
    type(allocator_t), pointer :: host_allocator => null()
#ifdef CUDA
    type(cuda_backend_t) :: cuda_backend
    type(cuda_allocator_t) :: cuda_allocator
#elif defined(OMP_TGT)
    type(omptgt_backend_t) :: omptgt_backend
    type(omptgt_allocator_t) :: omptgt_allocator
#else
    type(omp_backend_t) :: omp_backend
#endif
    type(allocator_t) :: omp_allocator
  contains
    procedure :: init
  end type backend_setup_t

contains

  subroutine init(self, mesh)
    class(backend_setup_t), target, intent(inout) :: self
    type(mesh_t), target, intent(inout) :: mesh

    integer :: dims(3), nrank, ierr

    call MPI_Comm_rank(MPI_COMM_WORLD, nrank, ierr)
    call select_device(nrank)

    ! get local vertex dimensions
    dims = mesh%get_dims(VERT)
#ifdef CUDA
    self%cuda_allocator = cuda_allocator_t(dims, SZ)
    self%allocator => self%cuda_allocator
    call log_info('CUDA allocator instantiated')

    self%omp_allocator = allocator_t(dims, SZ)
    self%host_allocator => self%omp_allocator

    self%cuda_backend = cuda_backend_t(mesh, self%allocator)
    self%backend => self%cuda_backend
    call log_info('CUDA backend instantiated')
#elif defined(OMP_TGT)
    self%omptgt_allocator = omptgt_allocator_t(dims, SZ)
    self%allocator => self%omptgt_allocator
    call log_info('OpenMP target allocator instantiated')

    self%omp_allocator = allocator_t(dims, SZ)
    self%host_allocator => self%omp_allocator

    self%omptgt_backend = omptgt_backend_t(mesh, self%allocator)
    self%backend => self%omptgt_backend
    call log_info('OpenMP target backend instantiated')
#else
    self%omp_allocator = allocator_t(dims, SZ)
    self%allocator => self%omp_allocator
    self%host_allocator => self%omp_allocator
    call log_info('OpenMP allocator instantiated')

    self%omp_backend = omp_backend_t(mesh, self%allocator)
    self%backend => self%omp_backend
    call log_info('OpenMP backend instantiated')
#endif
  end subroutine init

  subroutine select_device(nrank)
    !! Select a device round-robin by MPI rank; a no-op on the CPU backend.
    integer, intent(in) :: nrank

#ifdef CUDA
    integer :: ierr, ndevs

    ierr = cudaGetDeviceCount(ndevs)
    call check_cuda(ierr, 'cudaGetDeviceCount')
    if (ndevs < 1) call abort_run('select_device: no CUDA devices available')
    ierr = cudaSetDevice(mod(nrank, ndevs))
    call check_cuda(ierr, 'cudaSetDevice')
#elif defined(OMP_TGT)
    integer :: ndevs

    ndevs = omp_get_num_devices()
    if (ndevs < 1) call abort_run('select_device: no OpenMP target devices &
                                  &available')
    call omp_set_default_device(mod(nrank, ndevs))
#endif
  end subroutine select_device

end module m_backend_setup