Laboratory Exercises For Computer Science 295

Lab 8: Message Passing in SR

Lab 8: Message Passing in SR

Goals: This lab provides experience with some simple applications of message passing in SR.

Steps for this Lab:

  1. Review sections 6.1-6.2 in Hartley's text concerning SR's capabilities for using message passing to coordinate tasks involving parallel processing.

  2. Copy Program 6.1 of Hartley's text to your account. (This program is available as ~walker/parallel/sr/book/messages.sr .)

    Compile and run the program to check that it works as expected.

    Complete Program 6.1 by providing appropriate comments, including notes about relevant variables, procedures, operations, and messages.

  3. Program simple-send.sr demonstrates how one process, running on one processor, can pass a message to a second process, running on another processor. (This program is available as ~walker/parallel/sr/examples/simple-send.sr .)

    1. Copy this program to your account and run it.
    2. Be sure you understand how this program produces its output.
    3. Add appropriate comments to the program to explain how each part of the code contributes to the running of the program.

  4. Program two-way-send.sr uses a single operation for two-way communication between processes running on different processors.

    Copy this program (from directory ~walker/parallel/sr/examples), run it, study the output, and comment relevant lines to explain how the program works.

    Experiment changing the call statement to send and rerun the program. Explain any similarities or differences in the output.

    Similarly, change the send statement to call and review the output.

    What happens if you remove the operations send and call (but leave the msg lines in both processes)?

  5. Program two-way-alt.sr (also in directory ~walker/parallel/sr/examples) demonstrates two-way communication through two operations. In this program, the main program can tell process_b where to find operation a_msg in process_a, because process_a is created before process_b. However, process_a cannot know about b_msg, which is created in a resource later.

    Thus, in this program, the first message from process_b to process_a includes the specifics of where process_b might be referenced. This allows process_a to find b_msg when later communication is desired.

    As with the previous steps, copy this program, run it, and comment relevant lines.

  6. Program find-max.sr (from directory ~walker/parallel/sr/examples) finds the maximum in a data array of size n, using n processes distributed over 6 processors.

    Copy this program to your account, run it, and describe in a few sentences what it does and how it works.

    1. What output is generated?
    2. What are the differences among the resources in_out_2_node, in_out_1_node, and out_node? Why are these different types of processes needed?
    3. What is the purpose of the channel resource?
    4. How are the processes distributed over various processors? How many processes run on each processor?
    5. How might the program be simplified if you knew the number of processes always would be odd?
    6. Draw a diagram showing each processor and identifying the communication channels between processors. That is, draw an arrow from one processor to another if the first processor sends a message to the second.
    7. Describe in a few sentences the channel configuration shown in your diagram.
    8. What changes are needed in the diagram if the number of processes is odd instead of even?

  7. Program find-max.sr may be modified to compute the sum of the elements in the array rather than the maximum. In this approach, each processor adds the value at its array location to the values received from other processors. This sum is then sent out along the processor's output channel.

    1. Modify the program as suggested to compute the sum of the values in an array.
    2. Compile and run your program on a variety of data, including at least one case where the size of the array is even and at least one case where the size is odd.
    3. Describe in a few sentences why this program works.

Work to be turned in:


This document is available on the World Wide Web as

http://www.math.grin.edu/~walker/courses/295/lab8.html

created March 31, 1997
last revised April 7, 1997