Printing inside a Parallel for region, printf vs std::cout()

Hello all, I have been trying to print inside a parallel for region and I noticed that using printf works as intended but when I use std::cout I get a compile-time error as follows - Accessing non-const global variable is not allowed within SYCL device code.

I was wondering what are basic differences between printf and std::cout that could result in such behavior.
PS - I am sorry if this question does not exactly fit in this forum. I tried searching the web and on stack overflow but none of them highlighted the basic differences and which one to be used in a kernel.


I will point you to the Logging section of our SYCL guide which describes the stream class that can be used to print output inside kernel code. It also explains how std::out can’t be used inside code not running on the host device.

Thanks a lot for your reply @rod , I will go through it.