Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 71463a96 authored by hhakim's avatar hhakim
Browse files

Fix (issue #205) inability to compile faust_butterfly C++ module when BUILD_MUTLITHREADING is OFF.

Add a header faust_openmp.h.in configured by cmake to define a compilation variable named OMP_ENABLED which is then used in faust_butterfly or faust_prod_opt modules to determine if OpenMP/C++ threads (posix threads) are available and enable a fallback code if they are not.
parent dd6cb0b8
Branches
Tags
No related merge requests found
......@@ -549,7 +549,9 @@ if(BUILD_MULTITHREAD)
endif()
message(STATUS OMP_CXX_FLAGS=${OMP_CXX_FLAGS} OMP_CXX_LFLAGS=${OMP_CXX_LFLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OMP_CXX_FLAGS}")
set(OMP_ENABLED ON) # (CPP preprocessor compilation constant) used in cpp code to detect if OMP is usable
endif(BUILD_MULTITHREAD)
configure_file(${FAUST_SRC_DIR}/utils/faust_openmp.h.in ${FAUST_SRC_DIR}/utils/faust_openmp.h)
#if( (CMAKE_BUILD_TYPE MATCHES "Debug") OR (CMAKE_BUILD_TYPE MATCHES "debug") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") )
if (BUILD_DEBUG OR (CMAKE_BUILD_TYPE MATCHES "Debug") OR (CMAKE_BUILD_TYPE MATCHES "debug") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") )
......
#include "faust_MatDense.h"
#include "faust_TransformHelper.h"
#include <vector>
#include "omp.h" //TODO: ifdef to avoid when BUILD_MULTITHREAD is OFF
#include "faust_openmp.h"
#ifdef OMP_ENABLED
#include "omp.h"
#endif
#include <cmath>
#include <limits>
......@@ -40,7 +43,11 @@ namespace Faust
// Vect<FPP, Cpu> c1(r), c2(r), r1(r), r2(r);
vector<bool> processed_ids(r, false);
auto eps = 1e-6;
#ifdef OMP_ENABLED
int nthreads = 8;
#else
int nthreads = 1;
#endif
auto th_class = new vector<faust_unsigned_int>[nthreads];
for(int i=0;i<r;i++)
{
......@@ -56,7 +63,11 @@ namespace Faust
{
if(s1.eq_cols(s2, i, j, eps) && s1.eq_rows(s2, i, j, eps))
{
#ifdef OMP_ENABLED
th_class[omp_get_thread_num()].push_back(j);
#else
th_class[0].push_back(j);
#endif
processed_ids[j] = true;
}
}
......
#include "faust_openmp.h"
//TODO: allow nflags == 1 and all factors using with same flag
/**
* \brief Multiply all the matrices together (as a product of n factors) with an optimization based on the associativity of the matrix product ; following an order that minimizes the number of scalar operations.
......@@ -346,7 +347,7 @@ template<typename FPP, FDevice DEVICE>
Faust::MatDense<FPP,DEVICE> Faust::multiply_omp(const std::vector<Faust::MatGeneric<FPP,DEVICE>*> data, const Faust::MatDense<FPP,DEVICE> A, const char opThis)
{
Faust::MatDense<FPP, DEVICE> *M = nullptr;
#ifdef _MUL_OMP_ //TODO: this compiler constant should be defined auto. when BUILD_MULTITHREADING is ON
#ifdef OMP_ENABLED
// until this this method is disabled at compilation unless we manually define the constant in CFLAGS (for example).
int nth, start_nth, thid, num_per_th, data_size;
Faust::MatDense<FPP,DEVICE>* mats[8];
......@@ -445,6 +446,8 @@ Faust::MatDense<FPP,DEVICE> Faust::multiply_omp(const std::vector<Faust::MatGene
template<typename FPP, FDevice DEVICE>
Faust::MatDense<FPP,DEVICE> Faust::multiply_par(const std::vector<Faust::MatGeneric<FPP,DEVICE>*>& data, const Faust::MatDense<FPP,DEVICE> A, const char opThis)
{
#ifdef OMP_ENABLED // this function doesn't use OpenMP but C++ threads are implemented using POSIX threads on Linux gcc as OpenMP, so for FAµST we assume it's the same
int nth = std::thread::hardware_concurrency(); // https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency
int barrier_count = nth;
Faust::MatDense<FPP, DEVICE> *M;
......@@ -504,7 +507,9 @@ Faust::MatDense<FPP,DEVICE> Faust::multiply_par(const std::vector<Faust::MatGene
//TODO: return a ptr instead of a copy
//TODO: delete threads
return *M;
#else
throw std::runtime_error("It's not possible to call Faust::multiply_par because the library hasn't been compiled with this function enabled.");
#endif
}
template<typename FPP, FDevice DEVICE>
......
#cmakedefine OMP_ENABLED // #define OMP_ENABLED if BUILD_MULTITHREAD=ON, not defined otherwise (see the main CMakeLists.txt for the variable def)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment