Download Here

Transcript
AsynChannel ch_right((myId + 1) % numProcs);
cout << "Hello from process " << myId << endl;
gb->wait();
if (myId == 0) {
ch_right.send(&counter, 4);
ch_left.receive(&counter, 4);
cout << "Counter at P0 = " << counter << endl;
} else {
ch_left.receive(&counter, 4);
counter++;
ch_right.send(&counter, 4);
cout << "Counter at P" << myId << " " << counter << endl;
}
gb->wait();
delete gb;
}
Compile this program and run it as follows:
g++ -o barrier barrier.cpp -lcm
cmrun -np 4 barrier
The following output is observed at the terminal:
Hello from
Hello from
Hello from
Counter at
Counter at
Counter at
process 0
process 1
process 2
P1 1
P2 2
P0 = 2
The history diagram for barrier wait operation is depicted in figure 7. It can be noted that the
vector time after passing a barrier is the same in all processes.
9
Topolgy
Topology is a higher level abstraction based on channels. It provides a convenient way to build
communication infrastructure for a group of processes. Channel library provides supports for various types of topology classes which includes constructor, send/receive functions, and collective
communication functions. Topology uses asynchronous channels for communication and since any
31