<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><head><META content="text/html; charset=utf-8" http-equiv="Content-Type">
<META content="text/html; charset=utf-8" http-equiv="Content-Type">
<STYLE TYPE="text/css"><!-- /* Style Definitions */p.75f0858b-6f5c-4282-b8cb-21279027696c, li.75f0858b-6f5c-4282-b8cb-21279027696c, div.75f0858b-6f5c-4282-b8cb-21279027696c, table.75f0858b-6f5c-4282-b8cb-21279027696cTable         {margin:0cm;        margin-bottom:.0001pt;} div.Section1 {page:Section1;} --></STYLE>
<META content="text/html; charset=utf-8" HTTP-EQUIV="Content-Type">
<META CONTENT="MS Exchange Server version 6.5.7638.1" NAME="Generator">
<TITLE>call PetscOptionsSetValue in fortran</TITLE>
<META content="text/html; charset=utf-8" http-equiv="Content-Type">
</head><BODY>
<FONT FACE="Arial" SIZE="2">
<P><FONT FACE="Arial" SIZE="2">
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>I'm trying to change the options of the Hypre preconditioner using PetscOptionsSetValue in a fortran program, but I must be doing something wrong, see the session below. It works fine from the command line, though. As an example, I took ex12f from src/ksp/ksp/examples/tests (petsc-2.3.3-p13) and modified it a little.<BR>
<BR>
<BR>
$ cat ex12f.F<BR>
!<BR>
program main<BR>
implicit none<BR>
<BR>
#include "include/finclude/petsc.h"<BR>
#include "include/finclude/petscvec.h"<BR>
#include "include/finclude/petscmat.h"<BR>
#include "include/finclude/petscpc.h"<BR>
#include "include/finclude/petscksp.h"<BR>
#include "include/finclude/petscviewer.h"<BR>
!<BR>
! This example is the Fortran version of ex6.c. The program reads a PETSc matrix<BR>
! and vector from a file and solves a linear system. Input arguments are:<BR>
! -f <input_file> : file to load. For a 5X5 example of the 5-pt. stencil<BR>
! use the file petsc/src/mat/examples/matbinary.ex<BR>
!<BR>
<BR>
PetscErrorCode ierr<BR>
PetscInt its<BR>
PetscTruth flg<BR>
PetscScalar norm,none<BR>
Vec x,b,u<BR>
Mat A<BR>
character*(128) f<BR>
PetscViewer fd<BR>
MatInfo info(MAT_INFO_SIZE)<BR>
KSP ksp<BR>
! cklaij: adding pc<BR>
PC pc<BR>
! cklaij: adding pc end<BR>
<BR>
none = -1.0<BR>
call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<BR>
<BR>
! Read in matrix and RHS<BR>
call PetscOptionsGetString(PETSC_NULL_CHARACTER,'-f',f,flg,ierr)<BR>
print *,f<BR>
call PetscViewerBinaryOpen(PETSC_COMM_WORLD,f,FILE_MODE_READ, &<BR>
& fd,ierr)<BR>
<BR>
call MatLoad(fd,MATSEQAIJ,A,ierr)<BR>
<BR>
! Get information about matrix<BR>
call MatGetInfo(A,MAT_GLOBAL_SUM,info,ierr)<BR>
write(*,100) info(MAT_INFO_ROWS_GLOBAL), &<BR>
& info(MAT_INFO_COLUMNS_GLOBAL), &<BR>
& info(MAT_INFO_ROWS_LOCAL),info(MAT_INFO_COLUMNS_LOCAL), &<BR>
& info(MAT_INFO_BLOCK_SIZE),info(MAT_INFO_NZ_ALLOCATED), &<BR>
& info(MAT_INFO_NZ_USED),info(MAT_INFO_NZ_UNNEEDED), &<BR>
& info(MAT_INFO_MEMORY),info(MAT_INFO_ASSEMBLIES), &<BR>
& info(MAT_INFO_MALLOCS)<BR>
<BR>
100 format(11(g7.1,1x))<BR>
call VecLoad(fd,PETSC_NULL_CHARACTER,b,ierr)<BR>
call PetscViewerDestroy(fd,ierr)<BR>
<BR>
! Set up solution<BR>
call VecDuplicate(b,x,ierr)<BR>
call VecDuplicate(b,u,ierr)<BR>
<BR>
! Solve system<BR>
call KSPCreate(PETSC_COMM_WORLD,ksp,ierr)<BR>
call KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN,ierr)<BR>
call KSPSetFromOptions(ksp,ierr)<BR>
! cklaij: try boomeramg<BR>
call KSPGetPC(ksp,pc,ierr)<BR>
call PCSetType(pc,PCHYPRE,ierr)<BR>
call PCHYPRESetType(pc,"boomeramg",ierr)<BR>
call PetscOptionsSetValue<BR>
& ("-pc_hypre_boomeramg_strong_threshold","0.5",ierr)<BR>
! cklaij: try boomeramg end<BR>
call KSPSolve(ksp,b,x,ierr)<BR>
<BR>
! Show result<BR>
call MatMult(A,x,u,ierr)<BR>
call VecAXPY(u,none,b,ierr)<BR>
call VecNorm(u,NORM_2,norm,ierr)<BR>
call KSPGetIterationNumber(ksp,its,ierr)<BR>
print*, 'Number of iterations = ',its<BR>
print*, 'Residual norm = ',norm<BR>
<BR>
! Cleanup<BR>
call KSPDestroy(ksp,ierr)<BR>
call VecDestroy(b,ierr)<BR>
call VecDestroy(x,ierr)<BR>
call VecDestroy(u,ierr)<BR>
call MatDestroy(A,ierr)<BR>
<BR>
call PetscFinalize(ierr)<BR>
end<BR>
<BR>
$ ./ex12f -f ../../../../mat/examples/matbinary.ex -ksp_view | grep Threshold<BR>
HYPRE BoomerAMG: Threshold for strong coupling 0.25<BR>
$ ./ex12f -f ../../../../mat/examples/matbinary.ex -pc_type hypre -pc_hypre_type boomeramg -pc_hypre_boomeramg_strong_threshold 0.5 -ksp_view | grep Threshold<BR>
HYPRE BoomerAMG: Threshold for strong coupling 0.5<BR>
$<BR>
</FONT>
</P>
</FONT></P><FONT FACE="Arial" SIZE="2">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="1" STYLE="WIDTH: 475px; HEIGHT: 180px" WIDTH="471">
<TBODY>
<TR>
<TD COLSPAN="3"><IMG ALIGN="left" ALT BORDER="0" HSPACE="0" SRC="cid:imagea7dbf8.jpg@7ba3538a.818d4bfb" STYLE="VERTICAL-ALIGN: bottom"><IMG ALIGN="center" ALT BORDER="0" HEIGHT="26" HSPACE="0" SRC="cid:image811ed8.jpg@ec1b9d7c.181446d2" STYLE="VERTICAL-ALIGN: top; WIDTH: 410px; HEIGHT: 26px" WIDTH="404"></TD></TR>
<TR>
<TD COLSPAN="3"><FONT COLOR="#828282" FACE="Arial" SIZE="2">dr. ir. Christiaan Klaij</FONT></TD></TR>
<TR>
<TD COLSPAN="3"><FONT COLOR="#828282" FACE="Arial" SIZE="2">CFD Researcher</FONT></TD></TR>
<TR>
<TD COLSPAN="3"><FONT COLOR="#828282" FACE="Arial" SIZE="2">Research & Development</FONT></TD></TR>
<TR>
<TD></TD>
<TD><FONT COLOR="#828282" FACE="Arial" SIZE="2"><STRONG>MARIN</STRONG></FONT></TD></TR>
<TR>
<TD WIDTH="45%"></TD>
<TD WIDTH="30%"><FONT COLOR="#828282" FACE="Arial" SIZE="2">2, Haagsteeg</FONT></TD>
<TD></TD></TR>
<TR>
<TD WIDTH="45%"><FONT FACE="Arial" SIZE="2" STYLE="TEXT-TRANSFORM: lowercase"><a href="mailto:C.Klaij@marin.nl">C.Klaij@marin.nl</a></FONT></TD>
<TD WIDTH="30%"><FONT COLOR="#828282" FACE="Arial" SIZE="2">P.O. Box 28</FONT></TD>
<TD WIDTH="25%"><FONT COLOR="#828282" FACE="Arial" SIZE="2"><FONT COLOR="#828282">T </FONT>+31 317 49 39 11</FONT></TD>
<TR>
<TD WIDTH="45%"><FONT COLOR="#828282" FACE="Arial" SIZE="2"></FONT></TD>
<TD WIDTH="30%"><FONT COLOR="#828282" FACE="Arial" SIZE="2">6700 AA Wageningen</FONT></TD>
<TD WIDTH="25%"><FONT COLOR="#828282" FACE="Arial" SIZE="2">F +31 317 49 32 45</FONT></TD></TR>
<TR>
<TD WIDTH="45%"><FONT COLOR="#828282" FACE="Arial" SIZE="2">T <FONT COLOR="#828282" FACE="Arial" SIZE="2">+31 317 49 33 44</FONT></FONT></TD>
<TD WIDTH="30%"><FONT COLOR="#828282" FACE="Arial" SIZE="2">The Netherlands</FONT></TD>
<TD WIDTH="25%"><FONT COLOR="#828282" FACE="Arial" SIZE="2"><FONT COLOR="#828282">I </FONT><A HREF="http://www.marin.nl/"><FONT COLOR="blue">www.marin.nl</FONT></A></FONT></TD></TR></TR></TBODY></TABLE>
<P></P></FONT><FONT FACE="Arial" SIZE="2"><FONT FACE="Arial" SIZE="2"></FONT></FONT>
<P></P>
<P><FONT COLOR="#828282" FACE="Arial" SIZE="2"><A HREF="http://www.marin.nl/web/show/id=46836/contentid=2324"><FONT FACE="Arial" SIZE="2">MARIN webnews:</FONT></A><FONT FACE="Arial" SIZE="2"> <SPAN LANG="NL" STYLE="FONT-SIZE: 10pt; FONT-FAMILY: Arial">First AMT'09 conference, Nantes, France, September 1-2</SPAN> <BR></FONT></FONT><BR></P></FONT><SPAN STYLE="FONT-SIZE: 10pt; FONT-STYLE: italic; FONT-FAMILY: Arial"><FONT COLOR="#828282" SIZE="1"><FONT COLOR="gray" FACE="Arial" SIZE="1"><SPAN LANG="EN-GB" STYLE="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: Arial">This e-mail may be confidential, privileged and/or protected by copyright. If you are not the intended recipient, you should return it to the sender immediately and delete your copy from your system.<BR></SPAN></FONT></FONT></SPAN><BR></BODY></HTML>