Hello i have a little problem with my program (i want to multiply array by scalar).
Basicly i want to create a vector of threads that will do the multiplication staff (element by element)
Code samples
First mainImplementation function
void mainImplementation(){
vector<thread> threads;
vector< vector<int> > result;
vector< vector<int> > tab;
vector<int> temp;
int row = 0;
int col = 0;
int scalar = 5;
loadDataFromFile(tab,temp,row,col);
int availableThreads = thread::hardware_concurrency();
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
for(int t = 1; i <= availableThreads; t++){
threads.push_back(thread(scalarMultiplication,std::ref(tab),
std::ref(result),std::ref(temp),std::ref(i),std::ref(j),std::ref(scalar)));
}
}
}
}
now function that implements scalar multiplication
void scalarMultiplication(vector< vector<int> >& vtab, vector< vector<int> >& vresult, vector<int>& vtemp, int& i, int& j, int& scalar){
//...implementation
}
I haven't implement this part yet but i cant resolve one issue
In the line
threads.push_back(thread(scalarMultiplication,std::ref(tab),
std::ref(result),std::ref(temp),std::ref(i),std::ref(j),std::ref(scalar)));
compiler says that there is an issue there
"Error: no instance of constructor std::thread::thread matches the argument list".
I can't seem to fix this issue. I did read that i should pass variables to the function in thread constructor by reference, so i think this is not an issue here. I pass to the multiplication function 6 variables so it should be ok but it isnt and i have no idea what to do here...google can't help me too cuz i searched for similar problem.
Thanks in advance for help.
It was as I thought, Visual Studio Ultimate 2012 doesn't have variadic templates. The default is 5
so you need to add a #define
to increase the limit (the max is 10
):
#define _VARIADIC_MAX 10