openmp-tutorial
openmp-tutorial copied to clipboard
how to use std::stringstream to fix in 03-parallel-cout.cpp
printf("Hello from thread %d of %d \n", omp_get_thread_num(), omp_get_num_threads());
#include <iostream>
#include <sstream>
#include <omp.h>
int main()
{
#pragma omp parallel
{
//std::cout << "Hello from thread " << omp_get_thread_num() << " of " <<
// omp_get_num_threads() << std::endl;
std::ostringstream s_stream;
s_stream << "Hello from thread " << omp_get_thread_num() << std::endl;
std::cout << s_stream.str();
}
return 0;
}