mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Have openmc_init take a MPI_Comm*
This commit is contained in:
parent
64fa01f537
commit
9b8cb2e0f1
8 changed files with 61 additions and 27 deletions
|
|
@ -434,6 +434,7 @@ set(LIBOPENMC_FORTRAN_SRC
|
|||
)
|
||||
set(LIBOPENMC_CXX_SRC
|
||||
src/error.h
|
||||
src/initialize.cpp
|
||||
src/hdf5_interface.h
|
||||
src/hdf5_interface.cpp
|
||||
src/random_lcg.cpp
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
#include "mpi.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
@ -46,7 +50,8 @@ extern "C" {
|
|||
int64_t openmc_get_seed();
|
||||
int openmc_get_tally_index(int32_t id, int32_t* index);
|
||||
void openmc_hard_reset();
|
||||
void openmc_init(const int* intracomm);
|
||||
int openmc_init(const void* intracomm);
|
||||
int openmc_init_f(const int* intracomm);
|
||||
int openmc_legendre_filter_get_order(int32_t index, int* order);
|
||||
int openmc_legendre_filter_set_order(int32_t index, int order);
|
||||
int openmc_load_nuclide(char name[]);
|
||||
|
|
@ -145,6 +150,11 @@ extern "C" {
|
|||
extern bool openmc_simulation_initialized;
|
||||
extern int openmc_verbosity;
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
// MPI variables
|
||||
extern MPI_Comm openmc_intracomm;
|
||||
#endif
|
||||
|
||||
// Run modes
|
||||
constexpr int RUN_MODE_FIXEDSOURCE {1};
|
||||
constexpr int RUN_MODE_EIGENVALUE {2};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from contextlib import contextmanager
|
||||
from ctypes import (CDLL, c_int, c_int32, c_int64, c_double, c_char_p,
|
||||
POINTER, Structure)
|
||||
POINTER, Structure, c_void_p)
|
||||
from warnings import warn
|
||||
|
||||
import numpy as np
|
||||
|
|
@ -27,7 +27,7 @@ _dll.openmc_find.argtypes = [POINTER(c_double*3), c_int, POINTER(c_int32),
|
|||
_dll.openmc_find.restype = c_int
|
||||
_dll.openmc_find.errcheck = _error_handler
|
||||
_dll.openmc_hard_reset.restype = None
|
||||
_dll.openmc_init.argtypes = [POINTER(c_int)]
|
||||
_dll.openmc_init.argtypes = [c_void_p]
|
||||
_dll.openmc_init.restype = None
|
||||
_dll.openmc_get_keff.argtypes = [POINTER(c_double*2)]
|
||||
_dll.openmc_get_keff.restype = c_int
|
||||
|
|
@ -116,13 +116,11 @@ def init(intracomm=None):
|
|||
|
||||
"""
|
||||
if intracomm is not None:
|
||||
# If an mpi4py communicator was passed, convert it to an integer to
|
||||
# be passed to openmc_init
|
||||
try:
|
||||
intracomm = intracomm.py2f()
|
||||
except AttributeError:
|
||||
pass
|
||||
_dll.openmc_init(c_int(intracomm))
|
||||
# If an mpi4py communicator was passed, convert it to void* to be passed
|
||||
# to openmc_init
|
||||
from mpi4py import MPI
|
||||
address = MPI._addressof(intracomm)
|
||||
_dll.openmc_init(c_void_p(address))
|
||||
else:
|
||||
_dll.openmc_init(None)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ module openmc_api
|
|||
use mesh_header
|
||||
use message_passing
|
||||
use nuclide_header
|
||||
use initialize, only: openmc_init
|
||||
use initialize, only: openmc_init_f
|
||||
use particle_header, only: Particle
|
||||
use plot, only: openmc_plot_geometry
|
||||
use random_lcg, only: openmc_get_seed, openmc_set_seed
|
||||
|
|
@ -64,7 +64,7 @@ module openmc_api
|
|||
public :: openmc_get_tally_index
|
||||
public :: openmc_global_tallies
|
||||
public :: openmc_hard_reset
|
||||
public :: openmc_init
|
||||
public :: openmc_init_f
|
||||
public :: openmc_load_nuclide
|
||||
public :: openmc_material_add_nuclide
|
||||
public :: openmc_material_get_id
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
#include "hdf5_interface.h"
|
||||
#include "error.h"
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "hdf5_hl.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "hdf5_hl.h"
|
||||
#ifdef OPENMC_MPI
|
||||
#include "mpi.h"
|
||||
#include "openmc.h"
|
||||
#endif
|
||||
#include "error.h"
|
||||
|
||||
|
||||
namespace openmc {
|
||||
|
||||
bool
|
||||
|
|
@ -158,7 +163,7 @@ file_open(const char* filename, char mode, bool parallel)
|
|||
if (parallel) {
|
||||
// Setup file access property list with parallel I/O access
|
||||
plist = H5Pcreate(H5P_FILE_ACCESS);
|
||||
H5Pset_fapl_mpio(plist, mpi_intracomm, MPI_INFO_NULL);
|
||||
H5Pset_fapl_mpio(plist, openmc_intracomm, MPI_INFO_NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,9 @@ contains
|
|||
! setting up timers, etc.
|
||||
!===============================================================================
|
||||
|
||||
subroutine openmc_init(intracomm) bind(C)
|
||||
function openmc_init_f(intracomm) result(err) bind(C)
|
||||
integer, intent(in), optional :: intracomm ! MPI intracommunicator
|
||||
integer(C_INT) :: err
|
||||
|
||||
#ifdef _OPENMP
|
||||
character(MAX_WORD_LEN) :: envvar
|
||||
|
|
@ -105,7 +106,8 @@ contains
|
|||
! Stop initialization timer
|
||||
call time_initialize%stop()
|
||||
|
||||
end subroutine openmc_init
|
||||
err = 0
|
||||
end function openmc_init_f
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
!===============================================================================
|
||||
|
|
|
|||
20
src/initialize.cpp
Normal file
20
src/initialize.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "openmc.h"
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
MPI_Comm openmc_intracomm;
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
openmc_init(const void* intracomm)
|
||||
{
|
||||
#ifdef OPENMC_MPI
|
||||
openmc_intracomm = *static_cast<const MPI_Comm *>(intracomm);
|
||||
|
||||
MPI_Fint fcomm = MPI_Comm_c2f(openmc_intracomm);
|
||||
openmc_init_f(&fcomm);
|
||||
#else
|
||||
openmc_init_f(nullptr);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
14
src/main.cpp
14
src/main.cpp
|
|
@ -1,17 +1,15 @@
|
|||
#include "openmc.h"
|
||||
|
||||
#ifdef MPI
|
||||
#include <mpi.h>
|
||||
#else
|
||||
#define MPI_COMM_WORLD nullptr
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int err;
|
||||
|
||||
// Initialize run -- when run with MPI, pass communicator
|
||||
openmc_init(MPI_COMM_WORLD);
|
||||
#ifdef OPENMC_MPI
|
||||
MPI_Comm world {MPI_COMM_WORLD};
|
||||
openmc_init(&world);
|
||||
#else
|
||||
openmc_init(nullptr);
|
||||
#endif
|
||||
|
||||
// start problem based on mode
|
||||
switch (openmc_run_mode) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue