Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BS95.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <BSprivate.h>
Include dependency graph for BS95.c:

Go to the source code of this file.

Functions

MPI_Comm GetCommunicator ()
 
void ctranspose (int n, double d[n][n])
 
void bs95setup_ (int *ndim, int *nnz, int *nstart, int *nrows, int rp[*nrows+1], int cval[*nnz], double aval[*nnz], int *symm, int *debugwrite)
 
void bs95solve_ (int *ndim, double rhs[*ndim], double x[*ndim], double *tolerance, int *debugwrite)
 
void bs95free_ (int *debugwrite)
 
void bs95finalize_ (int *debugwrite)
 
void serialbs95tridiag_ (int *ndim, double ad[*ndim], double bd[*ndim], double cd[*ndim], double rhs[*ndim], double x[*ndim], int *debugwrite)
 
void serialbs95_ (int *ndim, double A[*ndim][*ndim], double rhs[*ndim], double x[*ndim], int *debugwrite)
 
void serialbs95mat_ (int *ndim, int *nnz, double A[*ndim][*ndim], int rp[*ndim+1], int cval[*nnz], double aval[*nnz], int *debugwrite)
 

Variables

BSprocinfo * procinfo
 
BSspmat * bA
 
BSpar_mat * pA
 
BSpar_mat * f_pA
 
BScomm * Acomm
 
BScomm * fcomm
 
int maxiter = 10000
 

Function Documentation

void bs95finalize_ ( int *  debugwrite)

Definition at line 396 of file BS95.c.

396  {
397 
398  /*
399  // Finalize BlockSolve
400  */
401  if(*debugwrite==1){printf(" BS95FINALIZE\n finalizing BS...");}
402  BSfinalize();
403  if(*debugwrite==1){printf("done\n");}
404 
405 }
void bs95free_ ( int *  debugwrite)

Definition at line 346 of file BS95.c.

References Acomm, bA, f_pA, fcomm, pA, and procinfo.

Referenced by serialbs95_(), and serialbs95tridiag_().

346  {
347 
348  /*
349  // Free matrices
350  */
351  if(*debugwrite==1){printf(" BS95FREE\n freeing matrices...");}
352  BSfree_par_mat(pA);
353  BSfree_copy_par_mat(f_pA);
354  BSfree_easymat(bA);
355  if(*debugwrite==1){printf("done\n");}
356 
357  /*
358  // Free the communication patterns
359  */
360  if(*debugwrite==1){printf(" freeing the communication patterns...");}
361  BSfree_comm(Acomm);
362  BSfree_comm(fcomm);
363  if(*debugwrite==1){printf("done\n");}
364 
365  /*
366  // Free the processor context
367  */
368  if(*debugwrite==1){printf(" freeing the processor context...");}
369  BSfree_ctx(procinfo);
370  if(*debugwrite==1){printf("done\n");}
371 
372 }
BSspmat * bA
Definition: BS95.c:37
BScomm * fcomm
Definition: BS95.c:39
BSprocinfo * procinfo
Definition: BS95.c:36
BSpar_mat * f_pA
Definition: BS95.c:38
BSpar_mat * pA
Definition: BS95.c:38
BScomm * Acomm
Definition: BS95.c:39

Here is the caller graph for this function:

void bs95setup_ ( int *  ndim,
int *  nnz,
int *  nstart,
int *  nrows,
int  rp[*nrows+1],
int  cval[*nnz],
double  aval[*nnz],
int *  symm,
int *  debugwrite 
)

Definition at line 125 of file BS95.c.

References Acomm, bA, f_pA, FALSE, fcomm, GetCommunicator(), i, maxiter, pA, and procinfo.

Referenced by serialbs95_(), and serialbs95tridiag_().

