Tutorial example demonstrating how to use PETSc / Parallel

This tutorial script show how to modify your programs to use parallel computing with PETSc The sample problems considered here are the same ones as in SCRIPT_Lshape_parallel.m.

The FreeFem programs have only been modified for a few lines compared to their sequential versions. See inside the program for explanations.

Contents

Initialization

close all;
addpath([fileparts(fileparts(pwd)) '/SOURCES_MATLAB']);

SF_Start('verbosity',3);
SF_core_setopt('ffdatadir','./WORK_parallel/');
SF_core_arborescence('cleanall');
NOTICE  - Initialization already done
NOTICE  - Verbosity set to 3 : Notice messages
NOTICE  - Database directory :./WORK/
NOTICE  - Working dir does not exist : create it
NOTICE  - Database directory :./WORK_parallel/
NOTICE  - Working dir does not exist : create it
NOTICE  - CLEANALL in SF_core_arborescence ; working dir ./WORK_parallel/ is now empty
NOTICE  - Cleaning ALL arborescence ./WORK_parallel/

Build the mesh (sequencial)

Ndensity =40;
ffmesh = SF_Mesh('Lshape_Mesh.edp','Options',{'meshdensity',Ndensity});
NOTICE  -       ### INITIAL MESH CREATED WITH np = 1429 vertices

First example : Steady conduction

The FreeFem program is Lshape_Steady_parallel.edp. Please check inside this program and compare to its sequential counterpart Lshape_Steady.edp. to see what has been changed.

Note that the program has also been modified to produce a second result file "Partition.txt" allowing to visualize the partition of the mesh

[heatS,Partition] = SF_Launch('Lshape_Steady_parallel.edp','Mesh',ffmesh,'ncores',2,'Datafile',{'Data.txt','Partition.txt'})
figure; SF_Plot(heatS,'T','title','Temperature field')

figure; SF_Plot(Partition,'color','title','Mesh partition')
heatS = 

  struct with fields:

               mesh: [1x1 struct]
           filename: './WORK_parallel/Data.txt'
    DataDescription: 'Temperature in a L-Shape domain'
           datatype: 'HeatSteady'
    datastoragemode: 'ReP2'
    datadescriptors: 'T'
                  T: [5553x1 double]


Partition = 

  struct with fields:

               mesh: [1x1 struct]
           filename: './WORK_parallel/Partition.txt'
    DataDescription: 'Color to display the mesh partition done by buildDmesh '
           datatype: 'EXAMPLE'
    datastoragemode: 'ReP1'
    datadescriptors: 'color'
              color: [1429x1 double]


ans = 

  2x1 graphics array:

  ColorBar
  Patch


ans = 

  2x1 graphics array:

  ColorBar
  Patch

Second example : Navier-Stokes

The program is Lshape_NavierStokes_parallel.edp. Please check inside this program and compare to its sequential counterpart Lshape_NavierStokes.edp. to see what has been changed. Note that despite this program uses vectorial fespace [P2,P2,P1], the modifications are almost identical to those of the previous example !

Flow = SF_Launch('Lshape_NavierStokes_parallel.edp','Mesh',ffmesh,'ncores',2)
figure;SF_Plot(Flow,'ux')


% [[PUBLISH]] -> this tag is here to tell the git runner to automatically generate a web page from this script


%
fclose(fopen('Examples_Lshape_parallel.success','w+'));
Flow = 

  struct with fields:

               mesh: [1x1 struct]
           filename: './WORK_parallel/Data.txt'
    DataDescription: 'Navier-Stokes flow in a L-shaped bottom-driven cavity'
           datatype: 'StokesFlow'
    datastoragemode: 'ReP2P2P1.1'
    datadescriptors: 'ux,uy,p,Re'
                 Re: 1
           INDEXING: [1x1 struct]
                 Fx: -19.0589
          vorticity: [1429x1 double]
                 ux: [16176x1 double]
                 uy: [16176x1 double]
                  p: [8088x1 double]


ans = 

  2x1 graphics array:

  ColorBar
  Patch