Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91130655
cg_blas.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 8, 05:34
Size
1 KB
Mime Type
text/x-c
Expires
Sun, Nov 10, 05:34 (2 d)
Engine
blob
Format
Raw Data
Handle
22132897
Attached To
R9010 PHPC_final project_SLWang
cg_blas.c
View Options
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#include <mpi.h>
#include "mmio_wrapper.h"
#include "util.h"
#include "parameters.h"
#include "cg.h"
#include "second.h"
/*
Implementation of a simple CG solver using matrix in the mtx format (Matrix market)
Any matrix in that format can be used to test the code
*/
int
main
(
int
argc
,
char
**
argv
)
{
double
*
x
;
double
*
b
;
double
*
A
;
double
t1
,
t2
;
// Arrays and parameters to read and store the sparse matrix
double
*
val
=
NULL
;
int
*
Irn
=
NULL
;
int
*
Jcn
=
NULL
;
int
N
;
int
nz
;
const
char
*
element_type
=
"d"
;
int
symmetrize
=
0
;
int
m
,
n
;
struct
size_m
sA
;
double
h
;
int
rank
,
size
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"Usage: %s [martix-market-filename]
\n
"
,
argv
[
0
]);
exit
(
1
);
}
else
{
A
=
read_mat
(
argv
[
1
]);
sA
=
get_size
(
argv
[
1
]);
}
if
(
loadMMSparseMatrix
(
argv
[
1
],
*
element_type
,
true
,
&
N
,
&
N
,
&
nz
,
&
val
,
&
Irn
,
&
Jcn
,
symmetrize
)){
fprintf
(
stderr
,
"!!!! loadMMSparseMatrix FAILED
\n
"
);
return
EXIT_FAILURE
;
}
else
{
if
(
rank
==
0
)
{
printf
(
"Matrix loaded from file %s
\n
"
,
argv
[
1
]);
printf
(
"N = %d
\n
"
,
N
);
printf
(
"nz = %d
\n
"
,
nz
);
printf
(
"val[0] = %f
\n
"
,
val
[
0
]);
}
}
m
=
sA
.
m
;
n
=
sA
.
n
;
h
=
1.
/
(
double
)
n
;
b
=
init_source_term
(
n
,
h
);
x
=
(
double
*
)
malloc
(
n
*
sizeof
(
double
));
if
(
rank
==
0
)
{
printf
(
"Call cgsolver() on matrix size (%d x %d)
\n
"
,
m
,
n
);
t1
=
second
();
}
cgsolver
(
A
,
b
,
x
,
m
,
n
,
rank
,
size
);
if
(
rank
==
0
)
{
t2
=
second
();
printf
(
"Time for CG (dense solver) = %f [s]
\n
"
,(
t2
-
t1
));
}
/**
printf("Call cgsolver_sparse() on matrix size (%d x %d)\n",m,n);
t1 = second();
cgsolver_sparse( val, Irn, Jcn, b, x, N );
t2 = second();
printf("Time for CG (sparse solver) = %f [s]\n",(t2-t1));
**/
free
(
A
);
free
(
b
);
free
(
x
);
free
(
val
);
free
(
Irn
);
free
(
Jcn
);
// free(x0);
return
0
;
}
Event Timeline
Log In to Comment