Indice

SPM 1617 Exercise and assignments

Matrix multiplication

Write e program that generates two N by N matrixes A and B and computes C, the result of the multiplication of A by B. The computation has to be performed by M threads, each working on a partition of C. Check the correctness of the result against result computed sequentially. Plot scalability curve for the program.

Hints

 
  int main(int argc, char * argv[]) {
    int n = atoi(argv[1]);
    int m = atoi(argv[2]); 
    ...
  }
  std::chrono::time_point<std::chrono::system_clock> start, end;
  start = std::chrono::system_clock::now();
  ...
  end = std::chrono::system_clock::now();
  std::chrono::duration<double> elapsed_seconds = end-start;
  srand(123);
  for(....) {
      ... = ((float) (rand() % MAX)) / ((float) RAND_MAX);

Average neighbours

Write a program that generates an N by N matrix A and then executed a number Niter of iterations where at each iteration A[i][j] is substituted by the average of A[i][j] and the four neighbours (north, south, east and west). At the borders, the missing elements in the neighbourhood have to be assumed to be 0. All the new A[i][j] values must be computed summing up values at the current iteration for the neighbours. Computation of the single iteration should be parallelized using threads.