Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile speedup #979

Merged
merged 15 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ on:

jobs:
ubuntu-multiple-pythons:
name: Ubuntu with Python ${{ matrix.python-version }}
name: ${{ matrix.os }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ '3.5', '3.6', '3.7', '3.8', '3.9' ]
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
os: ['ubuntu-18.04', 'ubuntu-20.04']
fail-fast: false
steps:
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml scons numpy cython h5py pandas
- name: Build Cantera
run: python3 `which scons` build -j2
run: python3 `which scons` build -j2 debug=n
- name: Test Cantera
run: python3 `which scons` test

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml scons numpy cython h5py pandas
- name: Build Cantera
run: python3 `which scons` build -j2
run: python3 `which scons` build -j2 debug=n
- name: Test Cantera
run: python3 `which scons` test

Expand All @@ -101,15 +101,15 @@ jobs:
architecture: x64
- name: Install Apt dependencies
run: |
sudo apt-get install libboost-dev gfortran liblapack-dev libblas-dev
sudo apt-get install libboost-dev gfortran liblapack-dev libblas-dev libsundials-dev
- name: Upgrade pip
run: python3 -m pip install -U pip setuptools wheel
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml scons numpy cython h5py pandas
- name: Build Cantera
run: |
python3 `which scons` build blas_lapack_libs=lapack,blas coverage=y \
optimize=n -j2
optimize=n no_optimize_flags=-DNDEBUG -j2
- name: Test Cantera
run: python3 `which scons` test
- name: Upload Coverage to Codecov
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
python3 -m pip install ruamel.yaml scons numpy cython sphinx\<4.0 \
sphinxcontrib-katex sphinxcontrib-matlabdomain sphinxcontrib-doxylink
- name: Build Cantera with documentation
run: python3 `which scons` build -j2 doxygen_docs=y sphinx_docs=y
run: python3 `which scons` build -j2 doxygen_docs=y sphinx_docs=y debug=n optimize=n
# The known_hosts key is generated with `ssh-keygen -F cantera.org` from a
# machine that has previously logged in to cantera.org and trusts
# that it logged in to the right machine
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
python3-ruamel.yaml python-numpy cython3 libsundials-dev liblapack-dev \
libblas-dev
- name: Build Cantera
run: scons build python_cmd=/usr/bin/python3 blas_lapack_libs=lapack,blas -j2
run: scons build python_cmd=/usr/bin/python3 blas_lapack_libs=lapack,blas -j2 debug=n
- name: Test Cantera
run: scons test

Expand All @@ -189,7 +189,7 @@ jobs:
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: ['3.5', '3.6', '3.7', '3.8', '3.9']
python-version: ['3.6', '3.7', '3.8', '3.9']
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -208,7 +208,7 @@ jobs:
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml scons numpy cython h5py pandas matplotlib scipy
- name: Build Cantera
run: python3 `which scons` build -j2
run: python3 `which scons` build -j2 debug=n
- name: Run the examples
# See https://unix.stackexchange.com/a/392973 for an explanation of the -exec part
run: |
Expand Down Expand Up @@ -254,7 +254,7 @@ jobs:
run: |
scons build extra_inc_dirs=$CONDA_PREFIX/include:$CONDA_PREFIX/include/eigen3 \
extra_lib_dirs=$CONDA_PREFIX/lib system_fmt=y system_eigen=y system_yamlcpp=y \
system_sundials=y -j2 VERBOSE=True
system_sundials=y -j2 VERBOSE=True debug=n
shell: bash -l {0}
- name: Test Cantera
run: scons test
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
python3 -m pip install ruamel.yaml scons numpy h5py pandas;
python3 -m pip install https://github.com/cython/cython/archive/master.zip --install-option='--no-cython-compile';
- name: Build Cantera
run: python3 `which scons` build blas_lapack_libs=lapack,blas python_package='full' -j2
run: python3 `which scons` build blas_lapack_libs=lapack,blas python_package='full' -j2 debug=n
- name: Test Cantera
run: python3 `which scons` test

