During an integration work of TensorFlow 1.1 with my ongoing C++ project on Ubuntu 16... I want to include a support to MKL and 64 bit integers.
I encountered a compilation problem in Eigen library while instantiate a template struct that has a direct call to MKL:
In file included from /usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/Core:526:0,
from /usr/local/include/eigen3/unsupported/Eigen/CXX11/Tensor:14,
from /home/drormeirovich/projects/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/drormeirovich/projects/tensorflow/tensorflow/core/framework/tensor.h:19,
from /home/drormeirovich/projects/tensorflow/tensorflow/cc/framework/ops.h:21,
from /home/drormeirovich/projects/tensorflow/tensorflow/cc/client/client_session.h:24,
from /home/drormeirovich/projects/my_project.cpp:10:
/usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h: In static member function ‘static void Eigen::internal::general_matrix_matrix_product<Index, double, LhsStorageOrder, ConjugateLhs, double, RhsStorageOrder, ConjugateRhs, 0>::run(Index, Index, Index, const double*, Index, const double*, Index, double*, Index, double, Eigen::internal::level3_blocking<double, double>&, Eigen::internal::GemmParallelInfo<Index>*)’:
/usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h:103:173: error: cannot convert ‘char*’ to ‘CBLAS_LAYOUT’ for argument ‘1’ to ‘void cblas_dgemm(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, long long int, long long int, long long int, double, const double*, long long int, const double*, long long int, double, double*, long long int)’
BLASPREFIX##gemm(&transa, &transb, &m, &n, &k, &numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, &numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
^
/usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h:106:1: note: in expansion of macro ‘GEMM_SPECIALIZATION’
GEMM_SPECIALIZATION(double, d, double, cblas_d)
^
For more details... My whole progress on this integration issue is in this link:
https://docs.google.com/document/d/1VFTdPJy59QTCTHO8NHMNmnO8AOoQhNXgWixas9KmLLM/edit?usp=drivesdk
Do I have to remove the support of MKL from Eigen3?
Any help would be appreciated...
disclaimer: I used to be an EasyBuild developer.
In EasyBuild we can build Eigen3 with MKL support, so this should work.
One of our contributers seems to have figured out that for eigen3 you need to copy the 'signature_of_eigen3_matrix_library' file into the path you use for your includes, see
https://github.com/hpcugent/easybuild-easyblocks/blob/master/easybuild/easyblocks/e/eigen.py
https://github.com/RLovelett/eigen/blob/master/signature_of_eigen3_matrix_library
Related
I'm trying to debug my opengl program. and trying to use the error logging function. glDebugMessageCallback. However the only examples i can find use "typedef void (APIENTRY *DEBUGPROC)" or void APIENTRY glDebugOutput(...). and i know APIENTRY is a windows WINAPI based compiler flag, soo, how do i write a function that will work on linux using g++ compiler?... is it even possible?
if i try to it without that i get..
error: invalid conversion from ‘void* ()(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar, void*)’ {aka ‘void* ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, void*)’} to ‘GLDEBUGPROC’ {aka ‘void ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, const void*)’} [-fpermissive]
According to the OpenGL 4.6 spec, Section 20.2 Debug Message Callback
callback must be a function whose prototype is of the form
void callback( enum source, enum type, uint id,
enum severity, sizei length, const char *message,
const void *userParam );
The definition does not contain any mentioning of APIENTRY. But even if so, most gl.h files will contain a definition similar to
#define APIENTRY GLAPIENTRY
But all of this has nothing to do with your problem. The real problem you have is that your function parameter do not match the debug message callback definition. As the error message states:
void* () (unsigned int, unsigned int, unsigned int, unsigned int, int, const char, void*)
does not match
void ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, const void*)
Basically, you are missing a const for the last parameter.
I'm trying to solve very large sparse matrix system (Ax = b) with eigen using pardiso solver.
When I compile the code with g++, This error comes out:
In file included from ${Eigenroot}/Eigen/PardisoSupport:31,
from code.cpp:8:
${Eigenroot}/Eigen/src/PardisoSupport/PardisoSupport.h: In static member function 'static IndexType Eigen::internal::pardiso_run_selector<IndexType>::run(void*, IndexType, IndexType, IndexType, IndexType, IndexType, void*, IndexType*, IndexType*, IndexType*, IndexType, IndexType*, IndexType, void*, void*) [with IndexType = int]':
${Eigenroot}/Eigen/src/PardisoSupport/PardisoSupport.h:269: instantiated from 'Derived& Eigen::PardisoImpl<Derived>::compute(const typename Eigen::internal::pardiso_traits<Derived>::MatrixType&) [with Derived = Eigen::PardisoLU<Eigen::SparseMatrix<double, 0, int> >]'
${Eigenroot}/Eigen/src/PardisoSupport/PardisoSupport.h:409: instantiated from 'Eigen::PardisoLU<_MatrixType>::PardisoLU(const MatrixType&) [with MatrixType = Eigen::SparseMatrix<double, 0, int>]'
code.cpp:82: instantiated from here
${Eigenroot}/Eigen/src/PardisoSupport/PardisoSupport.h:50: error: cannot convert 'int*' to 'const long long int*' for argument '2' to 'void pardiso(void*, const long long int*, const long long int*, const long long int*, const long long int*, const long long int*, const void*, const long long int*, const long long int*, long long int*, const long long int*, long long int*, const long long int*, void*, void*, long long int*)'
I thought that I don't need to change the sparse matrices' form but it seems like I need to change the sparse matrix form should fit into pardiso.
But when I found other's sample code, they didn't change sparse matrix form.
And it seems work too.
Am I getting it right? I'm not so sure.
Can anyone tell me what is the problem?
(About the A and B they aren't related to this problem. Cause I did get the answer with sparseLU which is built-in solver from eigen. But the speed of it was too slow, I try to use pardisoLU.)
#include <iostream>
#include <fstream>
#include <string>
#include <Eigen/Sparse>
#include <unsupported/Eigen/SparseExtra>
#include <Eigen/PardisoSupport>
using namespace std;
using namespace Eigen;
typedef Eigen::Triplet<double> T;
typedef Eigen::SparseMatrix<double> SpMat;
int main(){
int m = 10000; // number of rows;
int n = 10000; // number of cols;
SpMat A(m,n); // declare sparse matrix A
//
make tripletlist
//
A.setFromTriplets(TripletList.begin(), TripletList.end());
SpMat B(m,1);
//
insert values into B
//
PardisoLU< SparseMatrix<double> > solver( A );
x = solver.solve( B );
}
And compile this with g++ as
g++ -I ${Eigenroot} -DEIGEN_USE_MKL_ALL -DMKL_ILP64 -m64 -I ${mklroot}/linux/mkl/include -o out.out code.cpp -L ${mklroot}/linux/mkl/lib/intel64 -Wl, -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lmkl_blacs_intelmpi_ilp64 -lgomp -lpthread -lm -ldl
probably some problems happen with ILP64 linking. Could you try to link without -DMKL_ILP64 option and with -lmkl_intel_lp64 instead of -lmkl_intel_ilp64?
I'm currently writing a header-only wrapper library which is supposed to provide C++ access to some FORTRAN code. But I'm stuck at the 'undefined reference (...)'
I must say I'm a little bit surprised because I compiled my own functions in C++ using this FORTRAN routine, with no problems at all.
Maybe a few words about the structure. The library follows the singleton pattern, but without the possibility of instantiating the Library by the user. So the only entry point for the user is a static method MultiNestWrapper::Wrapper<T>::run(). MultiNestWrapper is a namespace, Wrapper<T> is a templated class (so that in future you can benchmark how choosing on which type to perform calculations affects results and performance). The FORTRAN routine is declared outside of this namespace, as
extern "C" {
extern void __nested_MOD_nestrun(int *, int *, int *, double *, double *, int *, int *, int *, int *, int *, double *, const char *, int *, int *, int *, int *, void (*Loglike)(double *, int *, int *, double *), void (*dumper)(int *, int *, int *, double **, double **, double *, double *, double *), int *context);
}
and I call it like
__nested_MOD_nestrun(&_mmodal, &_ceff, &_nlive, &_tol, &_efr, &_ndims, &_nPar, &_nClsPar, &_maxModes, &_updInt, &_Ztol, _root, &_seed, _pWrap, &_fb, &_resume, internalLogLike, internalDumper, &_context);
And the types for arguments match.
When I try to compile it, I get the following error:
[dare2be#schroedinger multinest-interfejs]$ make all
g++ -c ExampleLibMnCpp.cpp -o ExampleLibMnCpp.o
gfortran -lstdc++ -llapack -lblas -lnest3 -L/usr/local/lib ExampleLibMnCpp.o -o ExampleLibMnCpp
ExampleLibMnCpp.o: In function `MultiNestWrapper::Wrapper<double>::run(MultiNestWrapper::MNParams<double>*, double (*)(double const*, int), bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, double, void (*)(int*, int*, int*, double**, double**, double*, double*, double*), int, double, bool)':
ExampleLibMnCpp.cpp:(.text._ZN16MultiNestWrapper7WrapperIdE3runEPNS_8MNParamsIdEEPFdPKdiEbSsididPFvPiS9_S9_PPdSB_SA_SA_SA_Eidb[MultiNestWrapper::Wrapper<double>::run(MultiNestWrapper::MNParams<double>*, double (*)(double const*, int), bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, double, void (*)(int*, int*, int*, double**, double**, double*, double*, double*), int, double, bool)]+0x585): undefined reference to `__nested_MOD_nestrun'
collect2: ld returned 1 exit status
make: *** [ExampleLibMnCpp] Error 1
But, note that
[dare2be#schroedinger multinest-interfejs]$ nm /usr/local/lib/libnest3.a | grep __nested_MOD_nestrun
000000000001e0f0 T __nested_MOD_nestrun
I've always dealt with those undefined references myself. But now I can't wrap my head around this. I specify -lnest3 -L/usr/local/lib explicite and /usr/local/lib/libnest3.a contains the routine the linker whines about... Please, help a brother out! :)
EDIT: fixed typos
The order in which you specify libraries in GCC's command-line matters. Read GCC man pages for details - in short you have to specify libraries (-lnest3 etc) after modules that use them. (I always specify libraries in the end of the command-line.)
In your case you have to write
gfortran ExampleLibMnCpp.o -o ExampleLibMnCpp -L/usr/local/lib -lstdc++ -llapack -lblas -lnest3
Maybe you need to specify the source files before the libraries when linking everything together. Like this:
gfortran *.o -lblas -l... ...
Linkers are sometimes picky about the order of their arguments.
I have an issue trying to compile a project under Mac OS X 10.8.5 using Boost libraries, version 1.34.1. I am using Xcode 4.6.3 and accompanying Command Line Tools. This must be an OS X specific issue, since the project compiles under CentOS Linux.
I am asking this here in hopes that someone has used Boost in OS X development and has maybe come across a similar issue.
I attach an excerpt of the compiler messages below. I have tried googling for the error, but can't seem to find satisfying answers. Please let me know if you can think of something from the top of your head or, which is more likely, if you need more info (e.g., source code excerpts) to be able to help me.
Thank you very much,
Best,
Sebastian
g++ -DPARC -DCPPPA_EXPORT= -fPIC -fno-common -D__STDC_LIMIT_MACROS -g -fno-inline -Wpointer-arith -Wwrite-strings -Wno-deprecated -Wreturn-type -W -I/usr/local/include -O2 -I../../src/include -I../../LexBase/src -I/include -I/usr/local/include/boost-1_34_1 -I/Users/sebastiansulger/projects/xle/dev/xfr/src/../../bgdb -Idb_client -I./ -I../include -Ifacts -Irules -Ichoices -Iterms -Imatches -Idriver -Iparser -Itriples -Iprolog -Idebug -Inew_parser -o terms/TermStorage.o -c terms/TermStorage.cpp
In file included from terms/TermStorage.cpp:9:
In file included from terms/TermStorage.h:28:
In file included from ./Types.h:26:
In file included from /usr/local/include/boost-1_34_1/boost/functional/hash.hpp:10:
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:487:20: error:
call to 'hash_value' is ambiguous
return hash_value(val);
^~~~~~~~~~
/usr/include/c++/4.2.1/ext/hashtable.h:595:16: note: in instantiation of member
function 'boost::hash<long long>::operator()' requested here
{ return _M_hash(__key) % __n; }
^
/usr/include/c++/4.2.1/ext/hashtable.h:587:16: note: in instantiation of member
function '__gnu_cxx::hashtable<std::pair<const long long, unsigned int>,
long long, boost::hash<long long>, std::_Select1st<std::pair<const long
long, unsigned int> >, std::equal_to<long long>, std::allocator<unsigned
int> >::_M_bkt_num_key' requested here
{ return _M_bkt_num_key(__key, _M_buckets.size()); }
^
/usr/include/c++/4.2.1/ext/hashtable.h:522:18: note: in instantiation of member
function '__gnu_cxx::hashtable<std::pair<const long long, unsigned int>,
long long, boost::hash<long long>, std::_Select1st<std::pair<const long
long, unsigned int> >, std::equal_to<long long>, std::allocator<unsigned
int> >::_M_bkt_num_key' requested here
size_type __n = _M_bkt_num_key(__key);
^
/usr/include/c++/4.2.1/ext/hash_map:219:22: note: in instantiation of member
function '__gnu_cxx::hashtable<std::pair<const long long, unsigned int>,
long long, boost::hash<long long>, std::_Select1st<std::pair<const long
long, unsigned int> >, std::equal_to<long long>, std::allocator<unsigned
int> >::find' requested here
{ return _M_ht.find(__key); }
^
terms/TermStorage.h:97:46: note: in instantiation of member function
'__gnu_cxx::hash_map<long long, unsigned int, boost::hash<long long>,
std::equal_to<long long>, std::allocator<unsigned int> >::find' requested
here
TsHashMapIter iter = mParent->mHashMap.find(t);
^
terms/TermStorage.cpp:85:47: note: in instantiation of member function
'powerset::xfr::TermHashStorage<long long>::hashInsert' requested here
uint32_t index = (uint32_t) mIntTermStorage.hashInsert(intVal);
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:105:24: note:
candidate function
inline std::size_t hash_value(int v)
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:110:24: note:
candidate function
inline std::size_t hash_value(unsigned int v)
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:115:24: note:
candidate function
inline std::size_t hash_value(long v)
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:120:24: note:
candidate function
inline std::size_t hash_value(unsigned long v)
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:229:24: note:
candidate function
inline std::size_t hash_value(float v)
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:234:24: note:
candidate function
inline std::size_t hash_value(double v)
^
/usr/local/include/boost-1_34_1/boost/functional/hash/hash.hpp:239:24: note:
candidate function
inline std::size_t hash_value(long double v)
^
1 error generated.
make[1]: *** [terms/TermStorage.o] Error 1
make: *** [build] Error 2
Sebastian-Sulgers-MacBook-Pro:dev sebastiansulger$
EDIT: I have noticed that boost/functional/hash/hash.hpp includes the following:
#if defined(BOOST_HAS_LONG_LONG) && defined(_M_X64) && defined(_WIN64)
// On 64-bit windows std::size_t is a typedef for unsigned long long, which
// isn't due to be supported until Boost 1.35. So add support here.
// (Technically, Boost.Hash isn't actually documented as supporting
// std::size_t. But it would be pretty silly not to).
std::size_t hash_value(long long);
std::size_t hash_value(unsigned long long);
#endif
So it seems that the definition of the type is there, but not available for my system. Does that make any sense? Can I circumvent this somehow?
It basically says that there are lots of hash_value functions in hash.hpp, but none of them works for the type in your hash table (apparently long long).
Either your tools are too old for that type, or you don't compile with the proper -std=... parameter for the compiler.
I'm currently writing a header-only wrapper library which is supposed to provide C++ access to some FORTRAN code. But I'm stuck at the 'undefined reference (...)'
I must say I'm a little bit surprised because I compiled my own functions in C++ using this FORTRAN routine, with no problems at all.
Maybe a few words about the structure. The library follows the singleton pattern, but without the possibility of instantiating the Library by the user. So the only entry point for the user is a static method MultiNestWrapper::Wrapper<T>::run(). MultiNestWrapper is a namespace, Wrapper<T> is a templated class (so that in future you can benchmark how choosing on which type to perform calculations affects results and performance). The FORTRAN routine is declared outside of this namespace, as
extern "C" {
extern void __nested_MOD_nestrun(int *, int *, int *, double *, double *, int *, int *, int *, int *, int *, double *, const char *, int *, int *, int *, int *, void (*Loglike)(double *, int *, int *, double *), void (*dumper)(int *, int *, int *, double **, double **, double *, double *, double *), int *context);
}
and I call it like
__nested_MOD_nestrun(&_mmodal, &_ceff, &_nlive, &_tol, &_efr, &_ndims, &_nPar, &_nClsPar, &_maxModes, &_updInt, &_Ztol, _root, &_seed, _pWrap, &_fb, &_resume, internalLogLike, internalDumper, &_context);
And the types for arguments match.
When I try to compile it, I get the following error:
[dare2be#schroedinger multinest-interfejs]$ make all
g++ -c ExampleLibMnCpp.cpp -o ExampleLibMnCpp.o
gfortran -lstdc++ -llapack -lblas -lnest3 -L/usr/local/lib ExampleLibMnCpp.o -o ExampleLibMnCpp
ExampleLibMnCpp.o: In function `MultiNestWrapper::Wrapper<double>::run(MultiNestWrapper::MNParams<double>*, double (*)(double const*, int), bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, double, void (*)(int*, int*, int*, double**, double**, double*, double*, double*), int, double, bool)':
ExampleLibMnCpp.cpp:(.text._ZN16MultiNestWrapper7WrapperIdE3runEPNS_8MNParamsIdEEPFdPKdiEbSsididPFvPiS9_S9_PPdSB_SA_SA_SA_Eidb[MultiNestWrapper::Wrapper<double>::run(MultiNestWrapper::MNParams<double>*, double (*)(double const*, int), bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, double, void (*)(int*, int*, int*, double**, double**, double*, double*, double*), int, double, bool)]+0x585): undefined reference to `__nested_MOD_nestrun'
collect2: ld returned 1 exit status
make: *** [ExampleLibMnCpp] Error 1
But, note that
[dare2be#schroedinger multinest-interfejs]$ nm /usr/local/lib/libnest3.a | grep __nested_MOD_nestrun
000000000001e0f0 T __nested_MOD_nestrun
I've always dealt with those undefined references myself. But now I can't wrap my head around this. I specify -lnest3 -L/usr/local/lib explicite and /usr/local/lib/libnest3.a contains the routine the linker whines about... Please, help a brother out! :)
EDIT: fixed typos
The order in which you specify libraries in GCC's command-line matters. Read GCC man pages for details - in short you have to specify libraries (-lnest3 etc) after modules that use them. (I always specify libraries in the end of the command-line.)
In your case you have to write
gfortran ExampleLibMnCpp.o -o ExampleLibMnCpp -L/usr/local/lib -lstdc++ -llapack -lblas -lnest3
Maybe you need to specify the source files before the libraries when linking everything together. Like this:
gfortran *.o -lblas -l... ...
Linkers are sometimes picky about the order of their arguments.