Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten-forty2 committed Aug 12, 2024
2 parents e8840a6 + 5fb5ad6 commit 5cfcad9
Show file tree
Hide file tree
Showing 50 changed files with 2,149 additions and 556 deletions.
65 changes: 45 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX OR ${CMAKE_CXX_COMPILE

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -ansi -pedantic -fno-omit-frame-pointer -Wall")
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -std=c++11 -ansi -pedantic -fno-omit-frame-pointer -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fopenmp")

### debug settings
# run with -DCMAKE_BUILD_TYPE=Debug
Expand Down Expand Up @@ -652,31 +653,55 @@ find_package(Sphinx 3.1)

if (SPHINX_FOUND AND NOT SKIP_SPHINX)
add_subdirectory(doc EXCLUDE_FROM_ALL)
message(STATUS "Search recursive for *.rst from here: " ${CMAKE_SOURCE_DIR})
file(GLOB_RECURSE DOCFILES RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "*.rst")
message(STATUS "DOCFILES: " ${DOCFILES})

file(GLOB_RECURSE PNGFILES RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "*.png")
list(APPEND DOCFILES ${PNGFILES})

message(STATUS "PNGFILES: " ${PNGFILES})

file(GLOB_RECURSE BIBFILES RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "*.bib")
list(APPEND DOCFILES ${BIBFILES})
message(STATUS "Search recursive for related doc files from here: " ${CMAKE_SOURCE_DIR})

message(STATUS "BIBFILES: " ${BIBFILES})

file(GLOB_RECURSE PYFILES RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "doc/paper/*.py")
message(STATUS "PYFILES: " ${PYFILES})
file(GLOB DOCFILES LIST_DIRECTORIES false
RELATIVE "${CMAKE_SOURCE_DIR}"
"*.rst")
message(STATUS "DOCFILES: " ${DOCFILES})

list(APPEND DOCFILES ${PYFILES})
file(GLOB DFILES LIST_DIRECTORIES false
RELATIVE "${CMAKE_SOURCE_DIR}"
"*.md")
message(STATUS "MDFILES: " ${DFILES})
list(APPEND DOCFILES ${DFILES})

set (RECDOCTYPES "*.rst" "*.md" "*.png" "*.svg" "*.bib" "paper/*.py")

foreach (DTYPE ${RECDOCTYPES})
file(GLOB_RECURSE DFILES
LIST_DIRECTORIES false
RELATIVE "${CMAKE_SOURCE_DIR}"
"./doc/${DTYPE}")
message(STATUS "Append DOC files: (${DTYPE}) " ${DFILES})
list(APPEND DOCFILES ${DFILES})
endforeach()
# message(STATUS "RSTFILES: " ${DFILES})

# file(GLOB_RECURSE DFILES LIST_DIRECTORIES false
# RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "./doc/*.md")
# message(STATUS "MDFILES: " ${DFILES})
# list(APPEND DOCFILES ${DFILES})

# file(GLOB_RECURSE DFILES LIST_DIRECTORIES false
# RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "./doc/*.png")
# message(STATUS "PNGFILES: " ${DFILES})
# list(APPEND DOCFILES ${DFILES})

# file(GLOB_RECURSE DFILES LIST_DIRECTORIES false
# RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "./doc/*.bib")
# message(STATUS "BIBFILES: " ${DFILES})
# list(APPEND DOCFILES ${DFILES})

# file(GLOB_RECURSE PYFILES LIST_DIRECTORIES false
# RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" "doc/paper/*.py")
# message(STATUS "PYFILES: " ${PYFILES})
# list(APPEND DOCFILES ${PYFILES})

set(RSTFILES ${DOCFILES} CACHE INTERNAL "RST source file that we need to copy")

set(RSTFILES ${DOCFILES} CACHE INTERNAL "RST source file that we need to copy")
execute_process(
COMMAND ${SPHINX_EXECUTABLE} --version
OUTPUT_VARIABLE SPHINX_VERSION
execute_process(COMMAND ${SPHINX_EXECUTABLE} --version
OUTPUT_VARIABLE SPHINX_VERSION
)

add_custom_target(removedoc
Expand Down
8 changes: 7 additions & 1 deletion INSTALLATION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ retrieve the source code by git
git clone https://github.com/gimli-org/gimli
cd gimli
and install pygimli as a development package
and install pygimli as a development package using conda

.. code-block:: bash
conda develop .
or using pip

.. code-block:: bash
pip install --no-build-isolation --no-deps -e .
Alternatively you could set the PYTHONPATH variable but you would have to care
for dependencies by yourself.

Expand Down
9 changes: 4 additions & 5 deletions core/scripts/buildThirdParty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ CASTXML_URL=https://github.com/CastXML/CastXML.git
#CASTXML_REV=9d7a46d639ce921b8ddd36ecaa23c567d003294a #last functional

# Check for updates https://data.kitware.com/#search/results?query=castxml&mode=text
#CASTXML_BIN_LINUX=https://data.kitware.com/api/v1/file/5b6c5b4d8d777f06857c323b/download # 0.1
#CASTXML_BIN_MAC=https://data.kitware.com/api/v1/file/57b5de9f8d777f10f2696378/download # 0.1.0
#CASTXML_BIN_WIN=https://data.kitware.com/api/v1/file/5b68bfc28d777f06857c1f44/download # 0.1.0

CASTXML_BIN_LINUX=https://data.kitware.com/api/v1/item/63bed74d6d3fc641a02d7e98/download # 0.5.0
CASTXML_BIN_MAC=https://data.kitware.com/api/v1/item/63bed7726d3fc641a02d7e9e/download # 0.5.0
CASTXML_BIN_WIN=https://data.kitware.com/api/v1/file/63bed83a6d3fc641a02d7ea3/download # 0.5.0

if [[ $(uname -m) == 'arm64' ]]; then
Expand All @@ -39,6 +34,10 @@ else
CASTXML_BIN_MAC=https://data.kitware.com/api/v1/item/63bed7726d3fc641a02d7e9e/download # Intel chips
fi

#.. needs testing
# Check for updates https://github.com/CastXML/CastXMLSuperbuild/releases/tag/v0.6.5
#CASTXML_BIN_LINUX=https://github.com/CastXML/CastXMLSuperbuild/releases/download/v0.6.5/

PYGCCXML_URL=https://github.com/CastXML/pygccxml
PYGCCXML_REV=v2.2.1

Expand Down
4 changes: 2 additions & 2 deletions core/src/bert/bertJacobian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ MEMINFO
std::sort(cells.begin(), cells.end(), lessCellMarker);

double maxMemSize = max(0.0, getEnvironment("SENSMATMAXMEM", 0.0, verbose));
double maxSizeNeeded = mByte((double)nData * nModel * sizeof(double));
double maxSizeNeeded = MByte(nData * nModel * sizeof(double));

if (maxMemSize > 0 && verbose){
std::cout << "Size of S: " << maxSizeNeeded << " MB" << std::endl;
Expand Down Expand Up @@ -329,7 +329,7 @@ MEMINFO
throwError(WHERE_AM_I + " sorry, size of single sensitivity-row exceeds memory limitations.");
}

std::cout << "Size of S cluster: " << mByte((double)nData * modelCluster * sizeof(ValueType)) << " MB" << std::endl;
std::cout << "Size of S cluster: " << MByte(nData * modelCluster * sizeof(ValueType)) << " MB" << std::endl;
std::cout << "Using model cluster " << nModel << " x " << modelCluster << std::endl;

S.resize(nData, modelCluster);
Expand Down
12 changes: 6 additions & 6 deletions core/src/bert/dcfemmodelling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ void DCMultiElectrodeModelling::init_(){
Index nThreads = getEnvironment("BERTTHREADS", 0, verbose_);
nThreads = getEnvironment("BERT_NUM_THREADS", 0, verbose_);
if (nThreads > 0) setThreadCount(nThreads);

//log(Info, "DCMultiElectrodeModelling init with thread count:", nThreads);
}

void DCMultiElectrodeModelling::setComplex(bool c) {
Expand Down Expand Up @@ -1847,9 +1847,9 @@ void DCMultiElectrodeModelling::calculateK_(const std::vector < ElectrodeShape *
solver = new LinSolver(debug);
solverNeedsDelete = true;
dynamic_cast< LinSolver * >(solver)->setMatrix(S_, 1);
if (debug) std::cout << "Factorize (" << solver->name() << ") matrix ... " << swatch.duration() << std::endl;
if (debug) std::cout << "Factorize (" << solver->name() << ") matrix ... " << swatch.duration() << std::endl;
}

// MEMINFO

Vector < ValueType > sol(S_.cols());
Expand Down Expand Up @@ -2208,7 +2208,7 @@ void DCSRMultiElectrodeModelling::calculateK(const std::vector < ElectrodeShape
dynamic_cast< LinSolver * >(solver)->setMatrix(S_, 1);
if (debug) std::cout << "Factorize (" << solver->name() << ") matrix ... " << swatch.duration() << std::endl;
}


// MEMINFO

Expand Down Expand Up @@ -2288,11 +2288,11 @@ void DCSRMultiElectrodeModelling::calculateK(const std::vector < ElectrodeShape

if (singleVerbose) singleVerbose = false;
}

if (solverNeedsDelete == true){
delete solver;
}

}

} // namespace GIMLI{
7 changes: 7 additions & 0 deletions core/src/gimli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
std::mutex __GIMLILogWriteMutex__;
#endif

#include <omp.h>

namespace GIMLI{

Expand All @@ -48,6 +49,11 @@ static int __GIMLI_DEEP_DEBUG__ = 0;

Index __setTC__(){
// to close to number of cpu can bring significent shedular overhead
int omp = getEnvironment("OMP_NUM_THREADS", -1, false);
if (omp == -1){
omp_set_num_threads(min(8, numberOfCPU()-2));
}

int tc = getEnvironment("OPENBLAS_NUM_THREADS", -1, false);

if (tc == -1){
Expand Down Expand Up @@ -85,6 +91,7 @@ void setThreadCount(Index nThreads){
log(Debug, "Set amount of threads to " + str(nThreads));
//log(Debug, "omp_get_max_threads: " + str(omp_get_max_threads()));
//omp_set_num_threads

#if OPENBLAS_CBLAS_FOUND
openblas_set_num_threads(nThreads);
//omp_set_num_threads
Expand Down
29 changes: 21 additions & 8 deletions core/src/memwatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
#define USE_PROC_READPROC 0
#endif

#if USE_BOOST_THREAD
#include <boost/thread.hpp>
/*! Lock proc reading to be thread safe */
static boost::mutex __readproc__mutex__;
#include <mutex>
static std::mutex __readproc__mutex__;

#ifdef WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <mutex>
static std::mutex __readproc__mutex__;
#include <unistd.h>
#endif

namespace GIMLI {
Expand Down Expand Up @@ -73,7 +73,7 @@ double MemWatch::inUse() {

PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))){
double ret = mByte(pmc.WorkingSetSize);
double ret = MByte(pmc.WorkingSetSize);
return ret;
} else { return 0; }
#else // no WINDOWS
Expand All @@ -87,7 +87,7 @@ double MemWatch::inUse() {
// __MS("resident: " << usage.resident/1024)// number of resident set (non-swapped) pages (4k)
// __MS("share: " << usage.share/1024)
// __MS("rss: " << usage.rss/1024)
double ret = mByte(usage.vsize);
double ret = MByte(usage.vsize);
return ret;
#else
// no windows and no libproc
Expand Down Expand Up @@ -116,4 +116,17 @@ void MemWatch::info(const std::string & str){
}
}

long maxMem(){
#if defined(WIN32_LEAN_AND_MEAN)
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
return status.ullTotalPhys;
#else
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
#endif
}

} // namespace GIMLI
8 changes: 6 additions & 2 deletions core/src/memwatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
namespace GIMLI{

/*! Convert byte into KByte. */
inline double kByte(long byte){ return double(byte / 1024.0); }
inline double KByte(long byte){ return double(byte / 1024.0); }

/*! Convert byte into MByte */
inline double mByte(long byte){ return double(byte / (1024.0 * 1024.0)); }
inline double MByte(long byte){ return double(byte / (1024.0 * 1024.0)); }

/*! Convert byte into GByte */
inline double GByte(long byte){ return double(byte / (1024.0 * 1024.0 * 1024)); }

//! Memory watch.
/*! Class that might help debugging memory usage.
Expand Down Expand Up @@ -72,6 +75,7 @@ inline double memoryInUse(){
return GIMLI::MemWatch::instance().inUse();
}

DLLEXPORT long maxMem();

} // namespace GIMLI

Expand Down
12 changes: 6 additions & 6 deletions core/src/modellingbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ModellingBase::init_() {
constraints_ = 0;
dataContainer_ = 0;

nThreads_ = numberOfCPU();
nThreads_ = min(16, numberOfCPU()-2);
nThreadsJacobian_ = 1;

ownJacobian_ = false;
Expand Down Expand Up @@ -401,13 +401,13 @@ RSparseMapMatrix & ModellingBase::constraintsRef() {
return *dynamic_cast < RSparseMapMatrix *>(constraints_);
}

RVector ModellingBase::createMappedModel(const RVector & model,
RVector ModellingBase::createMappedModel(const RVector & model,
double background) const {
if (mesh_ == 0) throwError("ModellingBase has no mesh for ModellingBase::createMappedModel");

// __MS("ModellingBase::createMappedModel: " << this << " rm: " << regionManager_
// << " " << model.size() << " " << mesh_->cellCount())

if (model.size() == mesh_->cellCount()) {
IVector cM(mesh_->cellMarkers());

Expand Down Expand Up @@ -467,10 +467,10 @@ RVector ModellingBase::createMappedModel(const RVector & model,
// if (abs(cellAtts[i]) < TOLERANCE){ // this will never work since the prior prolongation
if (mesh_->cell(i).marker() <= MARKER_FIXEDVALUE_REGION){
// setting fixed values
SIndex regionMarker = -(mesh_->cell(i).marker() -
SIndex regionMarker = -(mesh_->cell(i).marker() -
MARKER_FIXEDVALUE_REGION);

// __MS(regionManagerInUse_ << " " << this << " " <<
// __MS(regionManagerInUse_ << " " << this << " " <<
// regionManager_->region(regionMarker)->fixValue())

if (regionManagerInUse_){
Expand Down Expand Up @@ -527,7 +527,7 @@ void ModellingBase::setRegionManager(RegionManager * reg){
} else {
regionManagerInUse_ = false;
regionManager_ = new RegionManager(verbose_);
ownRegionManager_ = true;
ownRegionManager_ = true;
// __MS("ModellingBase::setRegionManager new " << this << " rm: " << regionManager_)
}
// __MS("MB:setRegionManager: " << this << " rm: " << regionManager_)
Expand Down
11 changes: 7 additions & 4 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# recommand to create a suitable virtual environment first:
# python -m venv $ENVNAME
# source $ENVNAME/bin/activate
# python -m venv .venv --prompt=gimli
# source .venv/bin/activate
# python -m pip install -r dev_requirements.txt
# python -m pip list
# python -m pip install package==version

# needed to build
# needed
setuptools
numpy>=1.25
matplotlib
pyqt5 #pyqtagg backend
pyplusplus==1.8.4
pygccxml==2.0.0

Expand All @@ -18,7 +21,7 @@ ipython
jupytext

# optional, but strongly recommended
scipy>=1.11
scipy>=1.11
scooby
pyvista[all]>=0.42
pyqt5
Expand Down
Loading

0 comments on commit 5cfcad9

Please sign in to comment.