root / synthbench / euroben-ports / base / C-MPI / mod2am / mod2am.c @ 0:839f52ef7657
History | View | Annotate | Download (2.6 kB)
1 |
#include <stdio.h> |
---|---|
2 |
#include <stdlib.h> |
3 |
#include "mpi.h" |
4 |
#include "fundefs.h" |
5 |
#define MAXNOD 1000000 |
6 |
|
7 |
int me, nodes;
|
8 |
int offset[MAXNOD][2], sizes[MAXNOD][2]; |
9 |
|
10 |
int main( int argc, char* argv[] ) |
11 |
{ |
12 |
MPI_Comm comm = MPI_COMM_WORLD; |
13 |
int m, l, n;
|
14 |
int gok, ok, nrep;
|
15 |
int i;
|
16 |
int hsize, vsize;
|
17 |
double **a, **b, **c;
|
18 |
double corr, gtime, nops, speed, time;
|
19 |
FILE *inl; |
20 |
// ------------------------------------------------------------------------
|
21 |
MPI_Init( &argc, &argv ); |
22 |
MPI_Comm_rank( comm, &me ); |
23 |
MPI_Comm_size( comm, &nodes ); |
24 |
if ( me == 0 ) { |
25 |
state( "mod2a" );
|
26 |
prthead( nodes ); |
27 |
} |
28 |
inl = fopen( "mod2am.in", "r" ); |
29 |
while( ( fscanf( inl, "%d%d%d%d\n", &m, &l, &n, &nrep ) != EOF ) ) { |
30 |
sizoff( m, n ); |
31 |
// ------------------------------------------------------------------------
|
32 |
// --- Check whether No. of processes <= than No. of matrix rows/cols.
|
33 |
|
34 |
if ( m < nodes) {
|
35 |
if ( me == 0 ) { |
36 |
printf( "Stop: No. of processes <= than No. of matrix rows.\n" );
|
37 |
printf( "Increase problem size\n" );
|
38 |
} |
39 |
MPI_Finalize(); |
40 |
exit( -1 );
|
41 |
} |
42 |
if ( n < nodes) {
|
43 |
if ( me == 0 ) { |
44 |
printf( "Stop: No. of processes <= than No. of matrix columns.\n" );
|
45 |
printf( "Increase problem size\n" );
|
46 |
} |
47 |
MPI_Finalize(); |
48 |
exit( -1 );
|
49 |
} |
50 |
vsize = sizes[nodes-1][0]; |
51 |
// ------------------------------------------------------------------------
|
52 |
// --- Partition Matrix and allocate.
|
53 |
|
54 |
hsize = sizes[nodes-1][1]; |
55 |
a = makmat( vsize, l ); |
56 |
b = makmat( l, hsize ); |
57 |
c = makmat( m, hsize ); |
58 |
gendat( vsize, l, hsize, a, b ); |
59 |
// ------------------------------------------------------------------------
|
60 |
// --- Do timing on 'nrep' times repeated matrix-matrix multiply..
|
61 |
|
62 |
time = MPI_Wtime(); |
63 |
for( i = 0; i < nrep; i++ ) { |
64 |
clr_arr( m, hsize, c ); |
65 |
gmxm( l, vsize, l, hsize, a, b, c ); |
66 |
} |
67 |
time = MPI_Wtime() - time; |
68 |
ok = check( m, l, sizes[me][1], c );
|
69 |
corr = MPI_Wtime(); |
70 |
for( i = 0; i < nrep; i++ ) { |
71 |
clr_arr( m, hsize, c ); |
72 |
} |
73 |
corr = MPI_Wtime() - corr; |
74 |
time = ( time - corr )/nrep; |
75 |
nops = 2*(double)m*(double)l*(double)n; |
76 |
MPI_Reduce( &ok, &gok, 1, MPI_INT, MPI_LAND, 0, comm ); |
77 |
MPI_Reduce( &time, >ime, 1, MPI_DOUBLE, MPI_MAX, 0, comm ); |
78 |
if( me == 0 ) prtspeed( m, l, n, gtime, gok, nops ); |
79 |
delmat( vsize, a ); |
80 |
delmat( l, b ); |
81 |
delmat( m, c ); |
82 |
} |
83 |
if ( me == 0 ) { |
84 |
printf( "-------------------------------------------------\n" );
|
85 |
} |
86 |
MPI_Finalize(); |
87 |
} |