1. I have some knowledge in C/C++ programming, because i am electronic engineering student.
2. I have created Mpich 2 cluster and installed scalapack.
3. And most important I need to calculate Ax=b, where A is N by N matrix and b is N row.
4. From google i found some examples, but they are without comments and difficult to understood.
5. Please help me !!
my simplest code is bellow:
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
int main(int argc, char **argv)
{
int rank, size;
MPI_Init( &argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
int N;
N=9;
//2D matrix converted to 1D by row
double *A=(double*)malloc(N*N*sizeof(double));
A[0]=1;
A[1]=-0.5;
A[2]=0;
A[3]=-0.5;
A[4]=0;
A[5]=0;
A[6]=0;
A[7]=0;
A[8]=0;
A[9]=-0.5;
A[10]=2;
A[11]=-0.5;
A[12]=0;
A[13]=-1;
A[14]=0;
A[15]=0;
A[16]=0;
A[17]=0;
A[18]=0;
A[19]=-0.5;
A[20]=1;
A[21]=0;
A[22]=0;
A[23]=-0.5;
A[24]=0;
A[25]=0;
A[26]=0;
A[27]=-0.5;
A[28]=0;
A[29]=0;
A[30]=2;
A[31]=-1;
A[32]=0;
A[33]=-0.5;
A[34]=0;
A[35]=0;
A[36]=0;
A[37]=-1;
A[38]=0;
A[39]=-1;
A[40]=4;
A[41]=-1;
A[42]=0;
A[43]=-1;
A[44]=0;
A[45]=0;
A[46]=0;
A[47]=-0.5;
A[48]=0;
A[49]=-1;
A[50]=2;
A[51]=0;
A[52]=0;
A[53]=-0.5;
A[54]=0;
A[55]=0;
A[56]=0;
A[57]=-0.5;
A[58]=0;
A[59]=0;
A[60]=1;
A[61]=-0.5;
A[62]=0;
A[63]=0;
A[64]=0;
A[65]=0;
A[66]=0;
A[67]=-1;
A[68]=0;
A[69]=-0.5;
A[70]=2;
A[71]=-0.5;
A[72]=0;
A[73]=0;
A[74]=0;
A[75]=0;
A[76]=0;
A[77]=-0.5;
A[78]=0;
A[79]=-0.5;
A[80]=1;
//RHS
double *B=(double*)malloc(N*sizeof(double));
B[0]=0;
B[1]=0;
B[2]=0;
B[3]=0;
B[4]=1;
B[5]=0;
B[6]=0;
B[7]=0;
B[8]=0;
//=============RESULT MUST BE=============//
//0.8 0.9 0.8
//0.7 1 0.7
//0 0 0
//========================================//
MPI_Finalize();
exit(0);
}

