With intel TBB I'm trying to read a file `serial', apply a function on each line of the file, and save the result to a vector of a type A.
struct A
{
long long time;
double price;
A(long long t, double p) : time(t),price(p){};
}
I have created the following pipeline
vector<A> parallelFile(string fileName) {
ifstream fe(fileName);
string orden_fichero;
vector<A> ord;
parallel_pipeline( /*max_number_of_tokens=*/16,
make_filter<void,string>(
filter::serial,
[&](flow_control& fc)->string
{
getline(fe,orden_fichero);
if(fe.eof())
{
fc.stop(); // stop processing
return NULL;
}
else
{
return orden_fichero;
}
}
) &
make_filter<string,A>(
filter::parallel,
[](string p) ->A{
auto position = p.find('"',28);
auto price = stod(p.substr(position+2));
auto time = dateToMs2(p.substr(0,26).c_str());
return A(time, price);
}
) &
make_filter<A,void>(
filter::serial,
[&ord](A x) {ord.push_back(x);}
)
);
return ord;
}
int main()
{
vector<A> david=parallelFile("input.txt");
return 0;
}
where dateToMs is a function that returns a long long.
Executing this pipline y have the following error:
TBB Warning: Exact exception propagation is requested by application but the
linked library is built without support for it
terminate called after throwing an instance of 'tbb::captured_exception'
what(): basic_string::_M_construct null not valid
Aborted (core dumped)
I have seen that the first filter of the pipline reads all the file and the error comes at the end of the file.
What I'm doing wrong?
edit: each line of the file have the following structure: dd-mm-yyyy hh:mm:ss.msmsms "CompanyName" ff.ff
where:
- dd-mm-yyyy is the date in form day-month-year
- hh:mm:ss.212313 is the date in hours minutes seconds and miliseconds
- "companyName" is a string
- ff.ff is a double