diff --git a/Examples/src/InPolygon/README.md b/Examples/src/InPolygon/README.md index 2bd5e1166..d5daf3581 100644 --- a/Examples/src/InPolygon/README.md +++ b/Examples/src/InPolygon/README.md @@ -7,7 +7,7 @@ of the polygon, in a consistent way. Yet, the code provided here give an idea of We have implemented two types of algorithms: -1. The first one calculates the dot product between the normal of each polygon edge and the vector connecting the given +1. The first one, working only for convex polygons, calculates the dot product between the normal of each polygon edge and the vector connecting the given point and a point of the edge. The given point is inside only if all dot products have the same sign (we have not made any assumption on the orientation of the edge vertices, so we cannot assume an orientation for the normal). diff --git a/Examples/src/MyMat0/Makefile.inc b/Examples/src/MyMat0/Makefile.inc index cb5b92867..2c65edd6b 100644 --- a/Examples/src/MyMat0/Makefile.inc +++ b/Examples/src/MyMat0/Makefile.inc @@ -2,10 +2,10 @@ BLAS=yes# the default # change it to suite your needs if yo do not use modules # module load suitesparse will also load the blas library RELEASE=yes -#BLAS_LIB_DIR=-L${mkOpenblasLib} -#BLAS_INC_DIR=-I${mkOpenblasInc} +BLAS_LIB_DIR?=-L${mkOpenblasLib} +BLAS_LIB_INC?=-L${mkOpenblasInc} #BLAS_LIB_DIR=-L/opt/atlas/lib -#BLAS_INC_DIR=-I/opt/atlas/include +#BLAS_INC_DIR=-I/opt/atlas/includ BLAS_LIB_NAME=openblas # if you use module you have openblas #BLAS_LIB_NAME=cblas # if you use module you have openblas BLAS_LIB_NAME=blas # if you use other versions of blas diff --git a/Examples/src/STL/Reduce/mainReduce.cpp b/Examples/src/STL/Reduce/mainReduce.cpp index 6db4fde03..0bc70a463 100644 --- a/Examples/src/STL/Reduce/mainReduce.cpp +++ b/Examples/src/STL/Reduce/mainReduce.cpp @@ -27,7 +27,8 @@ randomVector(std::size_t n) res.emplace_back(uniform_dist(engine)); timer.stop(); std::cout << " Time taken to create vector:" << timer.wallTime() - << " microsec\n" << std::endl; + << " microsec\n" + << std::endl; return res; } int @@ -38,33 +39,35 @@ main() // Example of simple use of a parallel reduce: add all values Timings::Chrono timer; { - timer.start(); - std::cout << "Sum= " - << std::reduce(std::execution::par, // execution policy - std::begin(bigVector), // start - std::end(bigVector), // end - 0.0, // initial value - std::plus{}); // binary operator (sum, not needed - // since it is the default - std::cout << std::endl; - timer.stop(); - std::cout << "Parallel version. Time taken:" << timer.wallTime() << " microsec" << std::endl; + timer.start(); + std::cout << "Sum= " + << std::reduce(std::execution::par, // execution policy + std::begin(bigVector), // start + std::end(bigVector), // end + 0.0, // initial value + std::plus{}); // binary operator (sum, not needed + // since it is the default + timer.stop(); + std::cout << std::endl; + std::cout << "Parallel version. Time taken:" << timer.wallTime() + << " microsec" << std::endl; } { - timer.start(); - std::cout << "Sum= " - << std::reduce(std::execution::seq, // execution policy - std::begin(bigVector), // start - std::end(bigVector), // end - 0.0, // initial value - std::plus{}); // binary operator (sum, not needed - // since it is the default - std::cout << std::endl; - timer.stop(); - std::cout << "Sequential version.Time taken:" << timer.wallTime() << " microsec\n" << std::endl; + timer.start(); + std::cout << "Sum= " + << std::reduce(std::execution::seq, // execution policy + std::begin(bigVector), // start + std::end(bigVector), // end + 0.0, // initial value + std::plus{}); // binary operator (sum, not needed + // since it is the default + std::cout << std::endl; + timer.stop(); + std::cout << "Sequential version.Time taken:" << timer.wallTime() + << " microsec\n" + << std::endl; } - // A more interesting algorithm, transform_reduce. In this form it applies an // unitary operation to all values in the range and then applies a reduction // using a binary operation. In this example we compute the 1-norm @@ -73,58 +76,66 @@ main() auto absolute = [](double const &x) { return std::abs(x); }; { - timer.start(); - std::cout << "1-Norm= " - << std::transform_reduce(std::execution::par, // execution policy - std::begin(bigVector), // start - std::end(bigVector), // end - 0.0, // initial value - std::plus{}, // binary operator - absolute); // the lambda as unary operator - std::cout << std::endl; - timer.stop(); - std::cout << "Parallel version. Time taken:" << timer.wallTime() << " microsec" << std::endl; + timer.start(); + std::cout << "1-Norm= " + << std::transform_reduce( + std::execution::par, // execution policy + std::begin(bigVector), // start + std::end(bigVector), // end + 0.0, // initial value + std::plus{}, // binary operator + absolute); // the lambda as unary operator + std::cout << std::endl; + timer.stop(); + std::cout << "Parallel version. Time taken:" << timer.wallTime() + << " microsec" << std::endl; } { - timer.start(); - std::cout << "1-Norm= " - << std::transform_reduce(std::execution::seq, // execution policy - std::begin(bigVector), // start - std::end(bigVector), // end - 0.0, // initial value - std::plus{}, // binary operator - absolute); // the lambda as unary operator - std::cout << std::endl; - timer.stop(); - std::cout << "Sequential version.Time taken:" << timer.wallTime() << " microsec\n" << std::endl; - } + timer.start(); + std::cout << "1-Norm= " + << std::transform_reduce( + std::execution::seq, // execution policy + std::begin(bigVector), // start + std::end(bigVector), // end + 0.0, // initial value + std::plus{}, // binary operator + absolute); // the lambda as unary operator + std::cout << std::endl; + timer.stop(); + std::cout << "Sequential version.Time taken:" << timer.wallTime() + << " microsec\n" + << std::endl; + } // Another type of transform_reduce: it does the inner product auto secondVector{randomVector(n)}; { - timer.start(); - std::cout << "Dot product= " - << std::transform_reduce(std::execution::par, // execution policy - std::begin(bigVector), // start first - std::end(bigVector), // end firse - std::begin(secondVector), // begin second - 0.0); // Initial Value - std::cout << std::endl; - timer.stop(); - std::cout << "Parallel version. Time taken:" << timer.wallTime() << " microsec" << std::endl; + timer.start(); + std::cout << "Dot product= " + << std::transform_reduce(std::execution::par, // execution policy + std::begin(bigVector), // start first + std::end(bigVector), // end firse + std::begin(secondVector), // begin second + 0.0); // Initial Value + std::cout << std::endl; + timer.stop(); + std::cout << "Parallel version. Time taken:" << timer.wallTime() + << " microsec" << std::endl; } { - timer.start(); - std::cout << "Dot product= " - << std::transform_reduce(std::execution::seq, // execution policy - std::begin(bigVector), // start first - std::end(bigVector), // end firse - std::begin(secondVector), // begin second - 0.0); // Initial Value - std::cout << std::endl; - timer.stop(); - std::cout << "Sequential version.Time taken:" << timer.wallTime() << " microsec\n" << std::endl; - } // This is the most complex form. + timer.start(); + std::cout << "Dot product= " + << std::transform_reduce(std::execution::seq, // execution policy + std::begin(bigVector), // start first + std::end(bigVector), // end firse + std::begin(secondVector), // begin second + 0.0); // Initial Value + std::cout << std::endl; + timer.stop(); + std::cout << "Sequential version.Time taken:" << timer.wallTime() + << " microsec\n" + << std::endl; + } // This is the most complex form. // It applies a binary operation to all couple of elements of the two ranges // then a reduction applying a second binary operation consecutively on the // result. For instance here we compute the 1-norm of the difference ||A-B||_1 @@ -132,39 +143,41 @@ main() return std::abs(x - y); }; { - timer.start(); - std::cout - << "|a-b|_1= " - << std::transform_reduce( - std::execution::par, // execution policy - std::begin(bigVector), // start first - std::end(bigVector), // end firse - std::begin(secondVector), // begin second - 0.0, // Initial Value - std::plus{}, // binary operation performd for reduction - absDiff // binary operation performed on each couple of elements - ); - timer.stop(); + timer.start(); + std::cout + << "|a-b|_1= " + << std::transform_reduce( + std::execution::par, // execution policy + std::begin(bigVector), // start first + std::end(bigVector), // end firse + std::begin(secondVector), // begin second + 0.0, // Initial Value + std::plus{}, // binary operation performd for reduction + absDiff // binary operation performed on each couple of elements + ); + timer.stop(); - std::cout << std::endl; - std::cout << "Parallel version. Time taken:" << timer.wallTime() << " microsec" << std::endl; + std::cout << std::endl; + std::cout << "Parallel version. Time taken:" << timer.wallTime() + << " microsec" << std::endl; } { - timer.start(); - std::cout - << "|a-b|_1= " - << std::transform_reduce( - std::execution::seq, // execution policy - std::begin(bigVector), // start first - std::end(bigVector), // end firse - std::begin(secondVector), // begin second - 0.0, // Initial Value - std::plus{}, // binary operation performd for reduction - absDiff // binary operation performed on each couple of elements - ); - timer.stop(); + timer.start(); + std::cout + << "|a-b|_1= " + << std::transform_reduce( + std::execution::seq, // execution policy + std::begin(bigVector), // start first + std::end(bigVector), // end firse + std::begin(secondVector), // begin second + 0.0, // Initial Value + std::plus{}, // binary operation performd for reduction + absDiff // binary operation performed on each couple of elements + ); + timer.stop(); - std::cout << std::endl; - std::cout << "Sequential version. Time taken:" << timer.wallTime() << " microsec" << std::endl; + std::cout << std::endl; + std::cout << "Sequential version. Time taken:" << timer.wallTime() + << " microsec" << std::endl; } }