Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Problem with std::ref and std::vector

$
0
0

Hi guys.

I am using icpc version 16.0.0 (gcc version 5.0.0 compatibility), there seems to be an issue using std::ref and std::vector, i am trying to initalize a bunch of threads with reference for std::vector with the code:

void doTheMath(const int startIndex, const int endIndex, std::vector<int>& matrix, const int givenSeed)
{
	int seed = 0;

	for (int i = startIndex; i < endIndex; ++i) {

		seed = givenSeed + i;
		seed = VAL_A * seed + VAL_B;
		matrix[i] = seed % 100;

	}
}

void Cpp11::randmat(int nrows, int ncols, int s) {

	int totalMatrixSize = nrows * ncols;
	int numThreads = 4;
	int operationsByThread = totalMatrixSize / numThreads;

	std::vector<int> matrix(totalMatrixSize);
	std::vector<std::thread> threadsList;

	for (int i = 0; i < numThreads; ++i) {
		threadsList.emplace_back(std::thread(doTheMath, operationsByThread * i, operationsByThread * (i + 1), std::ref(matrix), s));

	}

	for ( auto &t : threadsList ) {

		t.join();

	}
}

To compile i'm using:

icpc cpp11.cpp randmat.cpp -std=c++11 -pthread

And i'm getting this error:

/usr/include/c++/5/functional(78): error: class "std::vector<int, std::allocator<int>>" has no member "result_type"
      { typedef typename _Functor::result_type result_type; };
                                   ^
          detected during:
            instantiation of class "std::_Maybe_get_result_type<_Functor, void> [with _Functor=std::vector<int, std::allocator<int>>]" at line 86
            instantiation of class "std::_Weak_result_type_impl<_Functor> [with _Functor=std::vector<int, std::allocator<int>>]" at line 184
            instantiation of class "std::_Weak_result_type<_Functor> [with _Functor=std::vector<int, std::allocator<int>>]" at line 264
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 283
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 399
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 36 of "randmat.cpp"

/usr/include/c++/5/functional(266): error: class "std::vector<int, std::allocator<int>>" has no member "argument_type"
        typedef typename _Tp::argument_type argument_type;
                              ^
          detected during:
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 283
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 399
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 36 of "randmat.cpp"

/usr/include/c++/5/functional(267): error: class "std::vector<int, std::allocator<int>>" has no member "first_argument_type"
        typedef typename _Tp::first_argument_type first_argument_type;
                              ^
          detected during:
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 283
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 399
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 36 of "randmat.cpp"

/usr/include/c++/5/functional(268): error: class "std::vector<int, std::allocator<int>>" has no member "second_argument_type"
        typedef typename _Tp::second_argument_type second_argument_type;
                              ^
          detected during:
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 283
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 399
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=std::vector<int, std::allocator<int>>]" at line 36 of "randmat.cpp"

I atached the source and the preprocessor file.

Strangely in g++ there is no problem. Someone can help me? Thanks in advance!

AdjuntoTamaño
Descargarcpp11.zip254.37 KB
Descargarcode.zip1.06 KB

Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>