3.17 Terminal I/O

CHARM++ provides both C and C++ style methods of doing terminal I/O.

In place of C-style printf and scanf, CHARM++ provides CkPrintf and CkScanf. These functions have interfaces that are identical to their C counterparts, but there are some differences in their behavior that should be mentioned.

A recent change to CHARM++ is to also support all forms of printf, cout, etc. in addition to the special forms shown below. The special forms below are still useful, however, since they obey well-defined (but still lax) ordering requirements.

int CkPrintf(format [, arg]*)
This call is used for atomic terminal output. Its usage is similar to printf in C. However, CkPrintf has some special properties that make it more suited for parallel programming on networks of workstations. CkPrintf routes all terminal output to the charmrun, which is running on the host computer. So, if a chare on processor 3 makes a call to CkPrintf, that call puts the output in a TCP message and sends it to host computer where it will be displayed. This message passing is an asynchronous send, meaning that the call to CkPrintf returns immediately after the message has been sent, and most likely before the message has actually been received, processed, and displayed. 18

void CkError(format [, arg]*))
Like CkPrintf, but used to print error messages on stderr.

int CkScanf(format [, arg]*)
This call is used for atomic terminal input. Its usage is similar to scanf in C. A call to CkScanf, unlike CkPrintf, blocks all execution on the processor it is called from, and returns only after all input has been retrieved.

For C++ style stream-based I/O, CHARM++ offers ckout and ckerr in the place of cout, and cerr. The C++ streams and their CHARM++ equivalents are related in the same manner as printf and scanf are to CkPrintf and CkScanf. The CHARM++ streams are all used through the same interface as the C++ streams, and all behave in a slightly different way, just like C-style I/O.

October 08, 2008
Charm Homepage