printf problem

Having problem with prinf statement. NVidia drivers upto date.

I’m basically executing:

myGPU(pthashToFind, ptfound, ptsofar, ptmyint, ptstep, pttrigger); //runs on GPU for approx 1second

printf("Round 1);

myGPU(pthashToFind, ptfound, ptsofar, ptmyint, ptstep, pttrigger); //runs on GPU for approx 1second

printf("Round 2);

The problem is that it does not print anything (i.e. “Round 1”) to the screen until the end of the program. Then it prints everything.

Can you help me please.

Thanks.

The output to stdout is buffered, so it will not write anything to screen until the buffer is full or you add a new line. You can write to stderr, which is unbuffered or try setting the stdout buffer to NULL.

setbuf(stdout, NULL);

Tried that; still same problem.

Thanks.

Is the printf() running on the GPU? If yes then I think (if I remember correctly) that it will only output once the GPU process has finished.
If not, remember that kernel calls are assynchronous to the host (ie: they launch and continue the host code, while the GPU is running), then you would need some kind of synchronization, like for intance cudaDeviceSynchronize(), prior to the printf.