PB3D  [2.45]
Ideal linear high-n MHD stability in 3-D
MPI_vars.f90
Go to the documentation of this file.
1 !------------------------------------------------------------------------------!
3 !------------------------------------------------------------------------------!
4 module mpi_vars
5 #include <PB3D_macros.h>
7  use str_utilities, only: i2str, r2str, r2strt
8  use mpi
9 
10  implicit none
11  private
12  public init_lock, dealloc_lock, &
13  &hdf5_lock
14 
63  type, public :: lock_type
64  integer, allocatable :: wl(:)
65  integer :: wl_win
66  integer :: wu_tag
67  logical :: blocking
68  contains
70  procedure :: init => init_lock
72  procedure :: dealloc => dealloc_lock
73  end type lock_type
74 
75  ! global variables
77 
78 contains
86  integer function init_lock(lock_loc,wu_tag) result(ierr)
87  use num_vars, only: n_procs, rank
88 
89  character(*), parameter :: rout_name = 'init_lock'
90 
91  ! input / output
92  class(lock_type), intent(inout) :: lock_loc
93  integer, intent(in) :: wu_tag
94 
95  ! local variables
96  integer(kind=MPI_ADDRESS_KIND) :: intlb ! lower bound of int type
97  integer(kind=MPI_ADDRESS_KIND) :: intex ! extent of int type
98 
99  ! initialize ierr
100  ierr = 0
101 
102  call mpi_type_get_extent(mpi_integer,intlb,intex,ierr)
103  chckerr('Failed to get extent of int')
104 
105  if (rank.eq.0) then ! master
106  allocate(lock_loc%wl(n_procs))
107 
108  lock_loc%wl = 0
109  call mpi_win_create(lock_loc%wl,n_procs*intex,int(intex),&
110  &mpi_info_null,mpi_comm_world,lock_loc%wl_win,ierr)
111  chckerr('Failed to create window to lock_loc')
112  else
113  allocate(lock_loc%wl(0))
114 
115  call mpi_win_create(lock_loc%wl,0*intex,int(intex),mpi_info_null,&
116  &mpi_comm_world,lock_loc%wl_win,ierr)
117  chckerr('Failed to create window to lock_loc')
118  end if
119 
120  lock_loc%wu_tag = wu_tag
121 
122  ! set fences
123  call mpi_win_fence(0,lock_loc%wl_win,ierr)
124  chckerr('Couldn''t set fence')
125  end function init_lock
126 
132  integer function dealloc_lock(lock_loc) result(ierr)
133  character(*), parameter :: rout_name = 'dealloc_lock'
134 
135  ! input / output
136  class(lock_type), intent(inout) :: lock_loc
137 
138  ! initialize ierr
139  ierr = 0
140 
141  ! free lock window
142  call mpi_win_free(lock_loc%wl_win,ierr)
143  chckerr('Failed to free window to HDF5_lock')
144 
145  ! deallocate lock
146  deallocate(lock_loc%wl)
147  end function dealloc_lock
148 end module mpi_vars
num_vars::dp
integer, parameter, public dp
double precision
Definition: num_vars.f90:46
num_vars::script_dir
character(len=7), public script_dir
directory where to save scripts for plots
Definition: num_vars.f90:154
num_vars
Numerical variables used by most other modules.
Definition: num_vars.f90:4
num_vars::max_str_ln
integer, parameter, public max_str_ln
maximum length of strings
Definition: num_vars.f90:50
str_utilities::i2str
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
Definition: str_utilities.f90:18
num_vars::n_procs
integer, public n_procs
nr. of MPI processes
Definition: num_vars.f90:69
num_vars::data_dir
character(len=4), public data_dir
directory where to save data for plots
Definition: num_vars.f90:155
str_utilities
Operations on strings.
Definition: str_utilities.f90:4
str_utilities::r2strt
elemental character(len=max_str_ln) function, public r2strt(k)
Convert a real (double) to string.
Definition: str_utilities.f90:54
mpi_vars
Variables pertaining to MPI.
Definition: MPI_vars.f90:4
mpi_vars::lock_type
lock type
Definition: MPI_vars.f90:63
str_utilities::r2str
elemental character(len=max_str_ln) function, public r2str(k)
Convert a real (double) to string.
Definition: str_utilities.f90:42
mpi_vars::init_lock
integer function, public init_lock(lock_loc, wu_tag)
Initializes a lock.
Definition: MPI_vars.f90:87
num_vars::plot_dir
character(len=5), public plot_dir
directory where to save plots
Definition: num_vars.f90:153
mpi_vars::dealloc_lock
integer function, public dealloc_lock(lock_loc)
Deallocates a lock.
Definition: MPI_vars.f90:133
mpi_vars::hdf5_lock
type(lock_type), public hdf5_lock
HDF5 lock.
Definition: MPI_vars.f90:76
num_vars::rank
integer, public rank
MPI rank.
Definition: num_vars.f90:68