Skip to content

Commit

Permalink
Remove local complexify and use shared library and scripts (#302)
Browse files Browse the repository at this point in the history
* Updating base makefile to clean complex build properly

* remove local complexify module and script

* update default config

* updating complex makefiles

* update doc and setup

* typo

* update docs
  • Loading branch information
eirikurj authored Aug 4, 2023
1 parent d161960 commit b0b6a6d
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 1,523 deletions.
36 changes: 12 additions & 24 deletions Makefile_CS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Master makefilefor complex ADflow. The actual makefile you want is
# Master makefile for complex ADflow. The actual makefile you want is
# src/build/Makefile_CS
default:
# Check if the config.mk file is in the config dir.
Expand All @@ -17,29 +17,17 @@ default:


clean:
rm -fr src_cs/build/*.mod
rm -fr src_cs/build/*.o
rm -fr src_cs/build/*.a
rm -fr src_cs/build/*.so
rm -fr src_cs/build/adflow_project.dep
rm -f *~ config.mk;
# Completely nuke most of the directories
rm -fr src_cs/adjoint
rm -fr src_cs/ADT
rm -fr src_cs/bcdata
rm -fr src_cs/initFlow
rm -fr src_cs/inputParam
rm -fr src_cs/NKSolver
rm -fr src_cs/metis-4.0
rm -fr src_cs/output
rm -fr src_cs/overset
rm -fr src_cs/partitioning
rm -fr src_cs/slidingComm
rm -fr src_cs/solver
rm -fr src_cs/turbulence
rm -fr src_cs/utils
rm -fr src_cs/wallDistance
rm -fr src_cs/warping
# The command will search "src_cs" finds and deletes anything (files and directories)
# except what is listed here below. Note in order not to delete the parent directory
# holding a file it needs to specified. Finally ! means "not".
find src_cs ! \( \
-wholename 'src_cs' \
-o -wholename 'src_cs/build' \
-o -wholename 'src_cs/build/Makefile' \
-o -wholename 'src_cs/build/Makefile1' \
-o -wholename 'src_cs/modules' \
-o -wholename 'src_cs/modules/precision.F90' \) \
-exec rm -rf {} +

adflow_build:
ln -sf config/config.mk config.mk;
Expand Down
4 changes: 4 additions & 0 deletions config/defaults/config.LINUX_GFORTRAN.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ CC_REAL_PRECISION_FLAG =
CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define complexify inlcude and linker flags -------------------------
COMPLEXIFY_INCLUDE_FLAGS=-I$(COMPLEXIFY_DIR)/include
COMPLEXIFY_LINKER_FLAGS=-L$(COMPLEXIFY_DIR)/lib -lcomplexify

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native
FF90_FLAGS = $(FF77_FLAGS) -std=f2008
Expand Down
4 changes: 4 additions & 0 deletions config/defaults/config.LINUX_INTEL.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ CC_REAL_PRECISION_FLAG =
CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define complexify inlcude and linker flags -------------------------
COMPLEXIFY_INCLUDE_FLAGS=-I$(COMPLEXIFY_DIR)/include
COMPLEXIFY_LINKER_FLAGS=-L$(COMPLEXIFY_DIR)/lib -lcomplexify

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
Expand Down
4 changes: 4 additions & 0 deletions config/defaults/config.LINUX_INTEL_AVX2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ CC_REAL_PRECISION_FLAG =
CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define complexify inlcude and linker flags -------------------------
COMPLEXIFY_INCLUDE_FLAGS=-I$(COMPLEXIFY_DIR)/include
COMPLEXIFY_LINKER_FLAGS=-L$(COMPLEXIFY_DIR)/lib -lcomplexify

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
Expand Down
4 changes: 4 additions & 0 deletions config/defaults/config.LINUX_INTEL_SAFE.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ CC_REAL_PRECISION_FLAG =
CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define complexify inlcude and linker flags -------------------------
COMPLEXIFY_INCLUDE_FLAGS=-I$(COMPLEXIFY_DIR)/include
COMPLEXIFY_LINKER_FLAGS=-L$(COMPLEXIFY_DIR)/lib -lcomplexify

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
Expand Down
4 changes: 4 additions & 0 deletions config/defaults/config.OSX_GFORTRAN.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ CC_REAL_PRECISION_FLAG =
CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define complexify inlcude and linker flags -------------------------
COMPLEXIFY_INCLUDE_FLAGS=-I$(COMPLEXIFY_DIR)/include
COMPLEXIFY_LINKER_FLAGS=-L$(COMPLEXIFY_DIR)/lib -lcomplexify

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native
FF90_FLAGS = $(FF77_FLAGS) -std=f2008
Expand Down
45 changes: 24 additions & 21 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ It is therefore necessary to build this library before using ADflow.
Requirements
------------
ADflow requires the following dependencies:

- CGNS Library
- PETSc
- MPI
- Complexify (see the `Complex build`_ section)

See the MDO Lab installation guide `here <https://mdolab-mach-aero.readthedocs-hosted.com/en/latest/installInstructions/install3rdPartyPackages.html>`_ for the supported versions and installation instructions.

Expand All @@ -21,14 +23,14 @@ To start, find a configuration file close to your current setup in::

config/defaults

and copy it to ''config/config.mk''. For example:
and copy it to ``config/config.mk``. For example:

.. prompt:: bash

cp config/defaults/config.LINUX_GFORTRAN.mk config/config.mk

If you are a beginner user installing the packages on a linux desktop,
you should use the ``config.LINUX_GFORTRAN`` versions of the configuration
If you are a beginner user installing the packages on a linux desktop,
you should use the ``config.LINUX_GFORTRAN`` versions of the configuration
files. The ``config.LINUX_INTEL`` versions are usually used on clusters.
ADflow has been successfully compiled on LINUX with either
``ifort`` or ``gfortran``.
Expand All @@ -47,19 +49,18 @@ the screen (near the end)::

If you don't see this, it will be necessary to configure the build manually.
To configure manually, open ``config/config.mk`` and modify options as necessary.

It is most likely that you need to modify the ``CGNS_INCLUDE_FLAGS`` and the ``CGNS_LINKER_FLAGS`` variables.
Common issues are often that dependency variable paths, such as ``CGNS_INCLUDE_FLAGS`` and ``CGNS_LINKER_FLAGS``, point to an incorrect location and need to be updated.
After changes to the configuration file, run ``make clean`` before attempting a new build.

.. NOTE::

Compiling ADflow on HPC clusters requires additional care, as some systems do not have a homogeneous CPU architecture across all nodes.
For example, the architecture of the login nodes may differ from the architecture of compute nodes available on the same cluster.
For example, the architecture of the login nodes may differ from the architecture of compute nodes available on the same cluster.

Compiling the code on/for a specific login node type may result in unexpected crashes if the compute nodes have an incompatible (newer) architecture.
You can append the ``-march=<HPC-ARCH>`` flag to the ``config.mk`` file to specify the architecture of the compute node and avoid such issues.
To optimize the compiled code for a specific architecture, one can add the ``-mtune=<HPC-ARCH>`` flag. However, this is rarely needed.
An example of the updated flags in the config file is::
You can append the ``-march=<HPC-ARCH>`` flag to the ``config.mk`` file to specify the architecture of the compute node and avoid such issues.
To optimize the compiled code for a specific architecture, one can add the ``-mtune=<HPC-ARCH>`` flag. However, this is rarely needed.
An example of the updated flags in the config file is::

FF90_FLAGS = <normal-flags> -march=<HPC-ARCH> -mtune=<HPC-ARCH>

Expand All @@ -69,7 +70,7 @@ After changes to the configuration file, run ``make clean`` before attempting a

FF90_FLAGS = <normal-flags> -march=sandybridge

We recommend to contact your local HPC team to get more information about hardware specific issues.
We recommend to contact your local HPC team to get more information about hardware specific issues.

Lastly, to build and install the Python interface, type:

Expand Down Expand Up @@ -105,30 +106,32 @@ Then in the root directory run:

Complex Build
-------------
ADflow contains scripts to automatically build a "complexified"
version of ADflow directly from the real version.

ADflow_CS REQUIRES a complex build of petsc to build and run. The
petsc configuration script must be re-run with the following
options:
Its possible to build a "complexified" version of ADflow directly from the real version.
To do so, ADflow relies on the `Complexify <https://github.com/mdolab/complexify>`__ module and library, which needs to be compiled and installed first.
Furthermore, complex ADflow **requires** a complex build of PETSc to build and run.
The PETSc configuration script must be re-run with the following options:

.. prompt:: bash

./configure --with-shared-libraries --download-superlu_dist=yes --download-parmetis=yes --download-metis=yes --with-fortran-interfaces=1 --with-debugging=yes --with-scalar-type=complex --PETSC_ARCH=complex-debug

Follow instructions as before to complete complex build.

Now, to build complex ADflow do:

.. prompt:: bash

export PETSC_ARCH=complex-debug
export PETSC_ARCH=$PETSC_ARCH_COMPLEX
make -f Makefile_CS

Note that the correct, complex PETSC_ARCH MUST be set before the code is
compiled and also must be set when running in complex mode.
Note that, ``PETSC_ARCH``, **must** be set and point to the complex PETSc before the code is compiled, and must also be set when running in complex mode.
In the above example, an intermediate convenience variable, ``PETSC_ARCH_COMPLEX``, defines the complex PETSc arch path.
Once the library is built run the following to install the python module and library into your environment.

.. prompt:: bash

pip install .[complex]

To run the complex tests, first set the ``$PETSC_ARCH`` to the complex architecture.
To run the complex tests, first set the ``PETSC_ARCH`` to the complex architecture.
Then run:

.. prompt:: bash
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"docs": docs_require,
"testing": ["parameterized", "testflo", "idwarp", "pygeo", "pyspline"],
"mphys": ["openmdao", "mphys", "idwarp"],
"complex": ["complexify"],
},
classifiers=["Operating System :: Linux", "Programming Language :: Python, Fortran"],
)
8 changes: 3 additions & 5 deletions src_cs/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ include ../../config/config.mk
EXTRA_FF90_FLAGS = $(shell bash ../../config/compilerCheck.sh $(FF90))

# Group all the fortran, C and compiler flags together.
FF90_ALL_FLAGS_NO_OPT = $(FF90_FLAGS) $(EXTRA_FF90_FLAGS) $(CGNS_INCLUDE_FLAGS) -I. -DUSE_COMPLEX \
FF90_ALL_FLAGS_NO_OPT = $(FF90_FLAGS) $(EXTRA_FF90_FLAGS) $(CGNS_INCLUDE_FLAGS) \
-I. -DUSE_COMPLEX $(COMPLEXIFY_INCLUDE_FLAGS) \
$(PETSC_CC_INCLUDES) $(FF90_PRECISION_FLAGS)

FF90_ALL_FLAGS = $(FF90_ALL_FLAGS_NO_OPT) $(FFXX_OPT_FLAGS)

CC_ALL_FLAGS = $(C_FLAGS) -I../c_defines -I../metis-4.0 $(PETSC_CC_INCLUDES) \
$(CC_PRECISION_FLAGS)

LINKER_ALL_FLAGS = $(CGNS_LINKER_FLAGS) $(PETSC_LIB) $(LINKER_FLAGS)
LINKER_ALL_FLAGS = $(CGNS_LINKER_FLAGS) $(COMPLEXIFY_LINKER_FLAGS) $(PETSC_LIB) $(LINKER_FLAGS)

# Include the full filelist
include ../../src/build/fileList
Expand All @@ -40,9 +41,6 @@ include ../../src/build/rules
dirs:=$(addprefix ../,$(dirs))
VPATH:=$(dirs)

# Add the special extra complexify module to the list of files:
fortranFiles:=$(fortranFiles) modules/complexify.f90

# Need to add the ../ to each of the file lists:
fortranFilesNoOpt:=$(addprefix ../,$(fortranFilesNoOpt))
fortranFiles:=$(addprefix ../,$(fortranFiles))
Expand Down
7 changes: 3 additions & 4 deletions src_cs/build/Makefile1
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ complexify:
@for file in $(filesToComplexify); do \
realFile=$(addprefix ../../src/,$$file); \
cmplxFile=$(addprefix ../,$$file); \
echo Checking $$file $$realFile $$cmplxFile; \
echo Checking $$realFile $$cmplxFile; \
if [ $$realFile -nt $$cmplxFile -o ! -e $$cmplxFile ]; then \
python complexify.py $$realFile; \
echo Complexifying $$file $$realFile $$cmplxFile; \
mv newFile $$cmplxFile; \
echo Complexifying $$realFile $$cmplxFile; \
complexify $$realFile --outFileName $$cmplxFile; \
fi;\
done

Expand Down
Loading

0 comments on commit b0b6a6d

Please sign in to comment.