Expand All @@ -293,13 +293,10 @@ jobs:
matrix:
os: ['windows-2019']
vs-toolset: ['14.0', '14.2']
python-version: [ '3.5', '3.6', '3.7', '3.8', '3.9' ]
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
# Must use windows-2016 image because it installs VS2017 (MSVC 14.1)
# Scons cannot find MSVC 14.1 when VS2019 is installed
include:
- os: 'windows-2016'
vs-toolset: '14.1'
python-version: '3.5'
- os: 'windows-2016'
vs-toolset: '14.1'
python-version: '3.6'
Expand Down
18 changes: 14 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,12 @@ config_options = [
'system_fmt',
"""Select whether to use the fmt library from a system installation
('y'), from a Git submodule ('n'), or to decide automatically
('default').""",
('default'). If you do not want to use the Git submodule and fmt
is not installed directly into system include and library
directories, then you will need to add those directories to
'extra_inc_dirs' and 'extra_lib_dirs'. This installation of fmt
must include the shared version of the library, for example,
'libfmt.so'.""",
'default', ('default', 'y', 'n')),
EnumVariable(
'system_yamlcpp',
Expand Down Expand Up @@ -866,8 +871,9 @@ if not conf.CheckCXXHeader('cmath', '<>'):
config_error('The C++ compiler is not correctly configured.')


def get_expression_value(includes, expression):
s = ['#include ' + i for i in includes]
def get_expression_value(includes, expression, defines=()):
s = ['#define ' + d for d in defines]
s.extend('#include ' + i for i in includes)
s.extend(('#define Q(x) #x',
'#define QUOTE(x) Q(x)',
'#include <iostream>',
Expand Down Expand Up @@ -909,7 +915,7 @@ if env['system_fmt'] in ('n', 'default'):
' git submodule update --init --recursive ext/fmt\n')

fmt_include = '<fmt/format.h>' if env['system_fmt'] else '"../ext/fmt/include/fmt/format.h"'
fmt_version_source = get_expression_value([fmt_include], 'FMT_VERSION')
fmt_version_source = get_expression_value([fmt_include], 'FMT_VERSION', ['FMT_HEADER_ONLY'])
retcode, fmt_lib_version = conf.TryRun(fmt_version_source, '.cpp')
try:
fmt_lib_version = divmod(float(fmt_lib_version.strip()), 10000)
Expand Down Expand Up @@ -1665,6 +1671,10 @@ else:
linkLibs.extend(env['sundials_libs'])
linkSharedLibs.extend(env['sundials_libs'])

if env['system_fmt']:
linkLibs.append('fmt')
linkSharedLibs.append('fmt')

if env['system_yamlcpp']:
linkLibs.append('yaml-cpp')
linkSharedLibs.append('yaml-cpp')
Expand Down
4 changes: 4 additions & 0 deletions ext/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ for subdir, extensions, prepFunction in libs:

if not env['system_fmt']:
license_files.append(('fmtlib', 'fmt/LICENSE.rst'))
localenv = prep_default(env)
localenv.Prepend(CPPPATH=Dir('#ext/fmt/include'))
libraryTargets.extend(
localenv.SharedObject(mglob(localenv, 'fmt/src', 'cc')))
for name in ('format.h', 'ostream.h', 'printf.h', 'core.h', 'format-inl.h'):
build(copyenv.Command("#include/cantera/ext/fmt/" + name,
"#ext/fmt/include/fmt/" + name,
Expand Down
6 changes: 1 addition & 5 deletions include/cantera/base/AnyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
#define CT_ANYMAP_H

#include "cantera/base/ct_defs.h"
#include "cantera/base/global.h"
#include "cantera/base/Units.h"
#include "cantera/base/ctexceptions.h"
#include "cantera/base/Units.h"

#include <string>
#include <vector>
#include <memory>
#include <unordered_map>
#include <functional>

Expand Down
104 changes: 15 additions & 89 deletions include/cantera/base/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
#ifndef CT_ARRAY_H
#define CT_ARRAY_H

#include "utilities.h"

#include "ct_defs.h"
#include <iostream>
#include <cstring>

namespace Cantera
{
Expand Down Expand Up @@ -48,11 +46,7 @@ class Array2D
/**
* Default constructor. Create an empty array.
*/
Array2D() :
m_data(0),
m_nrows(0),
m_ncols(0) {
}
Array2D();

//! Constructor.
/*!
Expand All @@ -62,10 +56,7 @@ class Array2D
* @param n Number of columns
* @param v Default fill value. The default is 0.0
*/
Array2D(const size_t m, const size_t n, const doublereal v = 0.0)
: m_data(0), m_nrows(m), m_ncols(n) {
m_data.assign(n*m, v);
}
Array2D(const size_t m, const size_t n, const double v=0.0);

//! Constructor.
/*!
Expand All @@ -77,43 +68,21 @@ class Array2D
* @param values Initial values of the array. Must be of length m*n, and
* stored in column-major order.
*/
Array2D(const size_t m, const size_t n, const doublereal* values)
: m_data(0), m_nrows(m), m_ncols(n) {
m_data.assign(values, values + n*m);
}
Array2D(const size_t m, const size_t n, const double* values);

Array2D(const Array2D& y) :
m_data(0),
m_nrows(0),
m_ncols(0) {
m_nrows = y.m_nrows;
m_ncols = y.m_ncols;
m_data = y.m_data;
}
Array2D(const Array2D& y);

virtual ~Array2D() {}

Array2D& operator=(const Array2D& y) {
if (&y == this) {
return *this;
}
m_nrows = y.m_nrows;
m_ncols = y.m_ncols;
m_data = y.m_data;
return *this;
}
Array2D& operator=(const Array2D& y);

//! Resize the array, and fill the new entries with 'v'
/*!
* @param n This is the number of rows
* @param m This is the number of columns in the new matrix
* @param v Default fill value -> defaults to zero.
*/
void resize(size_t n, size_t m, doublereal v = 0.0) {
m_nrows = n;
m_ncols = m;
m_data.resize(n*m, v);
}
void resize(size_t n, size_t m, double v=0.0);

//! Append a column to the existing matrix using a std vector
/*!
Expand All @@ -122,13 +91,7 @@ class Array2D
* @param c This vector is the entries in the column to be added. It must
* have a length equal to m_nrows or greater.
*/
void appendColumn(const vector_fp& c) {
m_ncols++;
m_data.resize(m_nrows*m_ncols);
for (size_t m = 0; m < m_nrows; m++) {
value(m_ncols, m) = c[m];
}
}
void appendColumn(const vector_fp& c);

//! Append a column to the existing matrix
/*!
Expand All @@ -137,36 +100,22 @@ class Array2D
* @param c This vector of doubles is the entries in the column to be
* added. It must have a length equal to m_nrows or greater.
*/
void appendColumn(const doublereal* const c) {
m_ncols++;
m_data.resize(m_nrows*m_ncols);
for (size_t m = 0; m < m_nrows; m++) {
value(m_ncols, m) = c[m];
}
}
void appendColumn(const double* const c);

//! Set the nth row to array rw
/*!
* @param n Index of the row to be changed
* @param rw Vector for the row. Must have a length of m_ncols.
*/
void setRow(size_t n, const doublereal* const rw) {
for (size_t j = 0; j < m_ncols; j++) {
m_data[m_nrows*j + n] = rw[j];
}
}
void setRow(size_t n, const double* const rw);

//! Get the nth row and return it in a vector
/*!
* @param n Index of the row to be returned.
* @param rw Return Vector for the operation. Must have a length of
* m_ncols.
*/
void getRow(size_t n, doublereal* const rw) {
for (size_t j = 0; j < m_ncols; j++) {
rw[j] = m_data[m_nrows*j + n];
}
}
void getRow(size_t n, double* const rw);

//! Set the values in column m to those in array col
/*!
Expand All @@ -175,11 +124,7 @@ class Array2D
* @param m Column to set
* @param col pointer to a col vector. Vector must have a length of m_nrows.
*/
void setColumn(size_t m, doublereal* const col) {
for (size_t i = 0; i < m_nrows; i++) {
m_data[m_nrows*m + i] = col[i];
}
}
void setColumn(size_t m, double* const col);

//! Get the values in column m
/*!
Expand All @@ -188,11 +133,7 @@ class Array2D
* @param m Column to set
* @param col pointer to a col vector that will be returned
*/
void getColumn(size_t m, doublereal* const col) {
for (size_t i = 0; i < m_nrows; i++) {
col[i] = m_data[m_nrows*m + i];
}
}
void getColumn(size_t m, double* const col);

//! Set all of the entries to zero
void zero() {
Expand Down Expand Up @@ -323,19 +264,7 @@ class Array2D
* @param m Object of type Array2D that you are querying
* @returns a reference to the ostream.
*/
inline std::ostream& operator<<(std::ostream& s, const Array2D& m)
{
size_t nr = m.nRows();
size_t nc = m.nColumns();
for (size_t i = 0; i < nr; i++) {
s << m(i,0);
for (size_t j = 1; j < nc; j++) {
s << ", " << m(i,j);
}
s << std::endl;
}
return s;
}
std::ostream& operator<<(std::ostream& s, const Array2D& m);

//! Overload the times equals operator for multiplication of a matrix and a
//! scalar.
Expand All @@ -345,10 +274,7 @@ inline std::ostream& operator<<(std::ostream& s, const Array2D& m)
* @param m Matrix
* @param a scalar
*/
inline void operator*=(Array2D& m, doublereal a)
{
scale(m.begin(), m.end(), m.begin(), a);
}
void operator*=(Array2D& m, double a);

}

Expand Down
1 change: 0 additions & 1 deletion include/cantera/base/FactoryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef CT_FACTORY_BASE
#define CT_FACTORY_BASE

#include <vector>
#include <mutex>
#include <unordered_map>
#include <functional>
Expand Down
Loading