AcouSTO  version 2.0

◆ solve_linear_system()

solve_linear_system ( int  icounter)

Solves the linear system of equation stored in solution_struct. The function uses the ScaLAPACK functions to solve the system.

Parameters
[in]icounter
42  {
43 
44 #ifdef _ACOUSTO_DEBUG
45  FILE* rhsfile;
46  char fname[15];
47  int ipsiu;
48  int i;
49 #endif
50  int descY[9];
51  int descRHS[9];
52 
53  COMPLEX* work;
54  int lwork;
55  int info;
56 
57  int gRows,gCols;
58  int locRows,locCols;
59 
60  int descsol[9];
61 
62  int itemp;
63  int izero = 0;
64  int ione =1;
65 
66  int nn,mm;
67  double t1,t2;
68 
69 
70 
71 #ifdef _ACOUSTO_DEBUG
72  rhsfile = fopen("rhs.sc","w");
73  fprintf(rhsfile,"b=[");
74  for(i=0;i<modgeominfo->ncntr;i++){
75  fprintf(rhsfile,"%f + %%i*%f ,",CREAL(solution->rhs[ i ]),CIMAG(solution->rhs[ i ]));
76  }
77  fprintf(rhsfile,"]");
78  fclose(rhsfile);
79 #endif
80 
81  gRows = modgeominfo->ncntr + modgeominfo->nchief;
82  gCols = modgeominfo->ncntr;
83 
84  locRows = numroc_(&gRows ,&runinfo->row_block_size,&runinfo->myrow,&izero,&runinfo->nprows);
85  locCols = numroc_(&gCols ,&runinfo->col_block_size,&runinfo->mycol,&izero,&runinfo->npcols);
86 
87 
88  itemp = max(1,locRows);
89  descinit_(descY ,&gRows,&gCols,&runinfo->row_block_size,&runinfo->col_block_size,&izero,&izero,&runinfo->ctxt,&locRows,&info);
90  descinit_(descRHS ,&gRows,&ione ,&runinfo->row_block_size,&ione ,&izero,&izero,&runinfo->ctxt,&locRows,&info);
91 
92  work = calloc(2,sizeof(COMPLEX));
93  lwork = -1;
94 
95  pzgels_( "N", &gRows,&gCols,&ione, solution->matY, &ione,&ione,descY, solution->rhs , &ione,&ione,descRHS, work,&lwork,&info);
96 
97  lwork = (int) work[0];
98 
99  free(work);
100  work = calloc(lwork,sizeof(COMPLEX));
101 
102  t1 = MPI_Wtime();
103  pzgels_( "N", &gRows,&gCols,&ione, solution->matY, &ione,&ione,descY, solution->rhs , &ione,&ione,descRHS, work,&lwork,&info);
104  t2 = MPI_Wtime();
105  logger(LOG_DEBUG," Pseudoinverse evaluation took %f s\n",(t2-t1));
106 
107  free(work);
108 
109  // Collecting solution on node zero and broadcasting to everyone
110  mm = gRows;// * runinfo->nprows;
111  nn = runinfo->npcols;
112  descinit_(descsol , &mm ,&ione, &gRows ,&ione,&izero,&izero,&runinfo->ctxt,&gRows ,&info);
113  pzgemr2d_(&gRows,&ione,solution->rhs,&ione, &ione,descRHS, solution->sol,&ione,&ione,descsol,&runinfo->ctxt);
114 
115 
116  MPI_Bcast(solution->sol,gRows,MPI_ACOUSTO_COMPLEX,0,MPI_COMM_WORLD);
117 
118 
119 }
struct run_info * runinfo
Definition: globals.h:34
int npcols
Definition: structs.h:113
int ncntr
Definition: structs.h:299
COMPLEX * matY
Definition: structs.h:603
static int max(int a, int b)
Definition: linsys.c:30
#define CREAL(x)
Definition: functions.h:49
#define MPI_ACOUSTO_COMPLEX
Definition: types.h:56
int myrow
Definition: structs.h:115
int nprows
Definition: structs.h:111
#define CIMAG(x)
Definition: functions.h:50
int nchief
Definition: structs.h:301
COMPLEX * sol
Definition: structs.h:607
void pzgemr2d_(int *m, int *n, COMPLEX *A, int *ia, int *ja, int *desca, COMPLEX *B, int *ib, int *jb, int *descb, int *ictxt)
Copies a (m x n) submatrix of A from element (ia,ja) on a submatrix of B from element (ib...
int ctxt
Definition: structs.h:109
void descinit_(int *desc, int *m, int *n, int *mb, int *nb, int *ia, int *ja, int *ictxt, int *llda, int *info)
struct solution_struct * solution
Definition: globals.h:52
#define COMPLEX
Definition: types.h:48
#define LOG_DEBUG
Definition: logger.h:27
int mycol
Definition: structs.h:117
int numroc_(int *m, int *mb, int *p, int *ia, int *npr)
int col_block_size
Definition: structs.h:121
void pzgels_(char *trans, int *m, int *n, int *nrhs, COMPLEX *A, int *ia, int *ja, int *desca, COMPLEX *rhs, int *irhs, int *jrhs, int *descrhs, COMPLEX *work, int *lwork, int *info)
COMPLEX * rhs
Definition: structs.h:605
int row_block_size
Definition: structs.h:119
void logger(int level, char *msg,...)
Definition: logger.c:56
#define calloc(n, size)
Definition: allocation.h:37
struct modgeom_info * modgeominfo
Definition: globals.h:38