2011年1月3日 星期一

cout and printf in OpenMP

Many implementations of printf acquire a lock to ensure that each printf call is not interrupted by other threads.

In contrast, std::cout's overloaded << operator means that (even with a lock) one thread's printing of i and ' ' and '\n' can be interleaved with another thread's output, because std::cout << i << " " << endl; is translated to three operator<<() function calls by the C++ compiler.

[References]
http://stackoverflow.com/questions/4459888/openmp-c-and-c-cout-printf-does-not-give-the-same-output
http://berenger.eu/blog/2010/12/06/c-openmp-stdcout-print-with-openmp/

沒有留言: