Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'debug'
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Nov 29, 2022
2 parents dc9f2c6 + 1b8a91f commit 2d0f6cb
Show file tree
Hide file tree
Showing 45 changed files with 1,316 additions and 1,074 deletions.
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)

# Set some options the user may choose
# Uncomment the below if you want the user to choose a parallelization library
OPTION(USE_MPI "Use the MPI library for parallelization" OFF)
OPTION(USE_MPI "Use the MPI library for parallelization" ON)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)

# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, and TESTING. You should review this file and make sure the flags
# are to your liking.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)

# Locate and set parallelization libraries. There are some CMake peculiarities
# taken care of here, such as the fact that the FindOpenMP routine doesn't know
# about Fortran.
INCLUDE(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake)

# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, PROFILING, and TESTING.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)


# There is an error in CMAKE with this flag for pgf90. Unset it
GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME)
Expand All @@ -59,9 +62,10 @@ SET(SWIFTEST_DRIVER swiftest_driver)
SET(SRC ${CMAKE_SOURCE_DIR}/src)
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(BIN ${CMAKE_SOURCE_DIR}/bin)
SET(MOD ${CMAKE_SOURCE_DIR}/include)

# Have the .mod files placed in the lib folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${LIB})
SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})

# The source for the SWIFTEST binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})
Expand Down
17 changes: 17 additions & 0 deletions cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# - Finds the Intel MKL libraries
find_path(MKL_INCLUDE_DIR NAMES mkl.h HINTS ENV MKLROOT PATH_SUFFIXES include)
find_library(MKL_LIBRARY NAMES libmkl_core.a HINTS ENV MKLROOT PATH_SUFFIXES lib lib/intel64 )

set(MKL_FOUND TRUE)
set(MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR})
set(MKL_LIBRARIES ${MKL_LIBRARY})
mark_as_advanced(MKL_LIBRARY MKL_INCLUDE_DIR)
10 changes: 8 additions & 2 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_TESTING}"

# Unroll loops
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-funroll-loops" # GNU
"-unroll" # Intel
Fortran "-unroll" # Intel
"/unroll" # Intel Windows
"-funroll-loops" # GNU
"-Munroll" # Portland Group
)

Expand Down Expand Up @@ -288,6 +288,12 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-fma" # Intel
)

# Generate fused multiply-add instructions
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-qmkl=cluster" # Intel
Fortran "-qmkl" # Intel
Fortran "-mkl" # Old Intel
)

#####################
### MATH FLAGS ###
Expand Down
14 changes: 14 additions & 0 deletions cmake/Modules/SetMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# Find MKL if not already found
IF(NOT MKL_FOUND)
ENABLE_LANGUAGE(C) # Some libraries need a C compiler to find
FIND_PACKAGE(MKL REQUIRED)
ENDIF(NOT MKL_FOUND)
22 changes: 8 additions & 14 deletions cmake/Modules/SetParallelizationLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# When one is turned on, the other is turned off
# If both are off, we explicitly disable them just in case

IF (USE_OPENMP AND USE_MPI)
MESSAGE (FATAL_ERROR "Cannot use both OpenMP and MPI")
ELSEIF (USE_OPENMP)
IF (USE_OPENMP)
# Find OpenMP
IF (NOT OpenMP_Fortran_FLAGS)
FIND_PACKAGE (OpenMP_Fortran)
Expand All @@ -23,20 +21,16 @@ ELSEIF (USE_OPENMP)
ENDIF (NOT OpenMP_Fortran_FLAGS)
ENDIF (NOT OpenMP_Fortran_FLAGS)
# Turn of MPI
UNSET (MPI_FOUND CACHE)
UNSET (MPI_COMPILER CACHE)
UNSET (MPI_LIBRARY CACHE)
ELSEIF (USE_MPI)
ENDIF (USE_OPENMP)

IF (USE_MPI)
# Find MPI
IF (NOT MPI_Fortran_FOUND)
FIND_PACKAGE (MPI REQUIRED)
ENDIF (NOT MPI_Fortran_FOUND)
# Turn off OpenMP
SET (OMP_NUM_PROCS 0 CACHE
STRING "Number of processors OpenMP may use" FORCE)
UNSET (OpenMP_C_FLAGS CACHE)
UNSET (GOMP_Fortran_LINK_FLAGS CACHE)
ELSE ()
ENDIF (USE_MPI)

