Skip to content

Commit 0ae1008

Browse files
authored
Merge pull request #382 from dilawar/chamcham
Maintenance release 3.1.5
2 parents 4c2e7fa + 114b9eb commit 0ae1008

File tree

6 files changed

+116
-226
lines changed

6 files changed

+116
-226
lines changed

.travis/travis_prepare_linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ apt-get install -qq libhdf5-serial-dev
2525
apt-get install -qq make cmake
2626
apt-get install -qq python-numpy python-matplotlib python-networkx python-pip
2727
apt-get install -qq python3-numpy python3-matplotlib python3-dev
28-
apt-get install -qq libboost-all-dev
28+
apt-get install -qq libboost-all-dev liblapack-dev libblas-dev
2929
apt-get install -qq libgsl0-dev
3030
apt-get install -qq python-pip python3-pip
3131
apt-get install -qq libgraphviz-dev

CMakeLists.txt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
2-
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
3-
4-
5-
project(pymoose)
6-
7-
if(COMMAND cmake_policy)
8-
cmake_policy(SET CMP0003 NEW)
9-
cmake_policy(SET CMP0004 NEW)
10-
if(POLICY CMP0050)
11-
cmake_policy(SET CMP0050 OLD)
12-
endif(POLICY CMP0050)
13-
endif(COMMAND cmake_policy)
14-
2+
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
3+
project(MOOSE)
154

165
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
176
include(CheckCXXCompiler.cmake)
@@ -34,7 +23,7 @@ endif()
3423
# If from command line, version info is not passed, use the git to generate a
3524
# version file. If GIT fails, use the previous known version.
3625
if(NOT VERSION_MOOSE)
37-
set(VERSION_MOOSE "3.1.3-${GIT_HEAD}")
26+
set(VERSION_MOOSE "3.1.5-${GIT_HEAD}")
3827
endif()
3928

4029
add_definitions( -DMOOSE_VERSION="${VERSION_MOOSE}")
@@ -91,9 +80,10 @@ endif()
9180
option(DEBUG "Build with debug support" OFF)
9281
option(GPROF "Build for profiling using gprof" OFF)
9382
option(ENABLE_UNIT_TESTS "Enable unit tests (DEBUG should also be ON)" OFF)
83+
option(WITH_PYTHON "Build native python extension" ON)
9484
option(WITH_MPI "Enable Openmpi support" OFF)
9585
option(WITH_BOOST "Use boost library instead of GSL" OFF)
96-
option(WITH_GSL "Use gsl-library. Alternative is WITH_BOOST" ON)
86+
option(WITH_GSL "Use gsl library. Alternative is WITH_BOOST" ON)
9787
option(PARALLELIZED_SOLVERS "Use parallel version of GSOLVE. (alpha)" OFF )
9888
option(PARALLELIZED_CLOCK "High level parallelization of moose::Clock (alpha)" OFF )
9989

@@ -366,7 +356,7 @@ if(MACOSX)
366356
${SYSTEM_SHARED_LIBS}
367357
${CMAKE_DL_LIBS}
368358
)
369-
ELSE(MACOSX)
359+
else(MACOSX)
370360
target_link_libraries(libmoose
371361
"-Wl,--whole-archive"
372362
${MOOSE_LIBRARIES}
@@ -384,8 +374,15 @@ endif( WITH_BOOST )
384374

385375

386376
######################### BUILD PYMOOSE ########################################
387-
# This target is built by pymoose/CMakeLists.txt file.
388-
add_subdirectory( pymoose )
377+
# Root of all python module.
378+
if(WITH_PYTHON)
379+
# find_package(Python3 COMPONENTS Interpreter Development)
380+
set(Python_ADDITIONAL_VERSIONS 2.7)
381+
find_package(PythonInterp 3.4)
382+
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
383+
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
384+
add_subdirectory(pymoose)
385+
endif()
389386

390387
# always override debian default installation directory. It will be installed in
391388
# site-packages instead of dist-packages.

cmake_modules/FindNumPy.cmake

Lines changed: 0 additions & 104 deletions
This file was deleted.

pymoose/CMakeLists.txt

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,44 @@ add_definitions(-DPYMOOSE)
22
include_directories(../basecode ../msg)
33

44
set(PYMOOSE_SRCS
5-
moosemodule.cpp
6-
vec.cpp
7-
mfield.cpp
8-
pymooseinit.cpp
9-
melement.cpp
10-
test_moosemodule.cpp
11-
PyRun.cpp
12-
)
5+
moosemodule.cpp
6+
vec.cpp
7+
mfield.cpp
8+
pymooseinit.cpp
9+
melement.cpp
10+
test_moosemodule.cpp
11+
PyRun.cpp)
1312

