0% found this document useful (0 votes)
53 views

Parallel Processing

This document describes parallel algorithms for matrix multiplication and analyzes their performance. It first describes a traditional algorithm that divides the matrix into rows and performs parallel multiplication. Cannon's algorithm is also described, which shifts submatrices to align for multiplication. Performance is analyzed by varying matrix size and number of processors. Results show computation time increases with matrix size while communication time increases with more processors. Cannon's algorithm has higher computation time than the traditional approach.

Uploaded by

prv142
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Parallel Processing

This document describes parallel algorithms for matrix multiplication and analyzes their performance. It first describes a traditional algorithm that divides the matrix into rows and performs parallel multiplication. Cannon's algorithm is also described, which shifts submatrices to align for multiplication. Performance is analyzed by varying matrix size and number of processors. Results show computation time increases with matrix size while communication time increases with more processors. Cannon's algorithm has higher computation time than the traditional approach.

Uploaded by

prv142
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Assignment 3

Course EC 566 Parallel Processing


Fall 2013

Matrix Multiplication

Parallel algorithms for multiplying two n x n dense, square matrices.


Traditional approach is used with simple modified parallelization
Cannons algorithm is implemented for matrix multiplication.
Product of A ^ k and Determinant are calculated in both approaches .

Traditional Algorithm

Matrix is divided into 1-D row parallelization is implemented.


The matrix is divided into p rows, each of size (n/p) x n.
This modified approach is chosen rather than the normal block matrix
operations .
the normal traditional algorithm, the n x n matrix is divided into p sub-block
matrices, each of (n/p) x (n/p).
For this approach number of processors used is always a perfect square.
Any other number would not divide the matrix properly into sub-block
matrices.
The 1D row parallelization can help us in the division issue.

Modified approach is implemented as below,

Scatter the agglomerated row to all p processes.


Perform all-to-all broadcast to acquire other process elements for
multiplication. MPI_Allgather operation is used for the all-to-all broadcast.
Perform sequential multiplication at each process to calculate the product.
Gather all the products at the root for the multiplied result.

Cost Analysis

With 1-D row agglomeration, all-to-all broadcast requires (p-1) steps of


communication between neighbors as in a 1-D array or a ring.
Each step involves a message of size m, which is (n 2p), takes (ts + m*tw).
Summing over p - 1 steps
Tcomm = (ts + n2p * tw) (p 1)
Each process computes the multiplied sub-result, which involves (n 2p * n)
multiplications.
Tcomp = n3 p
Total parallel run-time is Tp ~ n3 p + (ts + n2p * tw) (p 1)

Results & Graphs .


According to the problem,

n - the size of the matrix is varied from 64 to 512.


k - power of A is varied from 2 to 6
p - number of processors are varied from 2 to 8.

Table for 2 processors, size of the matrix varying from 64 to 512, Power of matrix
varying from 2 to 6 .

Total time VS Matrix Multiplication power for matrix size varying from 64 to 512
25
20
15

512
256
128

10

64
5
0
2

Communication time VS Matrix Multiplication power for matrix size varying from 64
to 512

0.2
0.18
0.16
0.14
0.12

512

0.1

256

0.08

128
64

0.06
0.04
0.02
0
2

Computation time VS Matrix Multiplication power for matrix size varying from 64 to
512 .
25
20
15

512
256
128

10

64
5
0
2

Table for 4 processors, size of the matrix varying from 64 to 512, Power of matrix
varying from 2 to 6

Total time VS Matrix Multiplication power for matrix size varying from 64 to 512
18
16
14
12
512

10

256

128
64

6
4
2
0
2

Communication time VS Matrix Multiplication power for matrix size varying from 64
to 512
6.000000
5.000000
4.000000
512
256

3.000000

128
64

2.000000
1.000000
0.000000
2

Computation time VS Matrix Multiplication power for matrix size varying from 64 to
512.
12.000000
10.000000
8.000000
512
256

