mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Fix MPI-related bugs
This commit is contained in:
parent
8f77f7ba06
commit
ebe5347636
7 changed files with 30 additions and 4 deletions
|
|
@ -433,6 +433,7 @@ set(LIBOPENMC_FORTRAN_SRC
|
|||
)
|
||||
set(LIBOPENMC_CXX_SRC
|
||||
src/initialize.cpp
|
||||
src/finalize.cpp
|
||||
src/hdf5_interface.cpp
|
||||
src/message_passing.cpp
|
||||
src/plot.cpp
|
||||
|
|
|
|||
|
|
@ -105,6 +105,11 @@ contains
|
|||
function openmc_finalize() result(err) bind(C)
|
||||
integer(C_INT) :: err
|
||||
|
||||
interface
|
||||
subroutine openmc_free_bank() bind(C)
|
||||
end subroutine openmc_free_bank
|
||||
end interface
|
||||
|
||||
! Clear results
|
||||
err = openmc_reset()
|
||||
|
||||
|
|
@ -170,6 +175,7 @@ contains
|
|||
#ifdef OPENMC_MPI
|
||||
! Free all MPI types
|
||||
call MPI_TYPE_FREE(MPI_BANK, err)
|
||||
call openmc_free_bank()
|
||||
#endif
|
||||
|
||||
end function openmc_finalize
|
||||
|
|
|
|||
10
src/finalize.cpp
Normal file
10
src/finalize.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "finalize.h"
|
||||
|
||||
#include "message_passing.h"
|
||||
|
||||
void openmc_free_bank()
|
||||
{
|
||||
#ifdef OPENMC_MPI
|
||||
MPI_Type_free(&openmc::mpi::bank);
|
||||
#endif
|
||||
}
|
||||
6
src/finalize.h
Normal file
6
src/finalize.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef FINALIZE_H
|
||||
#define FINALIZE_H
|
||||
|
||||
extern "C" void openmc_free_bank();
|
||||
|
||||
#endif // FINALIZE_H
|
||||
|
|
@ -1103,7 +1103,7 @@ contains
|
|||
character(*), intent(in), target :: buffer(:) ! read data to here
|
||||
logical, intent(in), optional :: indep ! independent I/O
|
||||
|
||||
integer :: i
|
||||
integer(HSIZE_T) :: i
|
||||
integer(HSIZE_T) :: dims(1)
|
||||
integer(C_SIZE_T) :: m, n
|
||||
logical(C_BOOL) :: indep_
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ void initialize_mpi(MPI_Comm intracomm)
|
|||
|
||||
// Initialize MPI
|
||||
int flag;
|
||||
if (!MPI_Initialized(&flag)) MPI_Init(nullptr, nullptr);
|
||||
MPI_Initialized(&flag);
|
||||
if (!flag) MPI_Init(nullptr, nullptr);
|
||||
|
||||
// Determine number of processes and rank for each
|
||||
MPI_Comm_size(intracomm, &openmc::mpi::n_procs);
|
||||
|
|
|
|||
|
|
@ -38,12 +38,14 @@ int main(int argc, char* argv[]) {
|
|||
err = openmc_calculate_volumes();
|
||||
break;
|
||||
}
|
||||
if (err) openmc::fatal_error(openmc_err_msg);
|
||||
|
||||
// Finalize and free up memory
|
||||
openmc_finalize();
|
||||
err = openmc_finalize();
|
||||
if (err) openmc::fatal_error(openmc_err_msg);
|
||||
|
||||
// If MPI is in use and enabled, terminate it
|
||||
#ifdef MPI
|
||||
#ifdef OPENMC_MPI
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue