Skip to content

Commit

Permalink
Improvements to Build System (#44)
Browse files Browse the repository at this point in the history
* Attempt to add CI for Mac as well

* Forgot to commit the files...

* Bug fixes.

* More bug fixes.

* More fixes...

* Pulled out cmake run into a separate script.

* Small fix.

* Mistake with travis_wait

* Just one file needed now, no separate build mpi

* Problem with cached openmpi

* Cached mpi

* Fixed mac bug.

* Switched swig method for mac.

* Need to install gcc for fortran.

* Mac fixes.

* A few fixes for Linux, caches Swig

* Cache swig

* Pip caching isuse maybe.

* Swig install with brew

* Problem with travis wait?

* No redirect to debug...

* Swig debugging

* Build examples on Travis-CI

* Pip problem.

* Needs to install python2

* Use easy install for pip

* Try pip2?

* Tried to fix the C++ example compilation.

* Added flag for release and debug mode.

* Fortran only option for compiling.

* Update ReadMe.md

* Bug fix.
  • Loading branch information
william-dawson authored Apr 20, 2018
1 parent 4e47b66 commit b56d6e5
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 105 deletions.
42 changes: 17 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


os: linux
sudo: required
dist: trusty
Expand All @@ -7,39 +9,29 @@ notifications:

language: C++

matrix:
include:
- os: linux
sudo: required
dist: trusty
env: TESTOS="LINUX"
- os: osx
sudo: required
env: TESTOS="OSX"

cache:
pip: true
directories:
- openmpi-2.1.1
- openmpi-3.0.1
- swig-3.0.12

before_install:
- sudo apt-get install gfortran
- travis_wait bash UnitTests/travis_build_mpi.sh
- cd openmpi-2.1.1
- sudo make install >/dev/null 2>&1
- cd ../
- sudo ldconfig
- sudo apt-get install python-dev
- sudo apt-get install doxygen
- wget https://downloads.sourceforge.net/swig/swig-3.0.12.tar.gz
- tar xvf swig-3.0.12.tar.gz >/dev/null
- cd swig-3.0.12
- ./configure >/dev/null 2>&1
- make >/dev/null 2>&1
- sudo make install >/dev/null 2>&1
- cd ../
- sudo pip install scipy --upgrade
- sudo pip install numpy --upgrade
- sudo pip install mpi4py --upgrade
- test -n $CC && unset CC
- test -n $FCC && unset FCC
- test -n $CXX && unset CXX
- travis_wait bash UnitTests/travis_before_install.sh

script:
- cd Build
- cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake ..
- bash ../UnitTests/travis_run_cmake.sh
- make
- travis_wait 30 make test > test_result.txt
- tail -n 13 Testing/Temporary/LastTest.log
- make test
- cd ../UnitTests/
- bash travis_check_examples.sh
31 changes: 27 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ find_package(MPI REQUIRED)

################################################################################
## Testing
enable_testing()
if (NOT FORTRAN_ONLY)
enable_testing()
endif()

################################################################################
## Output Locations
Expand All @@ -28,10 +30,31 @@ add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile)

################################################################################
## Toolchain File
set(CMAKE_Fortran_FLAGS ${F_TOOLCHAINFLAGS})
set(CMAKE_CXX_FLAGS ${CXX_TOOLCHAINFLAGS})
#if(CMAKE_BUILD_TYPE MATCHES Debug)
# set(CMAKE_Fortran_FLAGS_DEBUG ${F_TOOLCHAINFLAGS_DEBUG})
# set(CMAKE_CXX_FLAGS_DEBUG ${CXX_TOOLCHAINFLAGS_DEBUG})
#elseif(CMAKE_BUILD_TYPE MATCHES Release)
# set(CMAKE_Fortran_FLAGS_RELEASE ${F_TOOLCHAINFLAGS_RELEASE})
# set(CMAKE_CXX_FLAGS_RELEASE ${CXX_TOOLCHAINFLAGS_RELEASE})
#else()
# set(CMAKE_Fortran_FLAGS ${F_TOOLCHAINFLAGS_RELEASE})
# set(CMAKE_CXX_FLAGS ${CXX_TOOLCHAINFLAGS_RELEASE})
#endif()

