A final parallel implementation showing your best effort toward efficient, effective parallelization. This version should be able to run correctly on 1, 4 and 8 processors. You should show test runs, using a script file, for 1, 4, and 8 processors. The final draft of the documentation should also be included with this deliverable.
The details of the code:
For time, efficiency means using parallelism and performing communication efficiently. So, you should think about how best to distribute the data to minimize the amount of communication needed between processes during computation as well as minimizing the amount of duplicate data distribution work. In addition, when communication is needed, you should try to do it in an efficient manner, that is, avoid wait's if possible due to sequentialized communication schemes, and package up as much as possible in a message before sending. You are welcome to use any MPI command you find to achieve these goals, but it is perfectly fine to use only those we have discussed in class so far.
Your project will be evaluated according to the following criteria:
(3 pts) Generalize your code to take in matrices that are not necessarily evenly divisible by the number of processes, and demonstrate that it correctly handles these cases. (2 more pts = 5 pts) Give a solution that minimizes load imbalance, and explain how you deal with minimizing load imbalance in this situation.
For a single dimension array:
I first declare the array as a pointer, because I don't want to have to give it a fixed size like int vector[100]; So, instead, I declare it as:
int *vector;
This create space for a single pointer called vector, in each process's address space. Now, if I want to allocate space, say for size number of int's, I write:
vector = (int *) calloc(size, sizeof(int));or
vector = (int *) malloc(size * sizeof(int));
You can do a man on malloc or calloc and find out more.
Now, to access vector, I can either use pointer notation and pointer arithmetic, or I can use array notation.
So, I can do:
for(i=0; i<size;i++) printf("vector[%d]:%d\n", i, vector[i]);
to print out the values in the array. They should be all zero at this point, as malloc initializes the locations allocated to 0.
For two-dimensional arrays, it is much trickier: Here are some portions of my code:
In C, two-dimensional arrays are really an array of arrays, such that a[i][j] accesses the jth element of the ith array in the array of arrays. So, to declare a two-dimensional array that does not have space allocated yet, I need to declare a pointer to a pointer as:
int **grid;
Then, to allocate space for the whole grid of size, I can do it in two steps:
I first allocate the array of pointers which will point to the arrays. This can be done by:
grid = (int **) malloc(size * sizeof(int *));
This create space for size number of addresses; an address can be stored in the space of a pointer to an int.
Now, I have space as if I had size number of vector declarations. So, now I need to allocate the space for the vectors (single dimension arrays themselves). So, I do the same as I did for allocating a single vector, except I need size number of them, so I put it in a loop:
for (i=0;i<size;i++) grid[i] = (int *) malloc(size * sizeof(int));
Note that I can now access grid by the grid[i][j] notation, because it is fully allocated now.
This document was generated using the LaTeX2HTML translator Version 98.1p1 release (March 2nd, 1998)
Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
The command line arguments were:
latex2html -split 0 group1c.tex.
The translation was initiated by Lori Pollock on 2000-04-06