Matrix Multiplication
This implementation uses the simplest parallel algorithm that computes the product of two matrices. The two matrices are given in 2D decompositions (sqr), then redistributed to block column (col) and block row (row) decompositions. Finally, each process computes the result for its corresponding 2D domain.
Types
type range Range2D;
type partition <Range2D> PartRange2D [PartNP];
type swap <Range2D> SwapRange2D [PartNP];
type data Int, Config, File;
type data Vector2Dreal [PartRange2D];
Declarations
function add (A, B, ra -> C)
Vector2Dreal A[ra], B[ra], C[ra],
Range2D ra;
function sub (A, B, ra -> C)
Vector2Dreal A[ra], B[ra], C[ra],
Range2D ra;
function prod (A, B, sqr, row, col -> C)
Vector2Dreal A[row], B[col], C[sqr],
Range2D row, col, sqr;
function matrix_read (cfg, ra -> A, I, R)
Vector2Dreal A[ra], I[ra], R[ra],
Range2D ra,
Config cfg;
function init (cfg -> row, col, sqr, f)
PartRange2D row[ALLn], col[ALLn], sqr[ALLn],
Config cfg, File f;
function check_equal (A, B, ra)
Vector2Dreal A[ra], B[ra],
Range2D ra;
function econd (cfg, idx -> cond)
Int idx, cond, Config cfg;
Parallel Computations
function foo_loop (cfg, A, B, row, col, sqr -> D)
Vector2Dreal A[sqr], B[sqr], D[sqr],
PartRange2D row[ALLn], col[ALLn], sqr[ALLn],
Config cfg[ALL1]
{
// DECOMPOSITION RULES
sqr < row;
sqr < col;
sw_sr : sqr -> row;
sw_sc : sqr -> col;
computeSwap (sqr, row -> sw_sr[PPEn]);
computeSwap (sqr, col -> sw_sc[PPEn]);
// A -> C, A*A -> D
loop (idx, cond ; A[sqr], B[sqr] -> C[sqr], D[sqr]) [clock:MAIN]
{
prod (A[row], A[col], sqr -> D[sqr]);
add (A[sqr], D[sqr] -> Y[sqr]);
sub (Y[sqr], D[sqr] -> C[sqr]);
econd (cfg, idx -> cond);
}
}
function testfoo (cfg) [gen]
Config cfg[ALL1]
{
init (cfg -> row, col, sqr, fout);
matrix_read (cfg, sqr -> A[sqr], I[sqr], R[sqr]);
foo_loop (cfg, A[sqr], I[sqr], row, col -> C[sqr]);
check_equal (C[sqr], R[sqr]);
print (fout, A[sqr]);
print (fout, C[sqr]);
}
CGD Library
The following code is generated for the main loop:
for (idxe=0, conde=1; conde; idxe++)
{
CLK_MAIN_BEGIN(idxe);
swapBegin (sw_sre, A_row, A_row, 0, pe);
swapBegin (sw_sce, A_row, A_col, 1, pe);
econd (cfg, idxe, conde);
swapEnd (sw_sre, A_row, A_row, 0, pe);
swapEnd (sw_sce, A_row, A_col, 1, pe);
prod (A_row, A_col, sqr[pe], row[pe], col[pe], I_sqr);
add (A_row, I_sqr, sqr[pe], Ye_sqr);
sub (Ye_sqr, I_sqr, sqr[pe], A_row);
CLK_MAIN_END(idxe);
}
Files
| Programmer | Compiler generated | ||||
| CGD source | Type Declarations | Sequential Computations | Computation Declarations | Parallel Functions | |
| Matrix Multiply | mbh.pd | mbh.h | mbh.cc | mbh_decl.h | mbh_auto.cc |