set(CMAKE_Fortran_FLAGS_DEBUG ${F_TOOLCHAINFLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG ${CXX_TOOLCHAINFLAGS_DEBUG})
set(CMAKE_Fortran_FLAGS_RELEASE ${F_TOOLCHAINFLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${CXX_TOOLCHAINFLAGS_RELEASE})

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_Fortran_FLAGS ${F_TOOLCHAINFLAGS_RELEASE})
set(CMAKE_CXX_FLAGS ${CXX_TOOLCHAINFLAGS_RELEASE})
endif()

################################################################################
## Get at the source files
subdirs(Source)
subdirs(UnitTests)

if (NOT FORTRAN_ONLY)
subdirs(UnitTests)
endif()
9 changes: 5 additions & 4 deletions Examples/GraphTheory/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mpif90 main.f90 -o example \
C++ Build Instructions:
mpicxx main.cc -c \
-I../../Source/CPlusPlus -I../../Source/C

mpif90 main.o -o example \
-L../../Build/lib -lNTPolyCPP -lNTPolyWrapper -lNTPoly -fopenmp -lstdc++

Expand All @@ -34,8 +35,8 @@ C++ compiler, and link with the fortran compiler using the flags:
-qopenmp -cxxlib -nofor_main. When using Clang, use -lc++ instead of -lstdc++).

And then run with:
mpirun -np 4 ./example \
--process_rows 2 --process_columns 2 --process_slices 1 \
mpirun -np 1 ./example \
--process_rows 1 --process_columns 1 --process_slices 1 \
--threshold 1e-6 --convergence_threshold 1e-4 \
--number_of_nodes 2048 --extra_connections 128 \
--attenuation 0.7 --output_file Output.mtx
Expand All @@ -44,8 +45,8 @@ Setup python environment:
export PYTHONPATH=../../Build/python

Run with python:
mpirun -np 4 python main.py \
--process_rows 2 --process_columns 2 --process_slices 1 \
mpirun -np 1 python main.py \
--process_rows 1 --process_columns 1 --process_slices 1 \
--threshold 1e-6 --convergence_threshold 1e-4 \
--number_of_nodes 2048 --extra_connections 128 \
--attenuation 0.7 --output_file Output.mtx
Expand Down
1 change: 1 addition & 0 deletions Examples/HydrogenAtom/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ mpif90 main.f90 -o example \
C++ Build Instructions:
mpicxx main.cc -c \
-I../../Source/CPlusPlus -I../../Source/C

mpif90 main.o -o example \
-L../../Build/lib -lNTPolyCPP -lNTPolyWrapper -lNTPoly -fopenmp -lstdc++

Expand Down
1 change: 1 addition & 0 deletions Examples/PremadeMatrix/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mpif90 main.f90 -o example \
C++ Build Instructions:
mpicxx main.cc -c \
-I../../Source/CPlusPlus -I../../Source/C

mpif90 main.o -o example \
-L../../Build/lib -lNTPolyCPP -lNTPolyWrapper -lNTPoly -fopenmp -lstdc++

Expand Down
11 changes: 9 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@ repository. We of course recommend that you download a
to get started.

NTPoly uses CMake as a build system. First, take a look in the Targets
directory. You'll find a list of .cmake files which have example configurations
directory. You'll find a list of `.cmake` files which have example configurations
on popular systems. You should copy one of these files, and create your own
mymachine.cmake file. Then, cd into the Build directory, and type:
> cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/mymachine.cmake ..
There are a few options you can pass to CMake to modify the build. You can set
`-DCMAKE_BUILD_TYPE=Debug` for debugging purposes. You can set the install
directory using the standard `-DCMAKE_INSTALL_PREFIX=/path/to/dir`. You can
also set `-DFORTRAN_ONLY=YES` if you want to only build the Fortran interface.
Note that with just the Fortran interface, it is not possible to perform local
tests.

