Broadcast "Hello World" Program: A Parallel "Hello World" Program
This version of "Hello World" is basically the same as the Array "Hello World" program
except that all of the Hello chare objects will be told to say "Hello" at the same time
instead of each of them doing it one-by-one. The figure to the right shows the control
flow of the program. The source code is located below. Here are the differences from
the Array "Hello World" program:
-
broadcast: In the Array "Hello World" program, the last thing the Main::Main()
constructor did was tell the first element of the helloArray to sayHi().
In this version of "Hello World," Main::Main tells the entire array of Hello chare
objects to sayHi(). This is done by calling Hello::sayHi() on the array
itself (instead of just a single element of the array).
-
sayHi(): The Hello::sayHi() entry method no longer has the if statement that
tests if the object is the last object in the chare array. Instead, every element of the
chare arrays invokes done() on the Main chare object (sends a message).
-
done(): The Main::done() entry method is now invoked multiple times. The
Main chare object has a counter, doneCount, that counts the number of times
Main::done() has been called. Once this count reaches the number of elements in
the Hello chare array, the program exits.
-
numElements: Since the Main chare object is the only object that needs access
to the numElements value, it has been made into a member variable of the Main chare class.
Broadcast "Hello World" Code
The source code for this example can be found
here (BroadcastHelloWorld.tar.gz).
The "Hello" Chare Class
The "Main" Chare Class
Makefile
The makefile for this program is the same as it is for the Array "Hello World" program.
Output
The only difference in the output of this program and the Array "Hello World" program is
that all of the Hello chare objects are told to sayHi() by the Main chare object.
This is reflected by the fact that all the output lines below have "told by -1" in them.
|
$ ./charmrun +p3 ./hello 10
Running "Hello World" with 10 elements using 3 processors.
"Hello" from Hello chare # 0 on processor 0 (told by -1).
"Hello" from Hello chare # 3 on processor 0 (told by -1).
"Hello" from Hello chare # 6 on processor 0 (told by -1).
"Hello" from Hello chare # 9 on processor 0 (told by -1).
"Hello" from Hello chare # 1 on processor 1 (told by -1).
"Hello" from Hello chare # 4 on processor 1 (told by -1).
"Hello" from Hello chare # 7 on processor 1 (told by -1).
"Hello" from Hello chare # 2 on processor 2 (told by -1).
"Hello" from Hello chare # 5 on processor 2 (told by -1).
"Hello" from Hello chare # 8 on processor 2 (told by -1).
|
|
Figure: Output of the Broadcast "Hello World" Program
|