Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
47f0b97
Replace M_PI with PI constant for compiling on Windows with Intel.
HunterBelanger Jan 17, 2024
6f6ebae
Fix reading in file paths on Windows for xs data.
HunterBelanger Jan 17, 2024
9eff746
Makes cmake compatible with Windows/Intel build.
HunterBelanger Jan 17, 2024
d711dde
Updates for MSVC/Visual Studio compiler.
HunterBelanger Jan 17, 2024
c2fc162
Make sure atomic has seq_cst with Intel compiler on Windows
HunterBelanger Jan 19, 2024
722c6e6
Adds macros to export global variable symbols on Windows
HunterBelanger Jan 19, 2024
ae0b297
Updates Python API to find the dynamic libopenmc.dll on Windows
HunterBelanger Jan 19, 2024
7c832e2
Adds logic to generat dll on Windows and moves to more recent xtensor…
HunterBelanger Jan 19, 2024
45e7e19
Fix python parallel bug on Windows in depletion.
HunterBelanger Jan 19, 2024
a6eee38
Update file_utils tests for Windows
HunterBelanger Jan 19, 2024
a1bcd55
Export some more global variables in the DLL
HunterBelanger Jan 19, 2024
8731d7f
Merge branch 'develop' into feature/windows
HunterBelanger Mar 19, 2024
5f5bec8
Fixes formating
HunterBelanger Mar 26, 2024
2c82b3a
Add directory to openmc dll on Windows systems with python >= 3.8.0
HunterBelanger Mar 30, 2024
ee58f87
Update openmc/deplete/pool.py
HunterBelanger Mar 30, 2024
6359969
Merge branch 'develop' into feature/windows
HunterBelanger Jun 5, 2024
8b58264
Use submodules for xtensor again now that they have been updated.
HunterBelanger Jun 5, 2024
578faba
Fixes clang-format test
HunterBelanger Jun 5, 2024
544369e
Merge branch 'develop' into feature/windows
HunterBelanger Jul 18, 2024
06888e8
Merge branch 'develop' into pr/HunterBelanger/2919
paulromano Aug 16, 2024
ccdb7ee
Rename OPENMC_WIN_COMPILE to OPENMC_DLL_EXPORTS
paulromano Aug 16, 2024
3db9028
Remove mention of Python 3.8+
paulromano Aug 16, 2024
d6c7e0a
Use std::filesystem to get rid of sep_char
paulromano Aug 16, 2024
c609f24
Use _WIN32, not _MSC_VER
paulromano Aug 16, 2024
28c42ef
Rename DllExport to OPENMC_API
paulromano Aug 16, 2024
071c946
Change and to && for MSVC compilation
HunterBelanger Aug 16, 2024
fde82e2
Fixes to OMP reductions for compilation with MSVC
HunterBelanger Aug 16, 2024
f6e1a04
Fix C++ style
paulromano Aug 16, 2024
38e11f2
First attempt at adding Windows to CI
HunterBelanger Aug 18, 2024
3e1bce2
Fix xs download script on Windows
HunterBelanger Aug 18, 2024
61b7164
More annoying Windows fixes
HunterBelanger Aug 18, 2024
666e8af
Changes USERPROFILE to GITHUB_WORKSPACE to try and make Windows CI work
HunterBelanger Aug 18, 2024
ac97924
Add caching of xs for windows CI
HunterBelanger Aug 18, 2024
b1480ee
Tries to fix some Windows CI problems
HunterBelanger Aug 20, 2024
e436d8a
Merge branch 'develop' into feature/windows
HunterBelanger Aug 20, 2024
7a99ace
Maybe cmake will find HDF5 this time...
HunterBelanger Aug 20, 2024
03d40fd
Merge branch 'feature/windows' of github.com:HunterBelanger/openmc in…
HunterBelanger Aug 20, 2024
37cf13e
Debug action to explor windows runner
HunterBelanger Aug 22, 2024
2a74b4c
Merge branch 'develop' into feature/windows
HunterBelanger Apr 24, 2025
95a7d5e
Merge branch 'develop' into feature/windows
HunterBelanger May 5, 2025
2535052
Update Windows CICD to Python 3.11
HunterBelanger May 5, 2025
3f78e6c
Some updates to Windows CICD scripts
HunterBelanger May 5, 2025
76d8c21
Fix some clang-format problems
HunterBelanger May 5, 2025
0398a7d
Temporarily disable normal linux tests to simplify debugging of windo…
HunterBelanger May 5, 2025
6611d85
Undo trying to disable Ubuntu CICD. Didn't work right.
HunterBelanger May 5, 2025
53e1b82
Require Windows tests and run them first (for now).
HunterBelanger May 5, 2025
c511b79
Updates to Windows CI scripts and actions.
HunterBelanger May 6, 2025
06df927
Skip compiled source tests on Windows.
HunterBelanger May 6, 2025
84753ef
Update comparison of file paths for cross platform compatability.
HunterBelanger May 6, 2025
0c12586
Fixes for tests that were failing due to Windows line endings.
HunterBelanger May 6, 2025
be79895
Fix failing plot test on Windows.
HunterBelanger May 6, 2025
3fb37a7
Fixes some iterator / uninitialized bugs causing windows debug builds…
HunterBelanger May 9, 2025
2a2dd7f
Merge branch 'develop' into feature/windows
HunterBelanger May 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,75 @@ jobs:
cpp-coveralls -i src -i include -e src/external --exclude-pattern "/usr/*" --dump cpp_cov.json
coveralls --merge=cpp_cov.json --service=github

win:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.11"]
omp: [n, y]

include:
- python-version: "3.11"
omp: n
- python-version: "3.11"
omp: y
name: "Windows Python ${{ matrix.python-version }} (omp=${{ matrix.omp }})"

env:
OMP: ${{ matrix.omp }}
EVENT: ${{ matrix.event }}
NPY_DISABLE_CPU_FEATURES: "AVX512F AVX512_SKX"
OPENBLAS_NUM_THREADS: 1
# libfabric complains about fork() as a result of using Python multiprocessing.
# We can work around it with RDMAV_FORK_SAFE=1 in libfabric < 1.13 and with
# FI_EFA_FORK_SAFE=1 in more recent versions.
RDMAV_FORK_SAFE: 1

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Environment Variables
shell: pwsh
run: |
[Environment]::SetEnvironmentVariable("OPENMC_CROSS_SECTIONS", "$Env:GITHUB_WORKSPACE\nndc_hdf5\cross_sections.xml", 'Machine')
[Environment]::SetEnvironmentVariable("OPENMC_ENDF_DATA", "$Env:GITHUB_WORKSPACE\endf-b-vii.1", 'Machine')

- name: Cache XS
uses: actions/cache@v4
with:
path: |
${{github.workspace}}\nndc_hdf5
${{github.workspace}}\endf-b-vii.1
key: ${{ runner.os }}-build-xs-cache

- name: Install
shell: pwsh
run: |
${{github.workspace}}\tools\ci\gha-install.ps1

- name: Before
shell: pwsh
run: ${{github.workspace}}\tools\ci\download-xs.ps1

- name: Test
shell: pwsh
run: |
ctest --output-on-failure -C Release ${{ github.workspace }}\build\
${{github.workspace}}\tools\ci\gha-script.ps1

- name: Setup tmate debug session
continue-on-error: true
if: ${{ contains(env.COMMIT_MESSAGE, '[gha-debug]') }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 10

finish:
needs: main
needs: [win, main]
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
Expand Down
56 changes: 38 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ endif()

if(OPENMC_USE_OPENMP)
find_package(OpenMP REQUIRED)

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Special flag to get OpenMP to work on Windows with MSVC
list(APPEND cxxflags /openmp:llvm)
endif()
endif()

#===============================================================================
Expand Down Expand Up @@ -167,6 +172,12 @@ if(NOT DEFINED HDF5_PREFER_PARALLEL)
endif()
endif()

if (MSVC)
# To avoid problems with loading DLLs on Windows in the Python API,
# we should try to link libhdf5 statically.
set(HDF5_USE_STATIC_LIBRARIES TRUE)
endif()

find_package(HDF5 REQUIRED COMPONENTS C HL)

# Remove HDF5 transitive dependencies that are system libraries
Expand Down Expand Up @@ -211,24 +222,22 @@ endif()

# Skip for Visual Studio which has its own configurations through GUI
if(NOT MSVC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(OPENMC_ENABLE_PROFILE)
list(APPEND cxxflags -g -fno-omit-frame-pointer)
endif()
if(OPENMC_ENABLE_PROFILE)
list(APPEND cxxflags -g -fno-omit-frame-pointer)
endif()

if(OPENMC_ENABLE_COVERAGE)
list(APPEND cxxflags --coverage)
list(APPEND ldflags --coverage)
if(OPENMC_ENABLE_COVERAGE)
list(APPEND cxxflags --coverage)
list(APPEND ldflags --coverage)
endif()
endif()

# Show flags being used
message(STATUS "OpenMC C++ flags: ${cxxflags}")
message(STATUS "OpenMC Linker flags: ${ldflags}")

endif()

#===============================================================================
# Update git submodules as needed
#===============================================================================
Expand Down Expand Up @@ -446,20 +455,31 @@ list(APPEND libopenmc_SOURCES
src/external/quartic_solver.cpp
src/external/Faddeeva.cc)

# For Visual Studio compilers
#===============================================================================
# openmc library
#===============================================================================
add_library(libopenmc SHARED ${libopenmc_SOURCES})
add_library(OpenMC::libopenmc ALIAS libopenmc)

# For compilers on Windows
if(MSVC)
# Use static library (otherwise explicit symbol portings are needed)
add_library(libopenmc STATIC ${libopenmc_SOURCES})
# This ensures that all function/class method symbols are exported, without
# needing to add the export macros in the source.
set_target_properties(libopenmc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)

# This compile definition is needed to make sure that the correct macros
# are used for exporting symbols in the dll. While the
# WINDOWS_EXPORT_ALL_SYMBOLS exports all function/class symbols, it
# unfortunately does not work on global variables, which still need the macro.
target_compile_definitions(libopenmc PRIVATE -DOPENMC_DLL_EXPORTS)

# To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB
# compile definition must be specified.
target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB)
else()
add_library(libopenmc SHARED ${libopenmc_SOURCES})
if (NOT HDF5_USE_STATIC_LIBRARIES)
target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB)
endif()
endif()

