MFIX  2016-1
parallel_mpi_mod.f
Go to the documentation of this file.
1  module parallel_mpi
2 
3 ! A module to carry out init, finalize and check for any parallel errors
4 
5  use geometry
6  use compar
7  implicit none
8 
9  contains
10 
11  subroutine parallel_init()
12  implicit none
13  integer :: ierr
14 
15  numpes = 1
16  mype = 0
17 
18 #ifdef MPI
19  call mpi_init(ierr)
20  call mpi_check( 'parallel_init:MPI_Init ', ierr)
21 
22  call mpi_comm_size( mpi_comm_world, numpes, ierr )
23  call mpi_check( 'parallel_init:MPI_Comm_size ', ierr )
24 
25  call mpi_comm_rank( mpi_comm_world, mype, ierr )
26  call mpi_check( 'parallel_init:MPI_Comm_size ', ierr )
27 #endif
28  return
29  end subroutine parallel_init
30 
31  subroutine parallel_fin()
32  implicit none
33 
34 #ifdef MPI
35  integer :: ierr
36 
37  call mpi_finalize(ierr)
38  call mpi_check( 'parallel_init:MPI_Finalize ', ierr)
39 #endif
40 
41  return
42  end subroutine parallel_fin
43 
44  subroutine mpi_check( msg, ierr )
45 #ifdef MPI
46  use mpi, only: mpi_success ! ignore-depcomp
47 #endif
48  implicit none
49  character(len=*),intent(in) :: msg
50  integer, intent(in) :: ierr
51 
52 #ifdef MPI
53  character(len=512) :: errmsg
54  integer :: resultlen, ierror
55 
56  if (ierr .ne. mpi_success ) then
57  call mpi_error_string( ierr, errmsg, resultlen, ierror )
58  print*, 'Error: ', msg
59  print*, errmsg(1:resultlen)
60  stop '** ERROR ** '
61  endif
62 #endif
63 
64  return
65  end subroutine mpi_check
66 
67 
68  end module parallel_mpi
69 
subroutine parallel_init()
integer numpes
Definition: compar_mod.f:24
subroutine parallel_fin()
subroutine mpi_check(msg, ierr)
integer mype
Definition: compar_mod.f:24