6.000000

128
64

4.000000
2.000000
0.000000
2

Table for 8 processors, size of the matrix varying from 64 to 512, Power of matrix
varying from 2 to 6

Total time VS Matrix Multiplication power for matrix size varying from 64 to 512
18
16
14
12
512

10

256

128
64

6
4
2
0
2

Communication time VS Matrix Multiplication power for matrix size varying from 64
to 512
9.000000
8.000000
7.000000
6.000000
512

5.000000

256

4.000000

128
64

3.000000
2.000000
1.000000
0.000000
2

Computation time VS Matrix Multiplication power for matrix size varying from 64 to
512.
18
16
14
12
512

10

256

128
64

6
4
2
0
2

Total time VS Matrix Multiplication power for matrix size 64 and no of processors
varying from 4 to 8.
0.03
0.03
0.02
Processors2
Processors4

0.02

processors8
0.01
0.01
0
1

Computation time VS Matrix Multiplication power for matrix size 64 and no of


processors varying from 4 to 8.
0.01
0.01
0.01
0.01

Processors2
Processors4

processors8

0
0
0
0
1

Communication time VS Matrix Multiplication power for matrix size 64 and no of


processors varying from 4 to 8.
0.02
0.02
0.02
0.01
0.01

Processors2

0.01

Processors4

0.01

processors8

0.01
0
0
0
1

Analysis

Computation time is reduced when the processors are increased.


Communication time increased when the processors are increased
Communication time is negligible when compared to the computation time.
Total time of the algorithm decreases as the processors increased.
As the size of the matrix increases the communication, computation time
increases drastically.

Merits anda Demerits .

This algorithm can use a max of n processors.


It requires (n2/p) memory .
Each process adds (n2) memory.
Isoefficiency function of this algorithm is (p3/2).

Cannons Algorithm

Cannon's algorithm uses a mesh of s ^2 processes that are connected as a


torus.
Process (i,j) at location (i,j) initially begins with submatrices A {i,j} and B{i,j}.
Asthe algorithm progresses, the submatrices are passed left and upwards.
Initially P{i,j} begins with A{i,j} and B{i,j}.
Elements are moved from their initial positions to align them so that the
correct submatrices are multiplied with one another.
Note that submatrices on the diagonal don't actually require alignment.
Alignment is done by shifting the ith row of A by i positions left and the jth
column of B by j positions up.
Each process, P{i,j} multiplies its current submatrices and adds to a cumulative
sum.
The submatrices are shifted left and upwards.
The above two steps are repeated through the remaining submatrices.

Cost Analysis

The initial shift operation requires a time of 2 (t s + tw * n2/p).


Each p single step shift takes (ts + tw * n2/p) time.
The total communication time is given as,
Tcomm = 2 (ts + tw * n2/p) * p
Each process performs p multiplications of ( n/p * n/p) submatrices.
Tcomp = n3/p
Total parallel run time of this algorithm is,
Tp = 2 p (ts + tw * n2/p) + n3/p

Results & Graphs .


According to the problem,

n - the size of the matrix is varied from 64 to 512.


k - power of A is varied from 2 to 6

Table for 4 processors, size of the matrix varying from 64 to 512, Power of matrix
varying from 2 to 6 .

Total time VS Matrix Multiplication power for matrix size varying from 64 to 512
100
90
80
70
60

512

50

256

40

128
64

30
20
10
0
2

Communication time VS Matrix Multiplication power for matrix size varying from 64
to 512
30
25
20
512
256

15

128
64

10
5
0
2

Computation time VS Matrix Multiplication power for matrix size varying from 64 to
512.
70
60
50
512

40

256
30

128
64

20
10
0
2

Analysis

Computation time is increased when the Matrix size is increased.

Communication time increased when the Matrix size is increased


Communication time is negligible when compared to the computation time.
Total time of the algorithm increases as the Matrix size is increased.
As the size of the matrix increases the communication, computation time
increases drastically.

