Make sure the work gets attributed to the correct gpu. Add an fflush to stderr to minimise garbled output when multiple threads write at once.