root / synthbench / euroben-ports / base / C-MPI / mod2as / mod2as.c @ 0:839f52ef7657
History | View | Annotate | Download (2.3 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 ncols, nrows, nelmts;
|
14 |
int lrows, lelmts;
|
15 |
int i, j, k;
|
16 |
int *indx, *rowp;
|
17 |
int ok, gok;
|
18 |
double *matvals, *invec, *outvec;
|
19 |
double fill, mflops, gmflops, time, gtime;
|
20 |
FILE *inl; |
21 |
// ------------------------------------------------------------------------
|
22 |
MPI_Init( &argc, &argv ); |
23 |
MPI_Comm_rank( comm, &me ); |
24 |
MPI_Comm_size( comm, &nodes ); |
25 |
if ( me == 0 ) { |
26 |
state( "mod2as" );
|
27 |
prthead( nodes ); |
28 |
} |
29 |
inl = fopen( "mod2as.in", "r" ); |
30 |
while( ( fscanf( inl, "%d%d%d\n", &ncols, &nrows, &nelmts ) != EOF ) ) { |
31 |
if ( nrows < nodes ) {
|
32 |
if ( me == 0 ) { |
33 |
printf( "No. of rows < No. of processes: Increase problem size.\n");
|
34 |
} |
35 |
MPI_Finalize(); |
36 |
exit; |
37 |
} |
38 |
// ------------------------------------------------------------------------
|
39 |
// --- Partition problem row-wise and allocate.
|
40 |
|
41 |
lrows = part( nrows, me, nodes ); |
42 |
lelmts = part( nelmts, me, nodes ); |
43 |
indx = calloc( lelmts, sizeof( int ) ); |
44 |
rowp = calloc( lrows, sizeof ( int ) ); |
45 |
matvals = calloc( lelmts, sizeof ( double ) ); |
46 |
invec = calloc( ncols, sizeof ( double ) ); |
47 |
outvec = calloc( lrows, sizeof ( double ) ); |
48 |
getmatvec( ncols, lrows, lelmts, indx, rowp, matvals, invec ); |
49 |
time = MPI_Wtime(); |
50 |
spmxv( lrows, lelmts, indx, rowp, matvals, invec, outvec ); |
51 |
time = MPI_Wtime() - time; |
52 |
ok = check( ncols, lrows, lelmts, indx, rowp, outvec ); |
53 |
mflops = 2.0*1.0e-6*(double)nelmts/time; |
54 |
MPI_Reduce( &ok, &gok, 1, MPI_INT, MPI_LAND, 0, comm ); |
55 |
MPI_Reduce( &mflops, &gmflops, 1, MPI_DOUBLE, MPI_MIN, 0, comm ); |
56 |
MPI_Reduce( &time, >ime, 1, MPI_DOUBLE, MPI_MAX, 0, comm ); |
57 |
fill = 1.0e2*(double)nelmts/((double)(ncols*nrows)); |
58 |
if ( me == 0 ) prtspeed( ncols, nrows, fill, gtime, gmflops, gok ); |
59 |
free( indx ); free( rowp ); free( matvals ); free( invec ); |
60 |
free( outvec ); |
61 |
} |
62 |
if ( me == 0 ) { |
63 |
printf( "-------------------------------------------------------\n" );
|
64 |
} |
65 |
MPI_Finalize(); |
66 |
} |