125  {
126 
127  int argc = 1;
128  int i;
129  char **argv;
130  float my_alpha;
131 
132  if(*debugwrite==1) {
133  printf("ndim = %d\n",*ndim);
134  printf("nnz = %d\n",*nnz);
135  printf("nstart = %d\n",*nstart);
136  printf("nrows = %d\n",*nrows);
137  printf("rp = [ ");
138  for(i=0;i<*nrows+1;i++) {
139  printf("%d ",rp[i]);
140  }
141  printf("]\ncval = [ ");
142  for(i=0;i<*nnz;i++) {
143  printf("%d ",cval[i]);
144  }
145  printf("]\naval = [ ");
146  for(i=0;i<*nnz;i++) {
147  printf("%f ",aval[i]);
148  }
149  printf("]\n");
150  }
151 
152 
153  /*
154  // Initialize BlockSolve with dummy command-line arguments
155  */
156  argv = (char ** ) MALLOC(sizeof(char)*argc);
157  for(i=0;i<argc;i++) {
158  argv[i] = "1";
159  }
160  if(*debugwrite==1){printf(" BS95SETUP\n initializing BS...");}
161  BSinit(&argc,&argv);
162  if(*debugwrite==1){printf("done\n");}
163 
164  /*
165  // Get the processor context
166  */
167  if(*debugwrite==1){printf(" getting the processor context...");}
168  procinfo = BScreate_ctx();
169  // MPI_Comm self = MPI_COMM_SELF;
170  MPI_Comm the_communicator = GetCommunicator();
171  BSctx_set_ps(procinfo,the_communicator);
172  BSctx_set_err(procinfo,1);
173  if(*debugwrite==1){printf("done\n");}
174 
175  /*
176  // Create the A matrix in BSspmat datatype
177  */
178  if(*debugwrite==1){printf(" creating the BSspmat A matrix...");}
179  bA = BSeasy_A(*nstart,*nrows,rp,cval,aval,procinfo);
180  if(*debugwrite==1){printf("done\n");}
181 
182  /*
183  // Define whether matrix nonzeros are symmetric
184  */
185  if(*debugwrite==1){printf(" setting up matrix storage...");}
186  BSset_mat_symmetric(bA,*symm);
187  if(*debugwrite==1){printf("done\n");}
188 
189  /*
190  // Set up the storage type (Cholesky or ILU)
191  */
192  if(*debugwrite==1){printf(" setting up storage type...");}
193  BSset_mat_icc_storage(bA,*symm);
194  if(*debugwrite==1){printf("done\n");}
195 
196  /*
197  // Convert matrix to BSpar_mat datatype
198  */
199  if(*debugwrite==1){printf(" permuting the A matrix...");}
200  pA = BSmain_perm(procinfo,bA);
201  if(*debugwrite==1){printf("done\n");}
202 
203  /*
204  // Diagonally scale the matrix
205  */
206  if(*debugwrite==1){printf(" diagonally scaling the A matrix...");}
207  BSscale_diag(pA,pA->diag,procinfo);
208  if(*debugwrite==1){printf("done\n");}
209 
210  /*
211  // Set up communication data structures
212  */
213  if(*debugwrite==1){printf(" setting up communication data structures...");}
214  Acomm = BSsetup_forward(pA,procinfo);
215  fcomm = BSsetup_factor(pA,procinfo);
216  if(*debugwrite==1){printf("done\n");}
217 
218  /*
219  // Copy the pA matrix
220  */
221  if(*debugwrite==1){printf(" creating a copy of the permuted matrix...");}
222  f_pA = BScopy_par_mat(pA);
223  if(*debugwrite==1){printf("done\n");}
224 
225  /*
226  // Factor the matrix
227  */
228  if(*debugwrite==1){printf(" performing an incomplete factorization of the matrix...");}
229  my_alpha = 1.0;
230  while (BSfactor(f_pA,fcomm,procinfo) != 0) {
231  BScopy_nz(pA,f_pA);
232  my_alpha += 0.1;
233  BSset_diag(f_pA,my_alpha,procinfo);
234  }
235  if(*debugwrite==1){printf("done\n");}
236 
237  /*
238  // Set solver parameters
239  */
240  if(*debugwrite==1){printf(" setting solver parameters...");}
241  if(*symm==1) {
242  /* // Use CG if the system is symmetric */
243  BSctx_set_pre(procinfo,PRE_ICC);
244  BSctx_set_method(procinfo,CG);
245  }
246  else {
247  /* // Use GMRES if the system is non-symmetric */
248  BSctx_set_pre(procinfo,PRE_ILU);
249  BSctx_set_method(procinfo,GMRES);
250  }
251  BSctx_set_max_it(procinfo,maxiter);
252  BSctx_set_guess(procinfo,FALSE); /* // Use vector passed in as initial guess */
253  if(*debugwrite==1){printf("done\n");}
254 
255 }
#define FALSE
Definition: vinci.h:133
BSspmat * bA
Definition: BS95.c:37
BScomm * fcomm
Definition: BS95.c:39
int maxiter
Definition: BS95.c:40
BSprocinfo * procinfo
Definition: BS95.c:36
blockLoc i
Definition: read.cpp:79
BSpar_mat * f_pA
Definition: BS95.c:38
MPI_Comm GetCommunicator()
Definition: GetComm.C:6
BSpar_mat * pA
Definition: BS95.c:38
BScomm * Acomm
Definition: BS95.c:39