After that you can build using:
> make
And for the documentation:
> make doc
[Online documentation](https://william-dawson.github.io/NTPoly/) is also
[Online documentation](https://william-dawson.github.io/NTPoly/documentation/) is also
available. Further details about the library can be found on the
[Wiki](https://github.com/william-dawson/NTPoly/wiki).
If you aren't cross compiling, you can perform local tests using:
Expand Down
11 changes: 7 additions & 4 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
subdirs(C)
subdirs(CPlusPlus)
subdirs(Fortran)
subdirs(Swig)
subdirs(Wrapper)

if (NOT FORTRAN_ONLY)
subdirs(C)
subdirs(CPlusPlus)
subdirs(Swig)
subdirs(Wrapper)
endif()
10 changes: 6 additions & 4 deletions Targets/Intel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ set(CMAKE_C_COMPILER mpiicc)
set(CMAKE_Fortran_COMPILER mpiifort)
set(CMAKE_CXX_COMPILER mpiicpc)

set(CXX_TOOLCHAINFLAGS "-O3 -qopenmp -lgomp -fPIC")
set(F_TOOLCHAINFLAGS "-O3 -fpp -qopenmp -fPIC")
# Release suggestions
set(CXX_TOOLCHAINFLAGS_RELEASE "-O3 -qopenmp -lgomp -fPIC")
set(F_TOOLCHAINFLAGS_RELEASE "-O3 -fpp -qopenmp -fPIC")

# Debug suggestions
#set(CXX_TOOLCHAINFLAGS "-O0 -qopenmp -lgomp -fPIC")
#set(F_TOOLCHAINFLAGS "-check bounds -O0 -fpp -qopenmp -fPIC -DPURE=")
set(CXX_TOOLCHAINFLAGS_DEBUG "-O0 -qopenmp -lgomp -fPIC")
set(F_TOOLCHAINFLAGS_DEBUG "-check bounds -O0 -fpp -qopenmp -fPIC -DPURE=")
14 changes: 11 additions & 3 deletions Targets/K.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
################################################################################
# Build file for the K Computer.
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER mpifccpx)
set(CMAKE_Fortran_COMPILER mpifrtpx)
set(CMAKE_CXX_COMPILER mpiFCCpx)
set(CXX_TOOLCHAINFLAGS "-Kfast,-Kparallel,openmp,optmsg=2 --linkfortran")
set(F_TOOLCHAINFLAGS "-Kfast,-Kparallel,openmp,optmsg=2 -Cpp")
set(PYTHON_INCLUDE_PATH "/home/ra000010/a03363/include/python2.7")

# Release Suggestions
set(CXX_TOOLCHAINFLAGS_RELEASE
"-Kfast,-Kparallel,openmp,optmsg=2 --linkfortran")
set(F_TOOLCHAINFLAGS_RELEASE "-Kfast,-Kparallel,openmp,optmsg=2 -Cpp")

# Debug Suggestions
set(CXX_TOOLCHAINFLAGS_DEBUG "--linkfortran")
set(F_TOOLCHAINFLAGS_DEBUG "-Cpp")
9 changes: 7 additions & 2 deletions Targets/Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ set(CMAKE_C_COMPILER mpicc)
set(CMAKE_Fortran_COMPILER mpif90)
set(CMAKE_CXX_COMPILER mpicxx)

set(CXX_TOOLCHAINFLAGS "-O3 -openmp -lgomp -fPIC")
set(F_TOOLCHAINFLAGS "-O3 -cpp -openmp -fPIC")
# Release suggestions
set(CXX_TOOLCHAINFLAGS_RELEASE "-O3 -openmp -lgomp -fPIC")
set(F_TOOLCHAINFLAGS_RELEASE "-O3 -cpp -openmp -fPIC")

# Debug suggestions
set(CXX_TOOLCHAINFLAGS_DEBUG "-O0 -openmp -fPIC")
set(F_TOOLCHAINFLAGS_DEBUG "-O0 -cpp -fPIC")
11 changes: 8 additions & 3 deletions Targets/Mac-python2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CMAKE_Fortran_COMPILER mpif90)
set(CMAKE_CXX_COMPILER mpicxx)
set(PYTHON_EXECUTABLE python2)

# Determine Python Library Path
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"
Expand All @@ -18,7 +19,11 @@ path=get_python_lib(standard_lib=True)+\"/../../Python\"
print path"
OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)

set(CXX_TOOLCHAINFLAGS "-O3 -openmp -framework Accelerate -lgomp")
set(F_TOOLCHAINFLAGS "-O3 -cpp -fopenmp")
# Release Suggestions
set(CXX_TOOLCHAINFLAGS_RELEASE "-O3 -openmp -framework Accelerate -lgomp")
set(F_TOOLCHAINFLAGS_RELEASE "-O3 -cpp -fopenmp")

