I'm writing a program which reads content of file,then split all words as a separatly and count them. In some moment i have to create a vector of unique words, to check the list of words already counted to avoid counting this same words over and over again. This cost a lot of power. So i figure out that I will split this task on dynamicly created theards.Theards numbers will be incresed proportionally to numbers of words stored in vector. How should i do that ? I was redesigned whole program couple of times. I was trying to create thread as function, as separeted class. IMPORTANT The problem is that I have to pass as a parrametr to theard function id which will be a number just created thread to be able correcty divide range of vector to search. Thanks for help.
void Text::coutingWords()
{
int num;
vector<string>buffor;
bool flaga=true;
for( int i=0; i<_tekst.size(); i++) // MAIN LOOP through vector of separated words stored whole content
{
num=0; // counter of words;
string temp =_tekst[i];
int threadNumbers=0;
if(!(threadNumbers=(int)buffor.size()/100)) //evry 100 counted words is creating new thread
threadNumbers=1; //if 0 will be 1;
thread t1[threadNumbers]; //array of threads
for(int h=0; h<threadNumbers; h++)
{
thread(wordsCounting,buffor,h,threadNumbers,temp,flaga); //running threads and passing parrametrs
}
for(int h=0; h<threadNumbers; h++)
{
t1[h].join();
}
if(flaga) //bool variable decide if current words should be counted through whole content
{
for(int j=0; j<_tekst.size(); j++) //couting
{
if(_tekst[i].compare(_tekst[j])==0)
{
++num;
}
}
buffor.push_back(_tekst[i]); //local vector of unique words <- Thread should work on it
_counted[_tekst[i]]=num; // map as a key is unique words and value is just how many time apper in content
}
}
}
This should be thread function;
void Text::wordsCounting(vector<string>& buffor,const int id,const int threadNumber,string tekst,bool& flaga)
{
//Example...counted 253 words so 2 threads created.(every 100 1 thread)
//thread number 2. id=2;
//Step 126,topRange=253;bottomRange = 127;
int Step =buffor.size()/threadNumber;
int topRange=(buffor.size()/threadNumber)*id;
int bottomRange= topRange-Step;
for(int bottomRange; bottomRange<topRange; bottomRange++)
{
for(int m=0; m<tekst.size(); m++)
{
if(tekst.compare(buffor[bottomRange])==0) //checking
flaga=false; //if found change flag this will avoid couting content using this word.
}
}
}
This is my error error: no type named 'type' in 'class std::result_of >&, int, int, std::basic_string, bool&)>(std::vector >, int, int, std::basic_string, bool)>'|
Aucun commentaire:
Enregistrer un commentaire