6.4 Accessing Standard Input ( stdin ) and Standard Output ( stdout ) within PVM Tasks

6.4 Accessing Standard Input ( stdin ) and Standard Output ( stdout ) within PVM Tasks

A PVM environment ties a collection of machines together and presents them to the program as one logical machine with multiple processors. Which machine in the PVM should act as the console? When a PVM task inserts data into the cout ostream object, where will the data be displayed? If a PVM task attempts to get data from a keyboard, which keyboard will it read the data from? The stdout for each child process is intercepted and sent to a designated PVM task as a PVM message. Each child process inherits information that determines which task will receive information written to stdout and how that information should be identified. Each child process's stdin is tied to /dev/null . Anything written to /dev/null disappears. If /dev/null is opened for reading, the equivalent of end-of-file is returned. This means child processes should not be designed to rely on input from stdin ( cin ) or on sending output to stdout ( cout ). When designing input and output processing, this behavior of stdin and stdout in a PVM environment must be considered . However, stdin and stdout for the main or parent task behaves as expected. PVM tasks use messages to communicate. Input may be retrieved from messages, pipes, shared memory, environment variables , command-line arguments, or files. Output may be written to messages, pipes, shared memory, and files.

6.4.1 Retrieving Standard Output ( cout ) from a Child Task

Output written to stdout or inserted into cout behaves differently for PVM-spawned children. The parent decides what ultimately happens to the output. When output from a spawned child is inserted into cout or cerr , it is intercepted by the pvmd for that task and is packaged into standard PVM messages and sent to a TaskId specified by the parent. The parent associates a pair ( TaskId , Code ) to the cout and cerr of its children. This is done using the pvm_setopt() routine. This routine is called before the children are spawned. If the TaskId is , the messages will go to the master pvmd , where they will be written to its error log. A spawned child may only set the TaskId to , the value inherited from its parent, or its own TaskId . This means the parent ultimately controls where cout or cerr would write to. A child PVM designate other PVM tasks to receive data inserted into cout or cerr . The typical approach is to let the spawning task manage any important data written to stdout or stdin and let the master pvmd take everything else.



Parallel and Distributed Programming Using C++
Parallel and Distributed Programming Using C++
ISBN: 0131013769
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net