CIS 367: INTRODUCTION TO PARALLEL COMPUTING
Spring 1998
Programming Assignment 4
Due Date: Start of class, Tuesday, April 21, 1998
The objective of this assignment is to
code different data distributions of vectors and
matrices in preparation for using these routines in the next assignment,
and to increase your understanding of each distribution.
- Read through chapter 5 and 10.1 through 10.4 of the textbook.
- Write an MPI program that takes two integer arguments on the command
line, onedsize and twodsize, to be used
to determine the size of the arrays
to be allocated and used during this execution.
Your program should declare a single dimension
array called vector. Only process 0 should allocate space for this
array, by using the command line argument onedsize and malloc.
A two-dimensional square array
called grid should also be declared for all processes.
Again, only process 0 should create space
the size of twodsize elements.
Also, declare arrays local1d and local2d. In each
process (including process 0), these arrays should be sized to
hold (onedsize)/(number of processes) elements and (twodsize)/(number of processes) by (twodsize)/(number of processes) table of elements,
respectively.
- Write one routine that takes a single dimension array, its size, and
a function of one variable as input arguments, and initializes the
array using the function passed in as a function of the array index.
- Write a routine that takes a two dimension array, its size, and
a function of two variables as input parameters, and initializes the array
using the function passed in as a function of the array indices.
- For process 0 only, call the first routine to initialize
vector such that vector[i] = 2 * i + 3;
call the second routine to initialize grid such that grid[i,j] = w * i + j;
- For all processes, call the initialization routines to
set all elements of their local arrays to 0.
- Write two print routines, onedprint and twodprint, each taking an
array of the appropriate dimension, its size, and a rank. The print routines
should print out the rank of the processor passed in and then a nicely
formatted version of the array of the particular dimension. A vector should
be labeled nicely and printed across the page, then on to the next
line. A two dimensioned array should be printed as a table if possible.
For a vector of length greater than 30, it should print out only the
first ten and last ten elements, labeled as such. For a matrix of more than
20 by 20, it should print only the first 2 and last 2 rows, clearly marked as such.
- Write a routine called distribute1d which takes as arguments:
a single dimension array and all the necessary arguments to perform data
distribution in a general manner including an argument that indicates the kind
of distribution desired - either block, cyclic or
block-cyclic. distribute1d should perform the correct data distribution for the number of processors
and size of the array given as the argument. That is, it should
be possible to perform a block, cyclic, or block-cyclic distribution
of any size 1-dimensional array for any number of processors, by giving the
correct arguments to
distribute1d.
- Write a similar routine called distribute2d that is capable of
data distribution of a 2-d array for
(block,*), (*,block), (cyclic,*), (*,cyclic), (block, block), or (cyclic,cyclic).
Recall that (block,*) is block-row and (*,block) is block-column.
- In your main program, write calls to these routines to accomplish
each of the listed
distributions above, in the order given above for grading purposes.
- Between each call to the distribution routines,
each process should call the appropriate print routine to print out their
rank and their local array values.
Then, the appropriate
initialization
routine should be called by all processors to initialize their local array
variables to 0 in all positions.
- Compile and run the program for
1, 4, and 8 processes, each with command line arguments:
32 32
64 64
128 128
256 256
So, there should be a total of 12 runs. You do not have to do any timings!
Your experimental report should consist of the following sections in this
order. It is strongly recommended that you type your report using a
word processor rather than handing in a hand-written report.
-
Cover Page:
Title, author, course number and semester, date.
-
Project Summary:
In one paragraph, summarize the activities of the lab.
-
General Comments:
This section consists of a discussion of what you learned from
the lab.
Discuss your view of the issues involved in implementing each of the
distributions.
-
Appendix:
- Your code for the complete program.
- Your output from each run of the program, clearly marked.
A script showing your compilation and mpirun command lines and output is preferred.
This document was generated using the LaTeX2HTML translator Version 95.1 (Fri Jan 20 1995) Copyright © 1993, 1994, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
The command line arguments were:
latex2html -split 0 lab4.tex.
The translation was initiated by Lori Pollock on Tue Apr 14 14:06:27 EDT 1998
Lori Pollock
Tue Apr 14 14:06:27 EDT 1998