Merits anda Demerits .

This algorithm can use a max of n processors.


It requires (n2/p) memory .
Each process adds (n2) memory.
Isoefficiency function of this algorithm is (p3/2).

Code for Traditional Algorithm


#include <mpi.h>
#include <stdio.h>
#define n 64 // size of matrix
#define pow 2 // power of matrix A
int main (int argc, char *argv[])
{
int prcss, id;
int prv, nxt;
int rw, clm;
int nrw1, nclm1, brw1, bclm1;
int i, j, k, x, y;
float det1 = 2, det2 = 1;
double cst, cend, cdiff, commt = 0, compt = 0;
rw = n;
clm = n;
MPI_Status stat;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
MPI_Comm_size(MPI_COMM_WORLD, &prcss);
// Ring structure
prv = id - 1;
nxt = id + 1;
if (id == 0)
prv = prcss - 1;
if (id == (prcss - 1))

nxt = 0;
nrw1 = prcss;
nclm1 = 1;
brw1 = n/prcss;
bclm1 = n;
// building matrix A
float a[rw*clm];
if (id == 0)
{
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
{
if (i == j)
a[i + i*clm] = 1;
else
a[j + i*clm] = 0;
}
}
a[0] = 2;
}
// defining data-type
MPI_Datatype blocktype1;
MPI_Datatype blocktype2;
MPI_Type_vector(brw1, bclm1, clm, MPI_INT, &blocktype2);
MPI_Type_create_resized(blocktype2, 0, sizeof(int), &blocktype1);
MPI_Type_commit(&blocktype1);
int disp1[nrw1*nclm1];
int count1[nrw1*nclm1];
for (i = 0; i < nrw1; i++)
{
for (j = 0; j < nclm1; j++)
{
disp1[j + nclm1*i] = j*bclm1 + i*clm*brw1;
count1[j + nclm1*i] = 1;
}
}
// horizontal scatter operation
float b[brw1*bclm1];

cst = MPI_Wtime();
MPI_Scatterv(a, count1, disp1, blocktype1, b, brw1*bclm1, MPI_FLOAT, 0,
MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - cst;
commt = commt + cdiff;
// horizontal all-gather operation
float c[rw*clm];
cst = MPI_Wtime();
MPI_Allgather(&b, brw1*bclm1, MPI_FLOAT, &c, brw1*bclm1, MPI_FLOAT,
MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - cst;
commt = commt + cdiff;
// multiplication
float p[brw1*bclm1];
cst = MPI_Wtime();
for (y = 1; y < pow; y++)
{
for (i = 0; i < brw1; i++)
{
for (j = 0; j < bclm1; j++)
{
p[j + i*bclm1] = 0;
for (k = 0; k < bclm1; k++)
p[j + i*bclm1] = p[j + i*bclm1] + ( b[k + i*bclm1] *
c[j + k*bclm1] );
}
}

for (i = 0; i < brw1; i++)


{
for (j = 0; j < bclm1; j++)
b[j + i*bclm1] = p[j + i*bclm1];
}
}
cend = MPI_Wtime();
cdiff = cend - cst;

compt = compt + cdiff;


// gather Product
float mul[rw*clm];
cst = MPI_Wtime();
MPI_Gather(&p, brw1*bclm1, MPI_FLOAT, &mul, brw1*bclm1, MPI_FLOAT, 0,
MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - cst;
commt = commt + cdiff;
//Result Matrix
if (id == 0)
{
// Matrix A
printf("Initial Matrix A is\n");
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
printf(" %5.0f ", a[j + i*clm]);
printf("\n");
}
printf("\nMultiplied Matrix A^%d is\n", pow);
if (pow > 1)
{
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
printf(" %5.0f ", mul[j + i*clm]);
printf("\n");
}
}
if (pow == 1)
{
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
printf(" %5.0f ", a[j + i*clm]);
printf("\n");
}
}

// printing Determinant
det2 = mul[0];
printf("\nDet of A is %5f\nDet of A^%d is %5f\n", det1, pow, det2);
// printing Time
printf("Total communication time is %f\n", commt);
printf("Total computation time is %f\n", compt);
printf("Total parallel run time is %f\n", commt+compt);
}
MPI_Barrier (MPI_COMM_WORLD);
MPI_Finalize();
}
Output of Traditional Algorithm.
Initial Matrix A is
2
0
0

