<!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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; program main<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; implicit none<BR>
<BR>
#include &quot;include/finclude/petsc.h&quot;<BR>
#include &quot;include/finclude/petscvec.h&quot;<BR>
#include &quot;include/finclude/petscmat.h&quot;<BR>
#include &quot;include/finclude/petscpc.h&quot;<BR>
#include &quot;include/finclude/petscksp.h&quot;<BR>
#include &quot;include/finclude/petscviewer.h&quot;<BR>
!<BR>
!&nbsp; This example is the Fortran version of ex6.c.&nbsp; The program reads a PETSc matrix<BR>
!&nbsp; and vector from a file and solves a linear system.&nbsp; Input arguments are:<BR>
!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -f &lt;input_file&gt; : file to load.&nbsp; For a 5X5 example of the 5-pt. stencil<BR>
!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use the file petsc/src/mat/examples/matbinary.ex<BR>
!<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscErrorCode&nbsp; ierr<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscInt its<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscTruth flg<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscScalar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; norm,none<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x,b,u<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; character*(128)&nbsp; f<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscViewer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fd<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MatInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; info(MAT_INFO_SIZE)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KSP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ksp<BR>
! cklaij: adding pc<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pc<BR>
! cklaij: adding pc end<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; none = -1.0<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<BR>
<BR>
! Read in matrix and RHS<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PetscOptionsGetString(PETSC_NULL_CHARACTER,'-f',f,flg,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print *,f<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PetscViewerBinaryOpen(PETSC_COMM_WORLD,f,FILE_MODE_READ,&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp;&nbsp;&nbsp;&nbsp; fd,ierr)<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call MatLoad(fd,MATSEQAIJ,A,ierr)<BR>
<BR>
! Get information about matrix<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call MatGetInfo(A,MAT_GLOBAL_SUM,info,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,100) info(MAT_INFO_ROWS_GLOBAL),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp; info(MAT_INFO_COLUMNS_GLOBAL),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp; info(MAT_INFO_ROWS_LOCAL),info(MAT_INFO_COLUMNS_LOCAL),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp; info(MAT_INFO_BLOCK_SIZE),info(MAT_INFO_NZ_ALLOCATED),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp; info(MAT_INFO_NZ_USED),info(MAT_INFO_NZ_UNNEEDED),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp; info(MAT_INFO_MEMORY),info(MAT_INFO_ASSEMBLIES),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp; info(MAT_INFO_MALLOCS)<BR>
<BR>
&nbsp;100&nbsp; format(11(g7.1,1x))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecLoad(fd,PETSC_NULL_CHARACTER,b,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PetscViewerDestroy(fd,ierr)<BR>
<BR>
! Set up solution<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDuplicate(b,x,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDuplicate(b,u,ierr)<BR>
<BR>
! Solve system<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPCreate(PETSC_COMM_WORLD,ksp,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPSetFromOptions(ksp,ierr)<BR>
! cklaij: try boomeramg<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPGetPC(ksp,pc,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PCSetType(pc,PCHYPRE,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PCHYPRESetType(pc,&quot;boomeramg&quot;,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PetscOptionsSetValue<BR>
&nbsp;&nbsp;&nbsp;&nbsp; &amp;&nbsp;&nbsp;&nbsp;&nbsp; (&quot;-pc_hypre_boomeramg_strong_threshold&quot;,&quot;0.5&quot;,ierr)<BR>
! cklaij: try boomeramg end<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPSolve(ksp,b,x,ierr)<BR>
<BR>
! Show result<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call MatMult(A,x,u,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecAXPY(u,none,b,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecNorm(u,NORM_2,norm,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPGetIterationNumber(ksp,its,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print*, 'Number of iterations = ',its<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print*, 'Residual norm = ',norm<BR>
<BR>
! Cleanup<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPDestroy(ksp,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDestroy(b,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDestroy(x,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDestroy(u,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call MatDestroy(A,ierr)<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call PetscFinalize(ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<BR>
<BR>
$ ./ex12f&nbsp; -f ../../../../mat/examples/matbinary.ex -ksp_view | grep Threshold<BR>
&nbsp;&nbsp;&nbsp; HYPRE BoomerAMG: Threshold for strong coupling 0.25<BR>
$ ./ex12f&nbsp; -f ../../../../mat/examples/matbinary.ex -pc_type hypre -pc_hypre_type boomeramg -pc_hypre_boomeramg_strong_threshold 0.5 -ksp_view | grep Threshold<BR>
&nbsp;&nbsp;&nbsp; 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&nbsp;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 &amp; 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&nbsp; 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&nbsp;&nbsp;<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&nbsp; </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>