Intel® C++ Compiler 16.0 User and Reference Guide
This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).
Capturing C/C++ program output to stdout and stderr from writes performed inside offloaded code may require calling fflush(). This function is under the control of the coprocessor offload interface (COI) layer, not the compiler or compiler run-time libraries.
Writes performed in offloaded code may be buffered, while writes on the non-offloaded code happen immediately. If the application exits prior to the buffer threshold being reached then the output data may be lost. Therefore, I/O requires an additional explicit fflush() on the coprocessor to capture this output data, as shown in the sample.c example below.
sample.c: #pragma offload_attribute(push,target(mic)) #include <stdio.h> void sub() { printf("hello from MIC\n"); fflush(0); } #pragma offload_attribute(pop) int main(int argc, char* argv[]) { printf("hello from main\n"); #pragma offload target(mic) sub(); }
Compile and execute the above example as follows:
$ icc –o sample sample.c $ ./sample > log.txt $ cat log.txt hello from MIC hello from main
When calling fflush(), you can control directing stdout and stderr to the same or separate output files.
For example, to send the stdout (1) and stderr (2) to log.txt, enter:
$ ./sample > log.txt 2>&1
To redirect stdout to one file and stderr to another, use:
$ ./sample > log.txt 2> log_err.txt