# An example of PETSc on Windows

**URL:** https://community.freefem.org/t/an-example-of-petsc-on-windows/1447
**Category:** General Discussion
**Created:** [January 19, 2022, 12:56pm UTC](https://community.freefem.org/t/an-example-of-petsc-on-windows/1447 "2022-01-19T12:56:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)
#### Post date: [January 19, 2022, 12:56pm UTC](https://community.freefem.org/t/an-example-of-petsc-on-windows/1447/1 "2022-01-19T12:56:02Z")

</div>

Hello everyone, I ran an example of PETSc on Windows,  
load “PETSc”  
macro dimension()2// EOM  
include “macro\_ddm.idp”  
macro grad(u)[dx(u), dy(u)]// EOM  
load “Element\_P3”  
func Pk = P3;

border upper(t=0, pi) { x=cos(t); y=sin(t); label=1; }  
border lower(t=pi, 2\*pi) { x=cos(t); y=sin(t); label=2; }  
mesh Th = buildmesh(upper(100) + lower(100));  
Mat A;  
createMat(Th, A, Pk)

fespace Vh(Th, Pk);  
varf vPb(u, v) = intN(Th)(grad(u)’ \* grad(v)) + intN(Th)(v) + on(2, u = 0);  
matrix Loc = vPb(Vh, Vh, tgv = -2);  
real[int] b = vPb(0, Vh, tgv = -1);

A = Loc;

Vh u;  
set(A, sparams = “-pc\_type cholesky -ksp\_type bcgs -ksp\_converged\_reason”);  
ObjectView(A, object = “ksp”);  
u[] = A^-1 \* b;  
plotD(Th, u, cmm = “Solution with -pc\_type cholesky”)

set(A, sparams = “-pc\_type gamg -ksp\_type gmres”);

u[] = 0;  
u[] = A^-1 \* b;  
ObjectView(A, object = “ksp”);  
plotD(Th, u, cmm = “Solution with -pc\_type gamg”)

but failed to run,  
– FreeFem++ v4.1 (Sat, Nov 13, 2021 7:40:01 PM - git v4.10)  
file : C:\Users\DELL\Desktop\kg\Text122  
Load: lg\_fem lg\_mesh lg\_mesh3 eigenvalue  
1 : load “PETSc”(load: loadLibary E:\FreeFem++\.\PETSc = 0)  
2 : macro dimension()2// EOM  
2 & macro macroDDMidp()1// EOMACRO(!macroDDMidp)  
5 & macro partitioner()metis// EOM  
6 & ENDIFMACRO  
9 & macro partitionerSeq(part, Th, size){ if(size \<= 1) part = 0; else metisdual(part, Th, size); }// EOM  
10 & macro partitionerPar(part, Th, comm, size)broadcast(processor(0, comm), part)// EOM  
11 & ENDIFMACRO  
14 & macro partitionerSeq(part, Th, size){ if(size \<= 1) part = 0; else scotch(part, Th, size); }// EOM  
15 & macro partitionerPar(part, Th, comm, size)broadcast(processor(0, comm), part)// EOM  
16 & ENDIFMACRO  
19 & macro partitionerSeq(part, Th, size)// EOM  
20 & macro partitionerPar(part, Th, comm, size)parmetis(part, Th, size, communicator = comm, worker = getARGV("-parmetis\_worker", 1))// EOM  
21 & ENDIFMACRO  
25 & ENDIFMACROhe macro ‘partitioner’ must be set to ‘metis’, ‘scotch’, or ‘parmetis’" \<\< endl;  
27 & macro meshN()mesh// EOM // two-dimensional problem  
28 & macro intN()int2d// EOM // two-dimensional integral  
29 & macro intN1()int1d// EOM // one-dimensional integral  
30 & macro readmeshN()readmesh// EOM // two-dimensional problem  
31 & macro defVel(u)[u, u#Y]// EOM // two-dimensional velocity for convect/advect  
…  
927 @  
927 @ ThTab.resize( 1);  
928 @ ThBorderTab.resize( 1);  
929 @ prolongation.resize( 1 - 1);  
930 @ real timerPartition = mpiWtime The Identifier mpiWtime does not exist

Error line number 930, in file macro: buildOverlapEdgePeriodicRecursive in E:\FreeFem++\idp\macro\_ddm.idp, before token mpiWtime

current line = 930  
Compile error :  
line number :930, mpiWtime  
error Compile error :  
line number :930, mpiWtime  
code = 1 mpirank: 0

why,Seek guidance .

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 19, 2022, 7:32pm UTC](https://community.freefem.org/t/an-example-of-petsc-on-windows/1447/2 "2022-01-19T19:32:11Z")

</div>

You need to use `FreeFem++-mpi`, not `FreeFem++`, see, e.g., [Hydrodynamic Stability Implementation in FreeFEM - #4 by prj](https://community.freefem.org/t/hydrodynamic-stability-implementation-in-freefem/622/4).
