I have alike C++ program with openMP usage
#pragma omp parallel for private(i)
for (j=0;j<NUM_STEPS_J) {
for (i=0;i<NUM_STEPS_I;i++) {
std::cout << "Print some information about step i" << std::endl;
}
std::cout << "Check of item " << j << " finished" << std::endl;
}
What is the best way to provide a correct output in my case?
I know, that using “printf” instead “cout” solves this problem.
But when I changed “cout” to “printf” the time of my program’s execution increased from about 80 seconds to about 120 seconds.
I think, it is a sufficient influence on program’s productivity.
What is the best way to solve this problem without “printf”?
Is it possible to lock “cout” function during output in some way?
I would be surprised to see
printfbeing slower than iostreams… (and more so considering that you are usingstd::endlthat forces flushing of the buffer) but at any rate, you can use astringstreamto construct the output at once and then call eitherprintforstd::cout <<once with the already built line.