Skip to content

Commit

Permalink
Merge pull request #9 from rikigigi/devel
Browse files Browse the repository at this point in the history
fixed macos compilation, added ci for macos, fixed return value of cl…
  • Loading branch information
rikigigi authored Jul 21, 2021
2 parents eacf836 + c3d687c commit a7ad5ac
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ jobs:
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest ]
python-version: [ "3.7" ]
steps:
- uses: actions/checkout@v2

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Expand All @@ -32,7 +40,7 @@ jobs:
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
sudo -E ${{github.workspace}}/install/install_python.sh
env:
SP_DIR: /usr/lib/python3/dist-packages
SP_DIR: ${{github.workspace}}/tests
SOURCE_DIR: ${{github.workspace}}
BUILD_DIR: ${{github.workspace}}/build

Expand All @@ -43,10 +51,11 @@ jobs:
run: |
ctest -C ${{env.BUILD_TYPE}}
../install/install_test.sh
cd ../tests/ && pytest -sv .
cd ../tests/ && python -m pytest -sv .
- name: TestCli
run: |
${{github.workspace}}/tests/test_cli.sh
env:
SOURCE_DIR: ${{github.workspace}}
BUILD_DIR: ${{github.workspace}}/build
PYTHONPATH: /usr/lib/python${{ matrix.python-version }}/dist-packages
2 changes: 2 additions & 0 deletions analisi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ int main(int argc, char ** argv)

if (argc<=1 || ( (output_conversion!="" || output_conversion_gro.size()>0 ) && input=="") ||vm.count("help")|| (vm.count("loginput")==0 && ( debug2 || heat_coeff ) ) || skip<=0 || stop_acf<0 || final<0 || (!sub_mean && (sub_mean_start!=0) ) || sub_mean_start<0 || !(kk_l.size()==0 || kk_l.size()==2)){
std::cout << options << "\n";
if (vm.count("help"))
return 0;
return 1;
}

Expand Down
13 changes: 6 additions & 7 deletions lib/include/calcolamultithread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ template <class T, int FLAGS_T = CalcolaMultiThread_Flags::PARALLEL_SPLIT_AVERAG
class CalcolaMultiThread
{
public:
CalcolaMultiThread(unsigned int nthreads=0, unsigned int skip=0, int natoms=0) : nthreads{nthreads},skip{skip},ntimesteps{0},natoms{natoms}
CalcolaMultiThread(ssize_t nthreads=0, ssize_t skip=0, size_t natoms=0) : nthreads{nthreads},skip{skip},ntimesteps{0},natoms{natoms}
{
if (nthreads==0) nthreads=1;
if (skip==0) skip=1;

}
static constexpr int FLAGS=FLAGS_T;

std::pair<int,int> splitter(int ith, int nthreads, int primo) const {
std::pair<int,int> res;
std::pair<size_t,size_t> splitter(size_t ith, size_t primo) const {
std::pair<size_t,size_t> res;
res.first=ith*npassith;
if (ith==nthreads-1) {
res.second=end;
Expand Down Expand Up @@ -73,7 +73,7 @@ class CalcolaMultiThread
}
}

void calcola(unsigned int primo){
void calcola(size_t primo){
init_split();
if constexpr (!!(FLAGS & CalcolaMultiThread_Flags::CALL_CALC_INIT)) {
static_cast<T*>(this)->calc_init(primo);
Expand All @@ -83,7 +83,7 @@ class CalcolaMultiThread
for (ssize_t i=i0;i<i1;i+=skip){ //loop over trajectory. Can be a loop over a single value if disabled
for (unsigned int ith=0;ith<nthreads;++ith){
threads.push_back(std::thread([&,ith,t,i](){
auto range=splitter(ith,nthreads,primo);
auto range=splitter(ith,primo);
// calculate given start and stop timestep. note that & captures everything, user must take care of multithread safety of calc_single_th function
// select a different signature of the calculation function depending on where the loops (if present) are parallelized
if constexpr (FLAGS & CalcolaMultiThread_Flags::PARALLEL_LOOP_AVERAGE && (FLAGS & CalcolaMultiThread_Flags::PARALLEL_LOOP_TIME)) {
Expand Down Expand Up @@ -144,8 +144,7 @@ class CalcolaMultiThread
ssize_t nthreads,skip,ntimesteps, leff;

private:
size_t npassith,end;
ssize_t natoms;
size_t npassith,end, natoms;
ssize_t t0,t1,i0,i1;
};

Expand Down
3 changes: 2 additions & 1 deletion tests/src/test_sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct ShFixture{
~ShFixture(){}
TrajSetup traj;
unsigned int nbin;
int natoms,ntypes;
size_t natoms;
int ntypes;
SphericalCorrelations<l,double,Traiettoria> sh;
DataRegression<double> data;
double workspace[(l+1)*(l+1)], cheby[(l+1)*2];
Expand Down
10 changes: 8 additions & 2 deletions tests/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TESTS=( "MSD_normal_full" "-i $INPUT -Q"
N_arr=${#TESTS[@]}
N=$(( N_arr - 1 ))
RETURN=0
FLIST=""
for i in $(seq 0 2 $N )
do
ip=$(( i + 1 ))
Expand All @@ -41,12 +42,16 @@ do
if [ -f "$FTEST" ]
then
OUTPUT_F="`cat $FTEST`"

if [ -z "`diff <(echo "$OUTPUT") <(echo "$OUTPUT_F")`" ]
#the sign of nan is not defined by the standard
DIFF="`diff <(echo "$OUTPUT" | sed 's/-nan/nan/g') <(echo "$OUTPUT_F" | sed 's/-nan/nan/g') || true `"
if [ -z "$DIFF" ]
then
echo SUCCESS $NAME
else
echo FAILED $NAME
echo "$DIFF"
FLIST="$FLIST
FAILED $NAME"
RETURN=$(( RETURN + 1 ))
fi
else
Expand All @@ -55,4 +60,5 @@ do
fi

done
echo "$FLIST"
exit $RETURN

0 comments on commit a7ad5ac

Please sign in to comment.