Here is the call graph for this function:

Here is the caller graph for this function:

void bs95solve_ ( int *  ndim,
double  rhs[*ndim],
double  x[*ndim],
double *  tolerance,
int *  debugwrite 
)

Definition at line 288 of file BS95.c.

References Acomm, f_pA, i, maxiter, pA, procinfo, rhs, and x.

Referenced by serialbs95_(), and serialbs95tridiag_().

288  {
289 
290  FLOAT residual;
291  int num_iter;
292  int i;
293 
294  if(*debugwrite==1) {
295  printf("rhs = [ ");
296  for(i=0;i<*ndim;i++) {
297  printf("%f ",rhs[i]);
298  }
299  printf("]\n");
300  }
301 
302  /*
303  // Solve the system
304  */
305  if(*debugwrite==1){printf(" BS95SOLVE\n solving the system...");}
306  BSctx_set_tol(procinfo,*tolerance);
307  num_iter = BSpar_solve(pA,f_pA,Acomm,rhs,x,&residual,procinfo);
308  if(num_iter >= maxiter) {
309  printf("*** WARNING *** BlockSolve95 using too many iterations. Matrix likely ill-conditioned.\n");
310  }
311  if(*debugwrite==1){
312  printf("done\n");
313  printf(" BS took %d iterations to solve the system\n",num_iter);
314  printf(" x = [ ");
315  for(i=0;i<*ndim;i++) { printf("%f ",x[i]); }
316  printf("]\n");
317  printf(" residual = %e\n",residual);
318  }
319  /* //printf(" BS took %d iterations to solve the system\n",num_iter); */
320 
321 }
NT rhs
int maxiter
Definition: BS95.c:40
BSprocinfo * procinfo
Definition: BS95.c:36
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
BSpar_mat * f_pA
Definition: BS95.c:38
BSpar_mat * pA
Definition: BS95.c:38
BScomm * Acomm
Definition: BS95.c:39

Here is the caller graph for this function:

void ctranspose ( int  n,
double  d[n][n] 
)

Definition at line 71 of file BS95.c.

References d, i, j, and n.

Referenced by serialbs95_(), and serialbs95mat_().

71  {
72  double tempdmat[n][n];
73  int i;
74  int j;
75  for(i=0;i<n;i++) {
76  for(j=0;j<n;j++) {
77  tempdmat[i][j] = d[j][i];
78  }
79  }
80  for(i=0;i<n;i++) {
81  for(j=0;j<n;j++) {
82  d[i][j] = tempdmat[i][j];
83  }
84  }
85 }
const NT & d
blockLoc i
Definition: read.cpp:79
const NT & n
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function:

MPI_Comm GetCommunicator ( )

Definition at line 6 of file GetComm.C.

References COM_get_default_communicator().

Referenced by bs95setup_().

7  {
9  }
MPI_Comm COM_get_default_communicator()
Definition: roccom_c++.h:69

Here is the call graph for this function:

Here is the caller graph for this function:

void serialbs95_ ( int *  ndim,
double  A[*ndim][*ndim],
double  rhs[*ndim],
double  x[*ndim],
int *  debugwrite 
)

Definition at line 554 of file BS95.c.

References A, bs95free_(), bs95setup_(), bs95solve_(), ctranspose(), i, j, rhs, and x.