14-
# current binary directory using cmake.
15-
add_library( _moose MODULE ${PYMOOSE_SRCS} )
16-
set(PYMOOSE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/python/moose")
13+
# Python development.
14+
execute_process(COMMAND ${PYTHON_EXECUTABLE}-config --includes
15+
OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS
16+
OUTPUT_STRIP_TRAILING_WHITESPACE)
17+
message(STATUS "Python include paths: ${PYTHON_INCLUDE_FLAGS}")
1718

18-
find_package(PythonInterp REQUIRED)
19-
execute_process( COMMAND
20-
${PYTHON_EXECUTABLE} -c
21-
"import importlib.machinery
22-
print(importlib.machinery.EXTENSION_SUFFIXES[-1])"
23-
OUTPUT_VARIABLE PYTHON_SO_EXTENSION
24-
OUTPUT_STRIP_TRAILING_WHITESPACE
25-
)
26-
if(NOT PYTHON_SO_EXTENSION)
27-
set(PYTHON_SO_EXTENSION ".so")
28-
endif()
29-
message( STATUS "Python so extension ${PYTHON_SO_EXTENSION}" )
3019

31-
find_package(NumPy REQUIRED)
32-
include_directories(${NUMPY_INCLUDE_DIRS})
33-
add_definitions(-DUSE_NUMPY)
20+
# Numpy
21+
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.get_include())"
22+
OUTPUT_VARIABLE Python_NumPy_INCLUDE_DIRS
23+
OUTPUT_STRIP_TRAILING_WHITESPACE)
24+
message(STATUS "NumPy include path: ${Python_NumPy_INCLUDE_DIRS}")
3425

26+
add_library( _moose MODULE ${PYMOOSE_SRCS} )
27+
set(PYMOOSE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python/moose")
28+
add_definitions(-DUSE_NUMPY)
3529
add_definitions(-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)
3630

37-
execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --includes
38-
OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS
39-
OUTPUT_STRIP_TRAILING_WHITESPACE
40-
)
41-
execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --libs
42-
OUTPUT_VARIABLE PYTHON_LIBRARIES
43-
OUTPUT_STRIP_TRAILING_WHITESPACE
44-
)
45-
message( STATUS "Python include flags: ${PYTHON_INCLUDE_FLAGS}" )
46-
set_target_properties(_moose PROPERTIES
31+
target_include_directories(_moose
32+
PRIVATE ${PYTHON_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS})
33+
34+
set(PYTHON_SO_EXTENSION ".so")
35+
set_target_properties(_moose PROPERTIES
4736
COMPILE_DEFINITIONS "PYMOOSE"
48-
COMPILE_FLAGS "${PYTHON_INCLUDE_FLAGS}"
37+
COMPILE_FLAGS ${PYTHON_INCLUDE_FLAGS}
4938
LIBRARY_OUTPUT_DIRECTORY ${PYMOOSE_OUTPUT_DIRECTORY}
5039
PREFIX ""
5140
SUFFIX ${PYTHON_SO_EXTENSION}
5241
)
5342

54-
if(NOT(PYTHON_SO_EXTENSION STREQUAL ""))
55-
set_target_properties(_moose PROPERTIES
56-
SUFFIX ${PYTHON_SO_EXTENSION})
57-
endif()
5843

5944
# see issue #80
6045
if(HDF5_LIBRARY_DIRS)
@@ -92,6 +77,4 @@ add_custom_command(TARGET _moose POST_BUILD
9277
" Run 'sudo make install' to install it. "
9378
" "
9479
"NOTE: Run 'pip uninstall moose' to uninstall moose."
95-
VERBATIM
96-
)
97-
80+
VERBATIM)