IF (NOT USE_OPENMP AND NOT USE_MPI)
# Turn off both OpenMP and MPI
SET (OMP_NUM_PROCS 0 CACHE
STRING "Number of processors OpenMP may use" FORCE)
Expand All @@ -45,4 +39,4 @@ ELSE ()
UNSET (MPI_FOUND CACHE)
UNSET (MPI_COMPILER CACHE)
UNSET (MPI_LIBRARY CACHE)
ENDIF (USE_OPENMP AND USE_MPI)
ENDIF (NOT USE_OPENMP AND NOT USE_MPI)
3 changes: 3 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*/param.*
*/simdata/*
*/*/simdata/*

17 changes: 14 additions & 3 deletions examples/Basic_Simulation/initial_conditions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"source": [
"import swiftest\n",
"import numpy as np\n",
"from numpy.random import default_rng"
"from numpy.random import default_rng\n",
"%env OMP_NUM_THREADS=4"
]
},
{
Expand All @@ -20,8 +21,7 @@
"outputs": [],
"source": [
"# Initialize the simulation object as a variable\n",
"sim = swiftest.Simulation(tstart=0.0, tstop=10.0, dt=0.005, tstep_out=1.0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)\n",
"sim.get_parameter()"
"sim = swiftest.Simulation(tstart=0.0, tstop=1.0e6, dt=0.005, tstep_out=1.0e3, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)"
]
},
{
Expand Down Expand Up @@ -119,6 +119,17 @@
"sim.add_body(name_tp, a_tp, e_tp, inc_tp, capom_tp, omega_tp, capm_tp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "135bd3f8-0a56-4d62-b728-f150debc1a76",
"metadata": {},
"outputs": [],
"source": [
"# Display the run configuration parameters\n",
"sim.get_parameter()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
5 changes: 3 additions & 2 deletions examples/Basic_Simulation/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from numpy.random import default_rng

# Initialize the simulation object as a variable
sim = swiftest.Simulation(tstart=0.0, tstop=10.0, dt=0.005, tstep_out=1.0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)
sim.get_parameter()
sim = swiftest.Simulation(tstart=0.0, tstop=1.0e3, dt=0.005, tstep_out=1.0e0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)

# Add the modern planets and the Sun using the JPL Horizons Database
sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"])
Expand Down Expand Up @@ -64,6 +63,8 @@
capm_tp = default_rng().uniform(0.0, 360.0, ntp)

sim.add_body(name_tp, a_tp, e_tp, inc_tp, capom_tp, omega_tp, capm_tp)
# Display the run configuration parameters
sim.get_parameter()

# Run the simulation
sim.run()
119 changes: 119 additions & 0 deletions examples/Basic_Simulation/run_from_file.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "aa57e957-f141-4373-9a62-a91845203aa3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"env: OMP_NUM_THREADS=8\n"
]
}
],
"source": [
"import swiftest\n",
"import xarray as xr\n",
"import numpy as np\n",
"import os\n",
"%env OMP_NUM_THREADS=8"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a9c020aa-0a87-4fa9-9b11-62213edb370c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/simdata/param.in\n",
"\n",
"Creating Dataset from NetCDF file\n",
"Successfully converted 1 output frames.\n"
]
}
],
"source": [
"sim = swiftest.Simulation(read_param=True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "209523b6-d7a8-46f0-8687-54f199015c2d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing parameter inputs to file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/simdata/param.in\n",
"Running a Swiftest symba run from tstart=0.0 y to tstop=1000.0 y\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ca7e9529651b46209bc86174955f7a01",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Time: 0.0 / 1000.0 y : 0%| , npl: 14 ntp: 10 nplm: 13"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/daminton/git_debug/swiftest/python/swiftest/swiftest/simulation_class.py:465: UserWarning: Error executing main swiftest_driver program\n",
" self._run_swiftest_driver()\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Creating Dataset from NetCDF file\n",
"Successfully converted 19 output frames.\n",
"Swiftest simulation data stored as xarray DataSet .data\n"
]
}
],
"source": [
"sim.run()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (My debug_env Kernel)",
"language": "python",
"name": "debug_env"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 2 additions & 2 deletions examples/Basic_Simulation/run_from_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import swiftest
sim = swiftest.Simulation()
sim.run(tstop=20.0)
sim = swiftest.Simulation(read_param=True)
sim.run()
4 changes: 2 additions & 2 deletions examples/Basic_Simulation/run_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim = swiftest.Simulation()"
"sim = swiftest.Simulation(read_param=True)"
]
},
{
Expand All @@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim.run(tstop=10.0)"
"sim.run()"
]
},
{
Expand Down
Loading

0 comments on commit 2d0f6cb

Please sign in to comment.