554  {
555 
556  /*
557  // Solve general systems of equations
558  //
559  // [A]*[x] = [rhs]
560  //
561  */
562 
563  int *rp;
564  int *cval;
565  FLOAT *aval;
566  int i;
567  int j;
568  int nnz;
569  int avali;
570  int nstart = 0;
571  int symm = 0;
572 
573  /*
574  // Print footer
575  */
576  if(*debugwrite==1){printf(" Using BlockSolve95 to solve the system\n");}
577 
578  /*
579  // Transpose the matrix indices of the 2D matrices from Fortran style to C style
580  */
581  ctranspose(*ndim,A);
582 
583  /*
584  // Create the mapping of the nonzero entries of A
585  */
586  if(*debugwrite==1){printf(" defining matrix mapping...");}
587  nnz = 0;
588  for(i=0;i<*ndim;i++) {
589  for(j=0;j<*ndim;j++) {
590  if(A[i][j] != 0.0) {
591  nnz++;
592  }
593  }
594  }
595  aval = (FLOAT *) MALLOC(sizeof(FLOAT)*nnz);
596  cval = (int *) MALLOC(sizeof(int)*nnz);
597  rp = (int *) MALLOC(sizeof(int)*(*ndim+1));
598  printf(" \b"); /* // Give the program time to realize that new stuff has been allocated */
599  avali = 0;
600  rp[0] = 0;
601  for(i=0;i<*ndim;i++) {
602  for(j=0;j<*ndim;j++) {
603  if(A[i][j] != 0.0) {
604  aval[avali] = A[i][j];
605  cval[avali] = j;
606  avali++;
607  }
608  }
609  rp[i+1] = avali; }
610  if(*debugwrite==1){printf("done\n");}
611 
612  /*
613  // Solve the system
614  */
615  double *tol;
616  *tol = 1.0e-09;
617  bs95setup_(ndim,&nnz,&nstart,ndim,rp,cval,aval,&symm,debugwrite);
618  bs95solve_(ndim,rhs,x,tol,debugwrite);
619  bs95free_(debugwrite);
620 
621  /*
622  // Free the matrix mapping
623  */
624  if(*debugwrite==1){printf(" freeing matrix mapping...");}
625  free(aval);
626  free(cval);
627  free(rp);
628  if(*debugwrite==1){printf("done\n");}
629 
630  /*
631  // Transpose the matrix indices of the 2D matrices from C style to Fortran style
632  */
633  ctranspose(*ndim,A);
634 
635  /*
636  // Print footer
637  */
638  if(*debugwrite==1){printf(" Done using BlockSolve95 to solve the system\n");}
639 
640 }
NT rhs
void bs95free_(int *debugwrite)
Definition: BS95.c:346
rational * A
Definition: vinci_lass.c:67
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
void bs95solve_(int *ndim, double rhs[*ndim], double x[*ndim], double *tolerance, int *debugwrite)
Definition: BS95.c:288
j indices j
Definition: Indexing.h:6
void bs95setup_(int *ndim, int *nnz, int *nstart, int *nrows, int rp[*nrows+1], int cval[*nnz], double aval[*nnz], int *symm, int *debugwrite)
Definition: BS95.c:125
void ctranspose(int n, double d[n][n])
Definition: BS95.c:71

Here is the call graph for this function:

void serialbs95mat_ ( int *  ndim,
int *  nnz,
double  A[*ndim][*ndim],
int  rp[*ndim+1],
int  cval[*nnz],
double  aval[*nnz],
int *  debugwrite 
)

Definition at line 669 of file BS95.c.

References A, ctranspose(), i, and j.

669  {
670 
671  /*
672  // Construct the compressed row storage for a matrix
673  */
674 
675  int avali;
676  int i;
677  int j;
678 
679  /*
680  // Transpose the matrix indices of the 2D matrices from Fortran style to C style
681  */
682  ctranspose(*ndim,A);
683 
684  /*
685  // Create the mapping of the nonzero entries of A
686  */
687  if(*debugwrite==1){printf(" SERIALBS95MAT\n defining matrix mapping...");}
688  avali = 0;
689  rp[0] = 0;
690  for(i=0;i<*ndim;i++) {
691  for(j=0;j<*ndim;j++) {
692  if(A[i][j] != 0.0) {
693  aval[avali] = A[i][j];
694  cval[avali] = j;
695  avali++;
696  }
697  }
698  rp[i+1] = avali;
699  }
700  if(*debugwrite==1){printf("done\n");}
701 
702  /*
703  // Transpose the matrix indices of the 2D matrices from C style to Fortran style
704  */
705  ctranspose(*ndim,A);
706 
707 }
rational * A
Definition: vinci_lass.c:67
blockLoc i
Definition: read.cpp:79
j indices j
Definition: Indexing.h:6
void ctranspose(int n, double d[n][n])
Definition: BS95.c:71

Here is the call graph for this function:

void serialbs95tridiag_ ( int *  ndim,
double  ad[*ndim],
double  bd[*ndim],
double  cd[*ndim],
double  rhs[*ndim],
double  x[*ndim],
int *  debugwrite 
)

Definition at line 441 of file BS95.c.

References bs95free_(), bs95setup_(), bs95solve_(), i, rhs, and x.