pymoose/moosemodule.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <cstring>
4545
#include <map>
4646
#include <ctime>
47+
#include <cstring>
4748
#include <csignal>
4849
#include <exception>
4950

@@ -75,11 +76,11 @@ using namespace std;
7576
extern void testSync();
7677
extern void testAsync();
7778

78-
extern void testSyncArray(
79-
unsigned int size,
80-
unsigned int numThreads,
81-
unsigned int method
82-
);
79+
extern void testSyncArray(
80+
unsigned int size,
81+
unsigned int numThreads,
82+
unsigned int method
83+
);
8384

8485
extern void testShell();
8586
extern void testScheduling();
@@ -103,16 +104,16 @@ extern void test_moosemodule();
103104

104105

105106
extern Id init(
106-
int argc, char ** argv, bool& doUnitTests
107-
, bool& doRegressionTests, unsigned int& benchmark
108-
);
107+
int argc, char ** argv, bool& doUnitTests
108+
, bool& doRegressionTests, unsigned int& benchmark
109+
);
109110

110111
extern void initMsgManagers();
111112
extern void destroyMsgManagers();
112113

113114
extern void speedTestMultiNodeIntFireNetwork(
114-
unsigned int size, unsigned int runsteps
115-
);
115+
unsigned int size, unsigned int runsteps
116+
);
116117

117118
extern void mooseBenchmarks( unsigned int option );
118119

@@ -2717,14 +2718,25 @@ int defineDestFinfos(const Cinfo * cinfo)
27172718
// if (name.find("get") == 0 || name.find("set") == 0){
27182719
// continue;
27192720
// }
2720-
PyGetSetDef destFieldGetSet;
2721+
PyGetSetDef destFieldGetSet = {.name = (char*) name.c_str()
2722+
, .get=nullptr, .set=nullptr
2723+
, .doc= (char*) "Destination field"
2724+
, .closure=nullptr};
27212725
vec.push_back(destFieldGetSet);
27222726

2723-
vec[currIndex].name = strdup(name.c_str());
2724-
vec[currIndex].doc = (char*) "Destination field";
2727+
// Dilawar:
2728+
// strncpy can not write to const char* especially with clang++.
2729+
// Ref: https://docs.python.org/3/c-api/structures.html#c.PyGetSetDef
2730+
//vec[currIndex].name = (char*)calloc(name.size() + 1, sizeof(char));
2731+
//strncpy(vec[currIndex].name,
2732+
// const_cast<char*>(name.c_str()),
2733+
// name.size());
2734+
// vec[currIndex].doc = (char*) "Destination field";
2735+
27252736
vec[currIndex].get = (getter)moose_ObjId_get_destField_attr;
27262737
PyObject *args = PyTuple_New(1);
2727-
if (!args || !vec[currIndex].name) {
2738+
if (!args || !vec[currIndex].name)
2739+
{
27282740
cerr << "moosemodule.cpp: defineDestFinfos: allocation failed\n";
27292741
return 0;
27302742
}
@@ -3225,15 +3237,15 @@ PyMODINIT_FUNC MODINIT(_moose)
32253237

32263238
clock_t defclasses_end = clock();
32273239

3228-
LOG( moose::info, "`Time to define moose classes:"
3229-
<< (defclasses_end - defclasses_start) * 1.0 /CLOCKS_PER_SEC
3240+
LOG( moose::info, "`Time to define moose classes:"
3241+
<< (defclasses_end - defclasses_start) * 1.0 /CLOCKS_PER_SEC
32303242
);
32313243

32323244
PyGILState_Release(gstate);
32333245
clock_t modinit_end = clock();
32343246

3235-
LOG( moose::info, "`Time to initialize module:"
3236-
<< (modinit_end - modinit_start) * 1.0 /CLOCKS_PER_SEC
3247+
LOG( moose::info, "`Time to initialize module:"
3248+
<< (modinit_end - modinit_start) * 1.0 /CLOCKS_PER_SEC
32373249
);
32383250

32393251
if (doUnitTests)

0 commit comments

Comments
 (0)