# Debug suggestions
#set(F_TOOLCHAINFLAGS "-fbounds-check -O0 -fexternal-blas -framework Accelerate -cpp -fopenmp -Wall -DPURE=")
set(CXX_TOOLCHAINFLAGS_DEBUG "-O0 -framework Accelerate")
set(F_TOOLCHAINFLAGS_DEBUG
"-fbounds-check -O0 -fexternal-blas -framework Accelerate -cpp -Wall -DPURE=")
11 changes: 8 additions & 3 deletions Targets/Mac-python3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CMAKE_Fortran_COMPILER mpif90)
set(CMAKE_CXX_COMPILER mpicxx)
set(PYTHON_EXECUTABLE python3)

# Determine Python Library Path
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"
Expand All @@ -18,7 +19,11 @@ path=get_python_lib(standard_lib=True)+\"/../../Python\"
print(path)"
OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)

set(CXX_TOOLCHAINFLAGS "-O3 -openmp -lgomp")
set(F_TOOLCHAINFLAGS "-O3 -cpp -fopenmp")
# Release Suggestions
set(CXX_TOOLCHAINFLAGS_RELEASE "-O3 -openmp -framework Accelerate -lgomp")
set(F_TOOLCHAINFLAGS_RELEASE "-O3 -cpp -fopenmp")

# Debug suggestions
#set(F_TOOLCHAINFLAGS "-fbounds-check -O0 -cpp -fopenmp -Wall -DPURE=")
set(CXX_TOOLCHAINFLAGS_DEBUG "-O0 -framework Accelerate")
set(F_TOOLCHAINFLAGS_DEBUG
"-fbounds-check -O0 -fexternal-blas -framework Accelerate -cpp -Wall -DPURE=")
56 changes: 28 additions & 28 deletions UnitTests/testBuildInstructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,63 @@
import os


def parse_command(fin):
def parse_command(fin, num_commands=1):
'''Keep parsing a command until a blank line is reached.'''
return_string = ""
temp_string = fin.readline()
while(temp_string != '\n'):
return_string = return_string + temp_string
ret_strings = []
for i in range(0, num_commands):
return_string = ""
temp_string = fin.readline()
return return_string
while(temp_string != '\n'):
return_string = return_string + temp_string
temp_string = fin.readline()
ret_strings.append(return_string)
return ret_strings


##########################################################################
if __name__ == "__main__":
check_directory = argv[1]
check_command = argv[2]

build_command = ""
run_command = ""
env_var = os.environ.copy()

build_commands = []
run_commands = []
with open(check_directory + "/ReadMe.md", 'r') as fin:
while True:
line = fin.readline()
if not line:
break
if check_command == "run-fortran":
if line == "Fortran Build Instructions:\n":
build_command = parse_command(fin)
build_commands = parse_command(fin)
if line == "And then run with:\n":
run_command = parse_command(fin)
run_commands = parse_command(fin)
elif check_command == "run-c++":
if line == "C++ Build Instructions:\n":
build_command = parse_command(fin)
build_commands = parse_command(fin, 2)
if line == "And then run with:\n":
run_command = parse_command(fin)
run_commands = parse_command(fin)
pass
elif check_command == "run-python":
if line == "Setup python environment:\n":
build_command = parse_command(fin)
env_var["PYTHONPATH"] = "../../Build/python"
if line == "Run with python:\n":
run_command = parse_command(fin)
run_commands = parse_command(fin)

build_command = [x for x in build_command.split() if x != "\\"]
run_command = [x for x in run_command.split() if x != "\\"]
for i in range(0, len(build_commands)):
build_commands[i] = [x for x in build_commands[i].split() if x != "\\"]
for i in range(0, len(run_commands)):
run_commands[i] = [x for x in run_commands[i].split() if x != "\\"]

os.chdir(check_directory)
if check_command != "run-python":
check = call(build_command)
for bc in build_commands:
check = call(bc)
if check != 0:
print("Build Error")
exit(-1)
check = call(run_command)
for rc in run_commands:
rc = " ".join(rc)
check = call(rc, shell=True, env=env_var)
if check != 0:
print("Run Error")
exit(-1)
else:
env_var = os.environ.copy()
env_var["PYTHONPATH"] = "../../Build/python"
run_command = " ".join(run_command)
check = call(run_command, shell=True, env=env_var)
if check != 0:
print("Python Error")
exit(-1)
Loading

0 comments on commit b56d6e5

Please sign in to comment.