openmp-tutorial icon indicating copy to clipboard operation
openmp-tutorial copied to clipboard

how to use std::stringstream to fix in 03-parallel-cout.cpp

Open wangce888 opened this issue 6 years ago • 2 comments

wangce888 avatar Jun 26 '19 07:06 wangce888

printf("Hello from thread %d of %d \n", omp_get_thread_num(), omp_get_num_threads());

cloudren2017 avatar Mar 17 '20 07:03 cloudren2017

#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;
}

whitelovers avatar Jun 03 '20 07:06 whitelovers