0
0
0

0
0
0

1
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
1
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
1
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

1
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
1

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
1

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
1

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

Multiplied Matrix A^2 is


4
0
0

0
0
0

0
0
0

1
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
1
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
1

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0

0
0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

Determinant of A is 2.000000
Determinant of A^2 is 4.000000
Total communication time is 0.001938
Total computation time is 0.001689
Total Run time is 0.003627
Code for Cannons Algorithm
#include <mpi.h>
#include <stdio.h>
#define n 64 // size of matrix
#define pow 2 // power of matrix A
int main (int argc, char *argv[])
{
int prcss, id;
int prv, nxt;
int rw, clm;
int nrw1, nclm1, brw1, bclm1;
int i, j, k, x, y;
int sqrt;
float det1, det2;
double csrt, cend, cdiff, commt = 0, compt = 0;
rw = n;
clm = n;
MPI_Status stat;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
MPI_Comm_size(MPI_COMM_WORLD, &prcss);
// ring structure
prv = id - 1;
nxt = id + 1;
if (id == 0)
prv = prcss - 1;
if (id == (prcss - 1))

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

nxt = 0;
if (prcss == 4)
sqrt = 2;
else
sqrt = 4;
nrw1 = sqrt;
nclm1 = sqrt;
brw1 = n/sqrt;
bclm1 = n/sqrt;
// building matrix A & B
float a[rw*clm];
float b[rw*clm];
float temp1[rw*clm];
float temp2[rw*clm];
float temp3[rw*clm];
float mul[rw*clm];
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
{
if (i == j)
a[i + i*clm] = 1;
else
a[j + i*clm] = 0;
temp1[j + i*clm] = a[j + i*clm];
temp3[j + i*clm] = a[j + i*clm];
}
}
a[0] = 2;
temp1[0] = 2;
temp3[0] = 2;
det1 = 2;
// defining data-type
MPI_Datatype blocktype1;
MPI_Datatype blocktype2;
MPI_Type_vector(brw1, bclm1, clm, MPI_LONG, &blocktype2);
MPI_Type_create_resized(blocktype2, 0, sizeof(int), &blocktype1);
MPI_Type_commit(&blocktype1);

int disp1[nrw1*nclm1];
int count1[nrw1*nclm1];
for (i = 0; i < nrw1; i++)
{
for (j = 0; j < nclm1; j++)
{
disp1[j + nclm1*i] = j*bclm1 + i*clm*brw1;
count1[j + nclm1*i] = 1;
}
}
float b1[brw1*bclm1];
float c1[brw1*bclm1];
float p[brw1*bclm1];

for (y = 1; y < pow; y++)


