14 x[
"i"] = -R[
"ij"]*x[
"j"];
36 spA[
"ij"] += dnA[
"ij"];
40 dnA[
"ij"] = spA[
"ij"];
49 spR[
"ij"] = spA[
"ij"];
50 dnR[
"ij"] = dnA[
"ij"];
60 for (iter=0; iter<100; iter++){
64 res[
"i"] -= dnA[
"ij"]*c1[
"j"];
66 res_norm = res.
norm2();
67 if (res_norm < 1.E-4)
break;
71 printf(
"Completed %d iterations of Jacobi with dense matrix, residual F-norm is %E\n", iter, res_norm);
74 for (iter=0; iter<100; iter++){
78 res[
"i"] -= spA[
"ij"]*c2[
"j"];
80 res_norm = res.
norm2();
81 if (res_norm < 1.E-4)
break;
85 printf(
"Completed %d iterations of Jacobi with sparse matrix, residual F-norm is %E\n", iter, res_norm);
90 bool pass = c2.
norm2() <= 1.E-6;
94 printf(
"{ Jacobi x[\"i\"] = (1./A[\"ii\"])*(b[\"j\"] - (A[\"ij\"]-A[\"ii\"])*x[\"j\"]) with sparse A } passed \n");
96 printf(
"{ Jacobi x[\"i\"] = (1./A[\"ii\"])*(b[\"j\"] - (A[\"ij\"]-A[\"ii\"])*x[\"j\"]) with sparse A } failed \n");
106 char ** itr = std::find(begin, end, option);
107 if (itr != end && ++itr != end){
114 int main(
int argc,
char ** argv){
116 int const in_num = argc;
117 char ** input_str = argv;
119 MPI_Init(&argc, &argv);
120 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
121 MPI_Comm_size(MPI_COMM_WORLD, &np);
124 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
130 World dw(argc, argv);
133 printf(
"Running Jacobi method on random %d-by-%d sparse matrix\n",n,n);
Matrix class which encapsulates a 2D tensor.
int jacobi(int n, World &dw)
Vector class which encapsulates a 1D tensor.
an instance of the CTF library (world) on a MPI communicator
dtype norm2()
computes the frobenius norm of the tensor (needs sqrt()!)
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
int rank
rank of local processor
int main(int argc, char **argv)
void sparsify()
reduce tensor to sparse format, storing only nonzero data, or data above a specified threshold...
char * getCmdOption(char **begin, char **end, const std::string &option)
void jacobi_iter(Matrix<> &R, Vector<> &b, Vector<> &d, Vector<> &x)