Hi,
I am using a test program for compiling a boost::bind in Intel MIC(Xeom
Phi). Here are the details of the code and platform on which it is
compiled. I am using thread building blocks in my code, but the following
code does not contain any TBB threads. The errors in my test code below and
original code are same.
Compiler : Intel 13.0.1 / intel 14.0.1 SP1 Update 3 (latest from intel
composer XE trial version) I am using our lab's compiler installed on a
cluster. The TBB is installed in my home directory. boost 1.55 is also
installed in my home location.
Compiled for MIC: icpc -mmic -L/home/aniketnp/tbb42_20140122oss/lib/mic
-std=c++11 -I/home/aniketnp/boost_1_55_0
-I/home/aniketnp/tbb42_20140122oss/include test.cpp
Scenario: a functor takes 2 arguments in its operator()() by using a
boost::bind() method. The operator()() method contains a function which
uses comparisons ( < or > ) using if-else logic. The error pops up here.
Here is the following code.
#include <iostream>
#include
using namespace std;
struct Info_t {
int start;
int end;
Info_t(int s=0,int e=0) : start(s), end(e) { }
};
template
void process_info(const T& info1, const T& info2, const time& t) {
//the below gives compiler error
* if ((info1.start < info2.end) && (info2.end > info1.end) &&
(info1.end < info2.start) )*
std::cout << "yess error with mic" << std::endl;
//the below if works fine
if ((info1.start < info2.end) && (info2.end > info1.end))
std::cout << "no error at all" << std::endl;
}
template<typename Time>
struct my_functor {
public:
my_functor() { }
my_functor(Time& time_) : time(time_) { }
typedef void result_type;
template<typename info_t>
void operator()(const info_t& info1, const info_t& info2) {
const auto& i1 = info1;
const auto& i2 = info2;
process_info (i1,i2, time);
}
private:
Time& time;
};
int main() {
Info_t i1(10,2);
Info_t i2(2,10);
int t = 1;
auto func = boost::bind( my_functor<int>(t), _1, _2 );
func(i1,i2);
return 0;
}
test.cpp(16): error: expression must have a constant value
if ((info1.start < info2.end) && (info2.end > info1.end) &&
(info1.end < info2.start) )
^
detected during:
instantiation of "void my_functor<Time>::operator()(const
info_t &, const info_t &) [with Time=int, info_t=Info_t]" at line 313
of "/home/aniketnp/boost_1_55_0/boost/bind/bind.hpp"
instantiation of "void boost::_bi::list2::operator()(boost::_bi::type<void>, F &, A &, int) [with
A1=boost::arg<1>, A2=boost::arg<2>, F=my_functor<int>,
A=boost::_bi::list2]" at line 61 of
"/home/aniketnp/boost_1_55_0/boost/bind/bind_template.hpp"
instantiation of "boost::_bi::bind_t::result_type
boost::_bi::bind_t::operator()(A1 &, A2 &) [with
R=boost::_bi::unspecified, F=my_functor<int>,
L=boost::_bi::list2, boost::arg<2>>, A1=Info_t,
A2=Info_t]" at line 48
test.cpp(16): error: this operator is not allowed in a template
argument expression
if ((info1.start < info2.end) && (info2.end > info1.end) &&
(info1.end < info2.start) )
^
detected during:
instantiation of "void my_functor<Time>::operator()(const
info_t &, const info_t &) [with Time=int, info_t=Info_t]" at line 313
of "/home/aniketnp/boost_1_55_0/boost/bind/bind.hpp"
instantiation of "void boost::_bi::list2::operator()(boost::_bi::type<void>, F &, A &, int) [with
A1=boost::arg<1>, A2=boost::arg<2>, F=my_functor<int>,
A=boost::_bi::list2]" at line 61 of
"/home/aniketnp/boost_1_55_0/boost/bind/bind_template.hpp"
instantiation of "boost::_bi::bind_t::result_type
boost::_bi::bind_t::operator()(A1 &, A2 &) [with
R=boost::_bi::unspecified, F=my_functor<int>,
L=boost::_bi::list2, boost::arg<2>>, A1=Info_t,
A2=Info_t]" at line 48
test.cpp(16): error: expected a ">"
if ((info1.start < info2.end) && (info2.end > info1.end) &&
(info1.end < info2.start) )
^
detected during:
instantiation of "void my_functor<Time>::operator()(const
info_t &, const info_t &) [with Time=int, info_t=Info_t]" at line 313
of "/home/aniketnp/boost_1_55_0/boost/bind/bind.hpp"
instantiation of "void boost::_bi::list2::operator()(boost::_bi::type<void>, F &, A &, int) [with
A1=boost::arg<1>, A2=boost::arg<2>, F=my_functor<int>,
A=boost::_bi::list2]" at line 61 of
"/home/aniketnp/boost_1_55_0/boost/bind/bind_template.hpp"
instantiation of "boost::_bi::bind_t::result_type
boost::_bi::bind_t::operator()(A1 &, A2 &) [with
R=boost::_bi::unspecified, F=my_functor<int>,
L=boost::_bi::list2, boost::arg<2>>, A1=Info_t,
A2=Info_t]" at line 48
As a workaround, I try to do this, but same error
if ((info2.start < info2.end) && (info2.end > info1.end) )
{
if ( info1.end < info2.start)
//do something
}
// error is propagated towards inner if loop
test.cpp(17): error: expression must have a constant value
if ( info1.end < info2.start)
^
detected during:
instantiation of "void my_functor<Time>::operator()(const
info_t &, const info_t &) [with Time=int, info_t=Info_t]" at line 313
of "/home/aniketnp/boost_1_55_0/boost/bind/bind.hpp"
instantiation of "void boost::_bi::list2::operator()(boost::_bi::type<void>, F &, A &, int) [with
A1=boost::arg<1>, A2=boost::arg<2>, F=my_functor<int>,
A=boost::_bi::list2]" at line 61 of
"/home/aniketnp/boost_1_55_0/boost/bind/bind_template.hpp"
instantiation of "boost::_bi::bind_t::result_type
boost::_bi::bind_t::operator()(A1 &, A2 &) [with
R=boost::_bi::unspecified, F=my_functor<int>,
L=boost::_bi::list2, boost::arg<2>>, A1=Info_t,
A2=Info_t]" at line 49
test.cpp(17): error: this operator is not allowed in a template
argument expression
(rest error is the same)
-------------------------------------------------------------------------------------------------
Now, if I compile it without " -mmic " flag, then there is no compiler errors.
I compile with this : icpc
-L/home/aniketnp/tbb42_20140122oss/lib/intel64/gcc4.4 -std=c++11
-I/home/aniketnp/boost_1_55_0
-I/home/aniketnp/tbb42_20140122oss/include test.cpp
I dont get any error. It compiles and runs fine.
Any thoughts ? Please let me know.
--
Thanks and regards,
Aniket Pugaonkar