add_library(OpenMC::libopenmc ALIAS libopenmc)

# Avoid vs error lnk1149 :output filename matches input filename
if(NOT MSVC)
set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc)
Expand Down
11 changes: 10 additions & 1 deletion include/openmc/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,17 @@ extern int OPENMC_E_DATA;
extern int OPENMC_E_PHYSICS;
extern int OPENMC_E_WARNING;

// Macro to ensure global variables are exported in Windows DLLs
#if defined(_WIN32) && defined(OPENMC_DLL_EXPORTS)
#define OPENMC_API __declspec(dllexport)
#elif defined(_WIN32)
#define OPENMC_API __declspec(dllimport)
#else
#define OPENMC_API
#endif

// Global variables
extern char openmc_err_msg[256];
extern char OPENMC_API openmc_err_msg[256];

#ifdef __cplusplus
}
Expand Down
13 changes: 13 additions & 0 deletions include/openmc/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,19 @@ enum class GeometryType { CSG, DAG };
// representations. This value represents no surface.
constexpr int32_t SURFACE_NONE {0};

//==============================================================================
// Shared Libraries on Windows need the functions/classes/variables to be
// exposed to be declared with this special keyword "__declspec(dllexport)".
// We use a macro for this, so that it is only exported on Windows.

#if defined(_WIN32) && defined(OPENMC_DLL_EXPORTS)
#define OPENMC_API __declspec(dllexport)
#elif defined(_WIN32)
#define OPENMC_API __declspec(dllimport)
#else
#define OPENMC_API
#endif

} // namespace openmc

#endif // OPENMC_CONSTANTS_H
6 changes: 4 additions & 2 deletions include/openmc/dagmc.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef OPENMC_DAGMC_H
#define OPENMC_DAGMC_H

#include "openmc/constants.h" // Needed for OPENMC_API

namespace openmc {
extern "C" const bool DAGMC_ENABLED;
extern "C" const bool UWUW_ENABLED;
extern "C" const bool OPENMC_API DAGMC_ENABLED;
extern "C" const bool OPENMC_API UWUW_ENABLED;
} // namespace openmc

// always include the XML interface header
Expand Down
2 changes: 2 additions & 0 deletions include/openmc/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "openmc/particle.h"
#include "openmc/shared_array.h"

#include <tuple>