441  {
442 
443  /*
444  // Solve tridiagonal systems of equations:
445  //
446  // [ bd[0] cd[0] 0 ... 0 ] [ x[0] ] [ rhs[0] ]
447  // [ ad[1] bd[1] cd[1] 0 ... 0 ] [ x[1] ] [ rhs[1] ]
448  // [ . . . ] [ . ] [ . ]
449  // [ . . . ] * [ . ] = [ . ]
450  // [ . . . ] [ . ] [ . ]
451  // [ 0 ... 0 ad[ndim-2] bd[ndim-2] cd[ndim-2] ] [ x[ndim-2] ] [ rhs[ndim-2] ]
452  // [ 0 ... 0 ad[ndim-1] bd[ndim-1] ] [ x[ndim-1] ] [ rhs[ndim-1] ]
453  //
454  */
455 
456  int *rp;
457  int *cval;
458  FLOAT *aval;
459  int i;
460  int nnz;
461  int avali;
462  int nstart = 0;
463  int symm = 1;
464 
465  /*
466  // Print header
467  */
468  if(*debugwrite==1){printf(" Using BlockSolve95 to solve the tridiagonal system...\n");}
469 
470  /*
471  // Create the mapping of the nonzero entries of A
472  */
473  if(*debugwrite==1){printf(" defining matrix mapping...");}
474  nnz = 3*(*ndim)-2;
475  aval = (FLOAT *) MALLOC(sizeof(FLOAT)*nnz);
476  cval = (int *) MALLOC(sizeof(int)*nnz);
477  rp = (int *) MALLOC(sizeof(int)*(*ndim+1));
478  printf(" \b"); /* // Give the program time to realize that new stuff is allocated */
479  aval[0] = bd[0];
480  aval[1] = cd[0];
481  cval[0] = 0;
482  cval[1] = 1;
483  rp[0] = 0;
484  rp[1] = 2;
485  avali = 2;
486  for(i=1;i<*ndim-1;i++) {
487  aval[avali] = ad[i];
488  aval[avali+1] = bd[i];
489  aval[avali+2] = cd[i];
490  cval[avali] = i-1;
491  cval[avali+1] = i;
492  cval[avali+2] = i+1;
493  avali = avali + 3;
494  rp[i+1] = avali;
495  }
496  aval[nnz-2] = ad[*ndim-1];
497  aval[nnz-1] = bd[*ndim-1];
498  cval[nnz-2] = *ndim-2;
499  cval[nnz-1] = *ndim-1;
500  rp[*ndim] = nnz;
501  if(*debugwrite==1){printf("done\n");}
502 
503  /*
504  // Solve the system
505  */
506  double *tol;
507  *tol = 1.0e-09;
508  bs95setup_(ndim,&nnz,&nstart,ndim,rp,cval,aval,&symm,debugwrite);
509  bs95solve_(ndim,rhs,x,tol,debugwrite);
510  bs95free_(debugwrite);
511 
512  /*
513  // Free the matrix mapping
514  */
515  if(*debugwrite==1){printf(" freeing matrix mapping...");}
516  free(aval);
517  free(cval);
518  free(rp);
519  if(*debugwrite==1){printf("done\n");}
520 
521  /*
522  // Print footer
523  */
524  if(*debugwrite==1){printf(" Done using BlockSolve95 to solve the system\n");}
525 
526 }
NT rhs
void bs95free_(int *debugwrite)
Definition: BS95.c:346
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
void bs95solve_(int *ndim, double rhs[*ndim], double x[*ndim], double *tolerance, int *debugwrite)
Definition: BS95.c:288
void bs95setup_(int *ndim, int *nnz, int *nstart, int *nrows, int rp[*nrows+1], int cval[*nnz], double aval[*nnz], int *symm, int *debugwrite)
Definition: BS95.c:125

Here is the call graph for this function:

Variable Documentation

BScomm* Acomm

Definition at line 39 of file BS95.c.

Referenced by bs95free_(), bs95setup_(), and bs95solve_().

BSspmat* bA

Definition at line 37 of file BS95.c.

Referenced by bs95free_(), and bs95setup_().

BSpar_mat * f_pA

Definition at line 38 of file BS95.c.

Referenced by bs95free_(), bs95setup_(), and bs95solve_().

BScomm * fcomm

Definition at line 39 of file BS95.c.

Referenced by bs95free_(), and bs95setup_().

int maxiter = 10000

Definition at line 40 of file BS95.c.

Referenced by bs95setup_(), and bs95solve_().

BSpar_mat* pA

Definition at line 38 of file BS95.c.

Referenced by bs95free_(), bs95setup_(), and bs95solve_().

BSprocinfo* procinfo

Definition at line 36 of file BS95.c.

Referenced by bs95free_(), bs95setup_(), and bs95solve_().