{
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
{
a[j + i*clm] = temp1[i*clm + ((i+j)%clm)];
b[j + i*rw] = temp3[j + ((i+j)%rw)*rw];
}
}
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
{
temp1[j + i*clm] = a[j + i*clm];
temp2[j + i*clm] = b[j + i*clm];
}
}
// scatter operation
csrt = MPI_Wtime();
MPI_Scatterv(&a, count1, disp1, blocktype1, &b1, brw1*bclm1,
MPI_FLOAT, 0, MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - csrt;

commt = commt + cdiff;


csrt = MPI_Wtime();
MPI_Scatterv(&b, count1, disp1, blocktype1, &c1, brw1*bclm1,
MPI_FLOAT, 0, MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - csrt;
commt = commt + cdiff;
csrt = MPI_Wtime();
for (i = 0; i < brw1; i++)
{
for (j = 0; j < bclm1; j++)
{
p[j + i*bclm1] = 0;
p[j + i*bclm1] = p[j + i*bclm1] + ( b1[j + i*bclm1] * c1[j
+ i*bclm1] );
}
}
cend = MPI_Wtime();
cdiff = cend - csrt;
compt = compt + cdiff;

for (x = 1; x < rw; x++)


{
csrt = MPI_Wtime();
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
a[j + i*clm] = temp1[(j+1)%clm + i*clm];
b[j + i*rw] = temp2[j + ((1+i)%rw)*rw];
}
}
cend = MPI_Wtime();
cdiff = cend - csrt;
compt = compt + cdiff;
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
{
temp1[j + i*clm] = a[j + i*clm];
temp2[j + i*clm] = b[j + i*clm];

}
}
// scatter operation
csrt = MPI_Wtime();
MPI_Scatterv(&a, count1, disp1, blocktype1, &b1, brw1*bclm1,
MPI_FLOAT, 0, MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
MPI_Scatterv(&b, count1, disp1, blocktype1, &c1, brw1*bclm1,
MPI_FLOAT, 0, MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - csrt;
commt = commt + cdiff;
csrt = MPI_Wtime();
for (i = 0; i < brw1; i++)
{
for (j = 0; j < bclm1; j++)
p[j + i*bclm1] = p[j + i*bclm1] + ( b1[j + i*bclm1] *
c1[j + i*bclm1] );
}
cend = MPI_Wtime();
cdiff = cend - csrt;
compt = compt + cdiff;
}
// gather operation
csrt = MPI_Wtime();
MPI_Gatherv(&p, brw1*bclm1, MPI_FLOAT, &mul, count1, disp1,
blocktype1, 0, MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
MPI_Scatter(&mul, rw*clm, MPI_FLOAT, &temp1, rw*clm, MPI_FLOAT, 0,
MPI_COMM_WORLD);
MPI_Barrier (MPI_COMM_WORLD);
cend = MPI_Wtime();
cdiff = cend - csrt;
commt = commt + cdiff;
}
if (id == 0)
{

printf("Initial Matrix A is\n");


for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
printf(" %5.0f ", temp3[j + i*clm]);
printf("\n");
}
printf("\nThe multiplied matrix A^%d is\n", pow);
if (pow > 1)
{
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
printf(" %5.0f ", mul[j + i*clm]);
printf("\n");
}
}
if (pow == 1)
{
for (i = 0; i < rw; i++)
{
for (j = 0; j < clm; j++)
printf(" %5.0f ", temp3[j + i*clm]);
printf("\n");
}
}
det2 = mul[0];
// printing Determinant
printf("\nDet of A is %5f\nDet of A^%d is %5f\n", det1, pow, det2);
// printing Time
printf("Total communication time is %f\n", commt);
printf("Total computation time is %f\n", compt);
printf("Total parallel run time is %f\n", commt+compt);
}
MPI_Barrier (MPI_COMM_WORLD);
MPI_Finalize();
Output of Cannons Algorithm

Initial Matrix A is
2
0
0

0
0
0

0
0
0

1
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
1
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

1
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

The Multiplied Matrix A^2 Is


4
0
0

0
0
0

0
0
0

0
0
0

1
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

1
0
0

0
0

0
0
0

0
0
0

0
1
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0
0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

1
0

0
0
0
0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0
0
0
0

0
0

0
0

0
0
0

0
0
0

0
0

0
0

0
0

1
0

0
0

0
0
0
0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

1
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

1
0

0
0

0
0
0

0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

Determinant of A is 2.000000
Determinant of A^2 is 4.000000
Total communication time is 0.082163
Total computation time is 0.013703
Total Runtime is 0.095866

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0
0

0
0

0
0

0
0

0
1
0

0
0

0
1

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
1

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0

0
0
0

0
0

0
0

0
0

0
0
0

0
0

You might also like