namespace openmc {

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion include/openmc/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace openmc {

class BoundaryInfo;
struct BoundaryInfo;
class GeometryState;

//==============================================================================
Expand Down
3 changes: 2 additions & 1 deletion include/openmc/mcpl_interface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OPENMC_MCPL_INTERFACE_H
#define OPENMC_MCPL_INTERFACE_H

#include "openmc/constants.h"
#include "openmc/particle_data.h"
#include "openmc/span.h"
#include "openmc/vector.h"
Expand All @@ -13,7 +14,7 @@ namespace openmc {
// Constants
//==============================================================================

extern "C" const bool MCPL_ENABLED;
extern "C" const bool OPENMC_API MCPL_ENABLED;

//==============================================================================
// Functions
Expand Down
7 changes: 4 additions & 3 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "xtensor/xtensor.hpp"

#include "openmc/bounding_box.h"
#include "openmc/constants.h" // for OPENMC_API
#include "openmc/error.h"
#include "openmc/memory.h" // for unique_ptr
#include "openmc/particle.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ enum class ElementType { UNSUPPORTED = -1, LINEAR_TET, LINEAR_HEX };
// Global variables
//==============================================================================

extern "C" const bool LIBMESH_ENABLED;
extern "C" const bool OPENMC_API LIBMESH_ENABLED;

class Mesh;

Expand Down Expand Up @@ -578,7 +579,7 @@ class CylindricalMesh : public PeriodicStructuredMesh {

inline int sanitize_angular_index(int idx, bool full, int N) const
{
if ((idx > 0) and (idx <= N)) {
if ((idx > 0) && (idx <= N)) {
return idx;
} else if (full) {
return (idx + N - 1) % N + 1;
Expand Down Expand Up @@ -640,7 +641,7 @@ class SphericalMesh : public PeriodicStructuredMesh {

inline int sanitize_angular_index(int idx, bool full, int N) const
{
if ((idx > 0) and (idx <= N)) {
if ((idx > 0) && (idx <= N)) {
return idx;
} else if (full) {
return (idx + N - 1) % N + 1;
Expand Down
3 changes: 2 additions & 1 deletion include/openmc/message_passing.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
#include <mpi.h>
#endif

#include "openmc/constants.h"
#include "openmc/vector.h"

namespace openmc {
namespace mpi {

extern int rank;
extern int n_procs;
extern bool master;
extern bool OPENMC_API master;
Comment thread
paulromano marked this conversation as resolved.

#ifdef OPENMC_MPI
extern MPI_Datatype source_site;
Expand Down
7 changes: 4 additions & 3 deletions include/openmc/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ extern ResScatMethod res_scat_method; //!< resonance upscattering method
extern double res_scat_energy_min; //!< Min energy in [eV] for res. upscattering
extern double res_scat_energy_max; //!< Max energy in [eV] for res. upscattering
extern vector<std::string>
res_scat_nuclides; //!< Nuclides using res. upscattering treatment
extern RunMode run_mode; //!< Run mode (eigenvalue, fixed src, etc.)
extern SolverType solver_type; //!< Solver Type (Monte Carlo or Random Ray)
res_scat_nuclides; //!< Nuclides using res. upscattering treatment
extern RunMode OPENMC_API run_mode; //!< Run mode (eigenvalue, fixed src, etc.)
extern SolverType OPENMC_API
solver_type; //!< Solver Type (Monte Carlo or Random Ray)
Comment thread
paulromano marked this conversation as resolved.
extern std::unordered_set<int>
sourcepoint_batch; //!< Batches when source should be written
extern std::unordered_set<int>
Expand Down
10 changes: 10 additions & 0 deletions include/openmc/shared_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,23 @@ class SharedArray {
{
// Atomically capture the index we want to write to
int64_t idx;
#if _WIN32 && !__INTEL_COMPILER
#pragma omp atomic capture
idx = size_++;
#else
#pragma omp atomic capture seq_cst
idx = size_++;
#endif

// Check that we haven't written off the end of the array
if (idx >= capacity_) {
#if _WIN32 && !__INTEL_COMPILER
#pragma omp atomic write
size_ = capacity_;
#else
#pragma omp atomic write seq_cst
size_ = capacity_;
#endif
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion include/openmc/tallies/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Filter {

namespace model {
extern "C" int32_t n_filters;
extern std::unordered_map<int, int> filter_map;
extern std::unordered_map<int, int> OPENMC_API filter_map;
Comment thread
paulromano marked this conversation as resolved.
extern vector<unique_ptr<Filter>> tally_filters;
} // namespace model

Expand Down
7 changes: 7 additions & 0 deletions openmc/deplete/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@

from openmc.mpi import comm

import sys

# Configurable switch that enables / disables the use of
# multiprocessing routines during depletion
USE_MULTIPROCESSING = True

# Not sure why, but using multiprocessing on Windows leads to many transport
# simulations being run over eachother and leads to catastrophe.
if sys.platform == 'win32':
USE_MULTIPROCESSING = False
Comment on lines +19 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ought to get to the bottom of this since it should work in principle on Windows

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree, though I have not had time to look at it since. It was a while ago when I examined this, but from what I could tell I think it is a Python/Windows problem and not necessarily a bug on our side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note, turns out this same problem exists on my student's M1 mac.


# Allow user to override the number of worker processes to use for depletion
# calculations
NUM_PROCESSES = None
Expand Down
Loading