~ubuntu-branches/ubuntu/warty/petsc/warty

« back to all changes in this revision

Viewing changes to src/sles/pc/impls/spai/examples/tutorials/ex2.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2004-06-07 13:41:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040607134143-92p586zrauvie0le
Tags: 2.2.0-2
* Upstream patch level 2.
* New PETSC_BOPT_EXTRA option for different BOPT and lib names, with _c++
  symlinks only for plain and single (closes: #249617).
* New DEBIAN_DIST=contrib option to link with hypre, parmetis (closes:
  #249619).
* Combined petsc-c and petsc-fortran substvars into petsc-compilers.
* Extra quote in -dev prerm eliminates "too many arguments" problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#ifdef PETSC_RCS_HEADER
3
 
static char vcid[] = "$Id: ex2.c,v 1.2 1999/04/06 21:27:41 bsmith Exp $";
4
 
#endif
5
 
 
6
 
static char help[] = 
7
 
"Reads a PETSc matrix and vector from a file and saves in an ASCII file that\n\
8
 
  can be read by the SPAI test program.  Input parameters include\n\
9
 
  -f0 <input_file> : file to load\n\n";
10
 
 
11
 
/*T
12
 
   Routines: MatLoad(); VecLoad();
13
 
   Routines: ViewerBinaryOpen();
14
 
   Processors: 1
15
 
T*/
16
 
 
17
 
/* 
18
 
  Include "mat.h" so that we can use matrices.  Note that this file
19
 
  automatically includes:
20
 
     petsc.h  - base PETSc routines   vec.h - vectors
21
 
     sys.h    - system routines       is.h  - index sets
22
 
     viewer.h - viewers
23
 
*/
24
 
#include "mat.h"
25
 
#include "src/contrib/spai/include/spai.h"
26
 
 
27
 
int main(int argc,char **args)
28
 
{
29
 
  Mat        A;                /* matrix */
30
 
  Vec        b;                /* RHS */
31
 
  Viewer     viewer;               /* viewer */
32
 
  char       file[128];        /* input file name */
33
 
  int        ierr, flg;
34
 
  PetscTruth set;
35
 
  MatType    mtype;
36
 
  FILE       *fd;
37
 
 
38
 
  PetscInitialize(&argc,&args,(char *)0,help);
39
 
 
40
 
#if defined(USE_PETSC_COMPLEX)
41
 
  SETERRA(1,0,"This example does not work with complex numbers");
42
 
#else
43
 
 
44
 
  /* 
45
 
     Determine files from which we read the linear system
46
 
     (matrix and right-hand-side vector).
47
 
  */
48
 
  ierr = OptionsGetString(PETSC_NULL,"-f0",file,127,&flg); CHKERRA(ierr);
49
 
  if (!flg) SETERRA(1,0,"Must indicate binary file with the -f0 option");
50
 
 
51
 
 
52
 
  /* 
53
 
       Open binary file.  Note that we use BINARY_RDONLY to indicate
54
 
       reading from this file.
55
 
  */
56
 
  ierr = ViewerBinaryOpen(PETSC_COMM_WORLD,file,BINARY_RDONLY,&viewer);CHKERRA(ierr);
57
 
 
58
 
  /* 
59
 
       Determine matrix format to be used (specified at runtime).
60
 
       See the manpage for MatLoad() for available formats.
61
 
  */
62
 
  ierr = MatGetTypeFromOptions(PETSC_COMM_WORLD,0,&mtype,&set); CHKERRQ(ierr);
63
 
 
64
 
  /*
65
 
       Load the matrix and vector; then destroy the viewer.
66
 
  */
67
 
  ierr = MatLoad(viewer,mtype,&A); CHKERRA(ierr);
68
 
  ierr = VecLoad(viewer,&b); CHKERRA(ierr);
69
 
  ierr = ViewerDestroy(viewer); CHKERRA(ierr);
70
 
 
71
 
  fd = fopen("example_matrix","w");
72
 
  ierr = MatDumpSPAI(A,fd); CHKERRQ(ierr);
73
 
  fclose(fd);
74
 
  fd = fopen("example_rhs","w");
75
 
  ierr = VecDumpSPAI(b,fd); CHKERRQ(ierr);
76
 
  fclose(fd);
77
 
 
78
 
  ierr = MatDestroy(A); CHKERRA(ierr);
79
 
  ierr = VecDestroy(b); CHKERRA(ierr);
80
 
 
81
 
  PetscFinalize();
82
 
#endif
83
 
  return 0;
84
 
}