From 11136adf175c79cc21a3e36eb9ed38698ffdcd2d Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Wed, 17 Feb 2021 13:03:49 +0100 Subject: [PATCH 01/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fcee89..e141827 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ julia> using GridapPETSc If, for any reason, you need to manually build the project, write down the following commands in Julia REPL: ``` pkg> add GridapPETSc -pkg> build GridPETSc +pkg> build GridapPETSc julia> using GridapPETSc ``` From d433db0131e1b6975f21e5554999a3b5d897c300 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 16:28:13 +0100 Subject: [PATCH 02/23] Updated to Gridap 0.15 --- Project.toml | 6 +++--- deps/build.jl | 8 +++----- src/const.jl | 2 +- test/femdriver.jl | 34 ++++++++++++++++++++-------------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Project.toml b/Project.toml index 3a40528..77acef1 100644 --- a/Project.toml +++ b/Project.toml @@ -10,9 +10,9 @@ MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] -Gridap = "0.8.0, 0.9.0, 0.10, 0.11, 0.12, 0.13" -MPI = "0.10.1, 0.13.1, < 0.14.2" -julia = "1" +Gridap = "0.15" +MPI = "0.14, 0.15, 0.16" +julia = "1.3" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/deps/build.jl b/deps/build.jl index 686879a..1a3e537 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -17,7 +17,6 @@ PETSC_SCALAR_DATATYPE = Float64 PETSC_REAL_DATATYPE = Float64 PETSC_INT_DATATYPE = Int32 - # Check PETSC_DIR exists if isdir(PETSC_DIR) @info "PETSc directory found at: $PETSC_DIR" @@ -73,7 +72,7 @@ if isdir(PETSC_DIR) Cint, (Cstring, Ptr{Cint}, - Ptr{UInt32}), + Ptr{UInt32}), name, ptype, found) return ptype[1], convert(Bool, found[1]) end @@ -84,13 +83,13 @@ if isdir(PETSC_DIR) ccall( (:PetscDataTypeGetSize, PETSC), Cint, (Cint, - Ptr{Csize_t}), + Ptr{Csize_t}), dtype, datasize) return datasize[1] end # Define types that depend on the options PETSc was compiled with - (petsc_real_data_type, found_real) = PetscDataTypeFromString("Real") + (petsc_real_data_type, found_real) = PetscDataTypeFromString("Real") (petsc_scalar_data_type, found_scalar) = PetscDataTypeFromString("Scalar") petsc_int_size = PetscDataTypeGetSize(PETSC_INT) @@ -161,4 +160,3 @@ PETSc configuration: - PETSC_REAL_DATATYPE = $PETSC_REAL_DATATYPE - PETSC_INT_DATATYPE = $PETSC_INT_DATATYPE """ - diff --git a/src/const.jl b/src/const.jl index 426d92d..3032726 100644 --- a/src/const.jl +++ b/src/const.jl @@ -9,7 +9,7 @@ const MatFactorType = UInt32 const PETSC_FALSE = (UInt32)(0) const PETSC_TRUE = (UInt32)(1) -const PETSC_INT = (Int32)(0) +const PETSC_INT = (Int32)(16) const PETSC_DOUBLE = (Int32)(1) const PETSC_COMPLEX = (Int32)(2) const PETSC_LONG = (Int32)(3) diff --git a/test/femdriver.jl b/test/femdriver.jl index 09cba54..40ca249 100644 --- a/test/femdriver.jl +++ b/test/femdriver.jl @@ -6,24 +6,30 @@ using GridapPETSc tol = 1e-10 -GridapPETSc.Init(["-ksp_rtol","$tol"]) +GridapPETSc.Init(["-ksp_rtol","$tol"]) -model = CartesianDiscreteModel((0,1,0,1,0,1), (10,10,10)) - -V = TestFESpace(reffe=:Lagrangian, order=1, valuetype=Float64, - conformity=:H1, model=model, dirichlet_tags="boundary") +domain = (0,1,0,1,0,1) +cells = (10,10,10) +model = CartesianDiscreteModel(domain,cells) +order = 1 +V = TestFESpace( model, + ReferenceFE(lagrangian,Float64,order), + conformity=:H1, dirichlet_tags="boundary" ) U = TrialFESpace(V) -trian = get_triangulation(model) -quad = CellQuadrature(trian,2) +Ω = Triangulation(model) + +degree = 2*order +dΩ = Measure(Ω,degree) + +f(x) = x[1]*x[2] -t_Ω = AffineFETerm( - (v,u) -> inner(∇(v),∇(u)), - (v) -> inner(v, (x) -> x[1]*x[2] ), - trian, quad) +a(u,v) = ∫( ∇(v)⋅∇(u) )*dΩ +l(v) = ∫( v*f )*dΩ -op = AffineFEOperator(SparseMatrixCSR{0,PetscReal,PetscInt},U,V,t_Ω) +ass = SparseMatrixAssembler(SparseMatrixCSR{0,PetscReal,PetscInt},U,V) +op = AffineFEOperator(a,l,ass) ls = PETScSolver() solver = LinearFESolver(ls) @@ -31,8 +37,8 @@ solver = LinearFESolver(ls) uh = solve(solver,op) x = get_free_values(uh) -A = op.op.matrix -b = op.op.vector +A = get_matrix(op) +b = get_vector(op) r = A*x - b @test maximum(abs.(r)) < tol From 6bf3040d271e1fb11401dfc8d596f3f47132d4b2 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:04:52 +0100 Subject: [PATCH 03/23] Switching to GH Actions --- .github/workflows/CompatHelper.yml | 3 +- .github/workflows/TagBot.yml | 8 +++-- .github/workflows/ci.yml | 54 ++++++++++++++++++++++++++++++ .github/workflows/ci_x86.yml | 39 +++++++++++++++++++++ .travis.yml | 37 -------------------- 5 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/ci_x86.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index ce8d353..47a84d4 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -1,9 +1,8 @@ name: CompatHelper - on: schedule: - cron: '00 00 * * *' - + workflow_dispatch: jobs: CompatHelper: runs-on: ubuntu-latest diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index d77d3a0..f49313b 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -1,11 +1,15 @@ name: TagBot on: - schedule: - - cron: 0 * * * * + issue_comment: + types: + - created + workflow_dispatch: jobs: TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' runs-on: ubuntu-latest steps: - uses: JuliaRegistries/TagBot@v1 with: token: ${{ secrets.GITHUB_TOKEN }} + ssh: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8ef181d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,54 @@ +name: CI +on: [push, pull_request] +jobs: + test: + name: Tests ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.5' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v1 + with: + file: lcov.info + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: '1.5' + - run: | + julia --project=docs -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate()' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} \ No newline at end of file diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml new file mode 100644 index 0000000..864320e --- /dev/null +++ b/.github/workflows/ci_x86.yml @@ -0,0 +1,39 @@ +name: CI_X86 +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + test: + name: Tests ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.5' + os: + - ubuntu-latest + arch: + - x86 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 70e9229..0000000 --- a/.travis.yml +++ /dev/null @@ -1,37 +0,0 @@ -# Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux -julia: - - 1.0 - - 1.3 - - nightly -addons: - apt: - update: true - packages: - - openmpi-bin - - petsc-dev -matrix: - allow_failures: - - julia: nightly - fast_finish: true -notifications: - email: false -before_script: - - export JULIA_MPI_BINARY="system" -after_success: - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' -jobs: - allow_failures: - - julia: nightly - include: - - stage: Documentation - julia: 1.1 - script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate(); - Pkg.build(); - include("docs/make.jl");' - after_success: skip From e66524b3a8d3cce4e0449afd447ff95c381d12c5 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:17:37 +0100 Subject: [PATCH 04/23] Install dependencies --- .github/workflows/ci.yml | 3 +++ .github/workflows/ci_x86.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ef181d..0ea4e57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,9 @@ jobs: arch: - x64 steps: + - name: Install dependencies + run: sudo apt-get update + run: sudo apt-get openmpi petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 864320e..2373a43 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -20,6 +20,9 @@ jobs: arch: - x86 steps: + - name: Install dependencies + run: sudo apt-get update + run: sudo apt-get openmpi petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: From 4f7f06725a1fd933c3d0cd31697e71d7b1e6eca8 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:20:33 +0100 Subject: [PATCH 05/23] Fixing install dependencies command --- .github/workflows/ci.yml | 3 +-- .github/workflows/ci_x86.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ea4e57..95c70bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,7 @@ jobs: - x64 steps: - name: Install dependencies - run: sudo apt-get update - run: sudo apt-get openmpi petsc-dev + run: sudo apt-get update; sudo apt-get openmpi petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 2373a43..dbf9811 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -21,8 +21,7 @@ jobs: - x86 steps: - name: Install dependencies - run: sudo apt-get update - run: sudo apt-get openmpi petsc-dev + run: sudo apt-get update; sudo apt-get openmpi petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: From fd72772ba09ecbcd5b265bc325f1c69dc9693854 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:22:05 +0100 Subject: [PATCH 06/23] Fixing install deps command --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_x86.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95c70bb..1cf5923 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - x64 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get openmpi petsc-dev + run: sudo apt-get update; sudo apt-get install openmpi petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index dbf9811..030ca90 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -21,7 +21,7 @@ jobs: - x86 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get openmpi petsc-dev + run: sudo apt-get update; sudo apt-get install openmpi petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: From 54634f499c914e4f52f970fc1228e1760a587f5d Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:26:28 +0100 Subject: [PATCH 07/23] Fixed wrong openmpi package name --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_x86.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1cf5923..157e737 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - x64 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get install openmpi petsc-dev + run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 030ca90..2f97d7a 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -21,7 +21,7 @@ jobs: - x86 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get install openmpi petsc-dev + run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: From 49a30d15d4007e2c43a8f225c603c694ed057dd3 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:34:24 +0100 Subject: [PATCH 08/23] Debian petsc-dev is version 3.7.7 --- src/const.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/const.jl b/src/const.jl index 3032726..426d92d 100644 --- a/src/const.jl +++ b/src/const.jl @@ -9,7 +9,7 @@ const MatFactorType = UInt32 const PETSC_FALSE = (UInt32)(0) const PETSC_TRUE = (UInt32)(1) -const PETSC_INT = (Int32)(16) +const PETSC_INT = (Int32)(0) const PETSC_DOUBLE = (Int32)(1) const PETSC_COMPLEX = (Int32)(2) const PETSC_LONG = (Int32)(3) From 0444307f1007f19a138a7e068e48655f65452da6 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 17:38:01 +0100 Subject: [PATCH 09/23] Add environment variable to build MPI.jl --- .github/workflows/ci.yml | 2 ++ .github/workflows/ci_x86.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 157e737..68401a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: ${{ runner.os }}-test- ${{ runner.os }}- - uses: julia-actions/julia-buildpkg@v1 + env: + JULIA_MPI_BINARY: system - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 2f97d7a..3486e62 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -38,4 +38,6 @@ jobs: ${{ runner.os }}-test- ${{ runner.os }}- - uses: julia-actions/julia-buildpkg@v1 + env: + JULIA_MPI_BINARY: system - uses: julia-actions/julia-runtest@v1 \ No newline at end of file From 02a000265bde4049d177ff01e503bfe480a575e4 Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 18:11:30 +0100 Subject: [PATCH 10/23] Do not rely on PetscDataType enum constants, they differ across 3.X versions --- deps/build.jl | 11 +++++++---- src/const.jl | 14 -------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 1a3e537..47bf960 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -91,16 +91,19 @@ if isdir(PETSC_DIR) # Define types that depend on the options PETSc was compiled with (petsc_real_data_type, found_real) = PetscDataTypeFromString("Real") (petsc_scalar_data_type, found_scalar) = PetscDataTypeFromString("Scalar") - petsc_int_size = PetscDataTypeGetSize(PETSC_INT) + (petsc_int_data_type, found_int) = PetscDataTypeFromString("Int") - @assert(found_real & found_scalar) + petsc_real_size = PetscDataTypeGetSize(petsc_real_data_type) + petsc_int_size = PetscDataTypeGetSize(petsc_int_data_type) + + @assert(found_real & found_scalar & found_int) petsc_scalar_data_type != petsc_real_data_type && throw(ErrorException("[ERROR] Only Real PetscScalar type is supported")) # Figure out equivalent Julia types for PETSc - if petsc_real_data_type == PETSC_DOUBLE + if petsc_real_size == 8 PETSC_SCALAR_DATATYPE = PETSC_REAL_DATATYPE = Float64 - elseif petsc_real_data_type == PETSC_FLOAT + elseif petsc_real_size == 4 PETSC_SCALAR_DATATYPE = PETSC_REAL_DATATYPE = Float32 else @warn "Unknown type of Real. Petsc real data type is $petsc_real_data_type" diff --git a/src/const.jl b/src/const.jl index 426d92d..79c92db 100644 --- a/src/const.jl +++ b/src/const.jl @@ -9,20 +9,6 @@ const MatFactorType = UInt32 const PETSC_FALSE = (UInt32)(0) const PETSC_TRUE = (UInt32)(1) -const PETSC_INT = (Int32)(0) -const PETSC_DOUBLE = (Int32)(1) -const PETSC_COMPLEX = (Int32)(2) -const PETSC_LONG = (Int32)(3) -const PETSC_SHORT = (Int32)(4) -const PETSC_FLOAT = (Int32)(5) -const PETSC_CHAR = (Int32)(6) -const PETSC_BIT_LOGICAL = (Int32)(7) -const PETSC_ENUM = (Int32)(8) -const PETSC_BOOL = (Int32)(9) -const PETSC_FLOAT128 = (Int32)(10) -const PETSC_OBJECT = (Int32)(11) -const PETSC_FUNCTION = (Int32)(12) -const PETSC_STRING = (Int32)(12) const MAT_FACTOR_NONE = (UInt32)(0) const MAT_FACTOR_LU = (UInt32)(1) From d5063e1abc68da5dc411247626a2514f57c1284d Mon Sep 17 00:00:00 2001 From: eneiva Date: Wed, 17 Feb 2021 18:27:56 +0100 Subject: [PATCH 11/23] Build package to generate Docs --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68401a0..c4ad1d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,8 @@ jobs: julia --project=docs -e ' using Pkg Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' + Pkg.instantiate() + Pkg.build()' - run: julia --project=docs docs/make.jl env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 21cc2597a17c6bc824836c45d6086c103f22128e Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Wed, 17 Feb 2021 18:57:28 +0100 Subject: [PATCH 12/23] Update README.md --- README.md | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e141827..9122cef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://gridap.github.io/GridapPETSc.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://gridap.github.io/GridapPETSc.jl/dev) -[![Build Status](https://travis-ci.com/gridap/GridapPETSc.jl.svg?branch=master)](https://travis-ci.com/gridap/GridapPETSc.jl) +[![Build Status](https://github.com/gridap/GridapPETSc.jl/workflows/CI/badge.svg?branch=master)](https://github.com/gridap/GridapPETSc.jl/actions?query=workflow%3ACI) [![Codecov](https://codecov.io/gh/gridap/GridapPETSc.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/gridap/GridapPETSc.jl) [Gridap](https://github.com/gridap/Gridap.jl) (Grid-based approximation of partial differential equations in Julia) plugin to use PETSC ([Portable, Extensible Toolkit for Scientific Computation](https://www.mcs.anl.gov/petsc/)). @@ -12,7 +12,8 @@ ```julia using MPI using Gridap -using GridapPETSC +using GridapPETSc +using SparseArrays MPI.Init() GridapPETSc.Init() @@ -32,31 +33,37 @@ MPI.Finalize() ## Usage in a Finite Element computation ```julia +using MPI using Gridap using GridapPETSc +tol = 1e-10 + MPI.Init() -GridapPETSc.Init() +GridapPETSc.Init(["-ksp_rtol","$tol"]) -# Define the FE problem -# -Δu = x*y in (0,1)^3, u = 0 on the boundary. +domain = (0,1,0,1,0,1) +cells = (10,10,10) +model = CartesianDiscreteModel(domain,cells) -model = CartesianDiscreteModel((0,1,0,1,0,1), (10,10,10)) +order = 1 +V = TestFESpace( model, + ReferenceFE(lagrangian,Float64,order), + conformity=:H1, dirichlet_tags="boundary" ) +U = TrialFESpace(V) -V = TestFESpace(reffe=:Lagrangian, order=1, valuetype=Float64, - conformity=:H1, model=model, dirichlet_tags="boundary") +Ω = Triangulation(model) -U = TrialFESpace(V) +degree = 2*order +dΩ = Measure(Ω,degree) -trian = get_triangulation(model) -quad = CellQuadrature(trian,2) +f(x) = x[1]*x[2] -t_Ω = AffineFETerm( - (u,v) -> inner(∇(v),∇(u)), - (v) -> inner(v, (x) -> x[1]*x[2] ), - trian, quad) +a(u,v) = ∫( ∇(v)⋅∇(u) )*dΩ +l(v) = ∫( v*f )*dΩ -op = AffineFEOperator(SparseMatrixCSR{0,PetscReal,PetscInt},U,V,t_Ω) +ass = SparseMatrixAssembler(SparseMatrixCSR{0,PetscReal,PetscInt},U,V) +op = AffineFEOperator(a,l,ass) ls = PETScSolver() solver = LinearFESolver(ls) @@ -71,7 +78,7 @@ MPI.Finalize() **GridPETSc** itself is installed when you add and use it into another project. -Please, ensure that your system fulfill the requirements. +Please, ensure that your system fulfills the requirements. To include into your project form Julia REPL, use the following commands: @@ -108,7 +115,7 @@ Basic `PETSc` installation in order to use it from `GridapPETSc` julia package i ``` $ sudo apt-get update -$ sudo apt-get openmpi petsc-dev +$ sudo apt-get install openmpi-bin petsc-dev ``` ## Continuous integration @@ -126,6 +133,14 @@ addons: - petsc-dev ``` +If your CI process is based on `GitHub Actions` you can add the following block at the beginning of the test steps in the `.github/workflows/ci.yml` file: + +``` +steps: + - name: Install dependencies + run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev +``` + ## Notes `GridapPETSc` default sparse matrix format is 0-based compressed sparse row. This types of sparse matrix can be described by `SparseMatrixCSR{0,PetscReal,PetscInt}` and `SymSparseMatrixCSR{0,PetscReal,PetscInt}`.These types of matrix are implemented in the [SparseMatricesCSR](https://gridap.github.io/SparseMatricesCSR.jl/stable/)) julia package. From 19f8e92c6b78589966c9c8a0e2d428457d7f9602 Mon Sep 17 00:00:00 2001 From: eneiva Date: Thu, 18 Feb 2021 07:47:31 +0100 Subject: [PATCH 13/23] Downgrade CI tests to Ubuntu 18.04 --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_x86.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4ad1d5..3db26b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: version: - '1.5' os: - - ubuntu-latest + - ubuntu-18.04 arch: - x64 steps: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 3486e62..69a953b 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -16,7 +16,7 @@ jobs: version: - '1.5' os: - - ubuntu-latest + - ubuntu-18.04 arch: - x86 steps: From f7c0585c1abf3d1e19f8c7413c8f71555a63fd93 Mon Sep 17 00:00:00 2001 From: eneiva Date: Thu, 18 Feb 2021 16:36:45 +0100 Subject: [PATCH 14/23] Install missing lib to pass tests in Ubuntu 20.04 --- .github/workflows/ci.yml | 5 +++-- .github/workflows/ci_x86.yml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3db26b9..03737c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,12 @@ jobs: version: - '1.5' os: - - ubuntu-18.04 + - ubuntu-latest arch: - x64 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev + run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev libstdc++6 - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: @@ -34,6 +34,7 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system + JULIA_MPI_PATH: /usr/local - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 69a953b..00bff1c 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -16,7 +16,7 @@ jobs: version: - '1.5' os: - - ubuntu-18.04 + - ubuntu-latest arch: - x86 steps: @@ -40,4 +40,5 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system + JULIA_MPI_PATH: /usr/local - uses: julia-actions/julia-runtest@v1 \ No newline at end of file From beb743360c26bdf5810727aad4c3a4113a052b18 Mon Sep 17 00:00:00 2001 From: eneiva Date: Thu, 18 Feb 2021 16:55:47 +0100 Subject: [PATCH 15/23] Revert "Install missing lib to pass tests in Ubuntu 20.04" This reverts commit f7c0585c1abf3d1e19f8c7413c8f71555a63fd93. --- .github/workflows/ci.yml | 5 ++--- .github/workflows/ci_x86.yml | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03737c9..3db26b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,12 @@ jobs: version: - '1.5' os: - - ubuntu-latest + - ubuntu-18.04 arch: - x64 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev libstdc++6 + run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: @@ -34,7 +34,6 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system - JULIA_MPI_PATH: /usr/local - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 00bff1c..69a953b 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -16,7 +16,7 @@ jobs: version: - '1.5' os: - - ubuntu-latest + - ubuntu-18.04 arch: - x86 steps: @@ -40,5 +40,4 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system - JULIA_MPI_PATH: /usr/local - uses: julia-actions/julia-runtest@v1 \ No newline at end of file From cd73c310e992b7c85f2261d4af7a08d0e4d6fae3 Mon Sep 17 00:00:00 2001 From: eneiva Date: Thu, 18 Feb 2021 16:55:57 +0100 Subject: [PATCH 16/23] Revert "Downgrade CI tests to Ubuntu 18.04" This reverts commit 19f8e92c6b78589966c9c8a0e2d428457d7f9602. --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_x86.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3db26b9..c4ad1d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: version: - '1.5' os: - - ubuntu-18.04 + - ubuntu-latest arch: - x64 steps: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 69a953b..3486e62 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -16,7 +16,7 @@ jobs: version: - '1.5' os: - - ubuntu-18.04 + - ubuntu-latest arch: - x86 steps: From f96d989ab087bf90062bdc535d5e1f232a58c1ee Mon Sep 17 00:00:00 2001 From: eneiva Date: Thu, 18 Feb 2021 18:56:37 +0100 Subject: [PATCH 17/23] Support to use GAMG on SeqAIJ matrices --- src/GridapPETSc.jl | 27 +----------- src/LinearSolver.jl | 33 +++++++------- src/load.jl | 3 +- src/mat.jl | 104 ++++++++++++++++++++++++++++++++++---------- test/PETSc.jl | 7 ++- test/femdriver.jl | 20 ++++++++- test/runtests.jl | 6 +-- 7 files changed, 124 insertions(+), 76 deletions(-) diff --git a/src/GridapPETSc.jl b/src/GridapPETSc.jl index abf28fd..c575f13 100644 --- a/src/GridapPETSc.jl +++ b/src/GridapPETSc.jl @@ -11,37 +11,12 @@ import Gridap.Algebra: symbolic_setup, SymbolicSetup import Gridap.Algebra: numerical_setup, numerical_setup!, NumericalSetup import Gridap.Algebra: solve, solve! -# Supported PETSc data types +# Supported PETSc data types export PetscInt export PetscReal export PetscScalar -# Mat -#export MatCreateSeqBAIJWithArrays! -#export MatCreateSeqBAIJWithArrays -#export MatCreateSeqSBAIJWithArrays! -#export MatCreateSeqSBAIJWithArrays -#export MatDestroy! -#export MatView - -# Vec -#export VecCreateSeqWithArray! -#export VecCreateSeqWithArray -#export VecDestroy! -#export VecView - -# KSP -#export KSPCreate! -#export KSPCreate -#export KSPSetOperators! -#export KSPSolve! -#export KSPSolveTranspose! -#export KSPDestroy! - # GridapPETSc datatypes -#export PetscMat -#export PetscVec -#export PetscKSP export PETScSolver export PETScSymbolicSetup export PETScNumericalSetup diff --git a/src/LinearSolver.jl b/src/LinearSolver.jl index 8de6894..95b666e 100644 --- a/src/LinearSolver.jl +++ b/src/LinearSolver.jl @@ -10,7 +10,7 @@ end PETScSolver() = PETScSolver(MPI.COMM_SELF) -struct PETScSymbolicSetup <: SymbolicSetup +struct PETScSymbolicSetup <: SymbolicSetup solver :: PETScSolver end @@ -20,15 +20,15 @@ struct PETScNumericalSetup <: NumericalSetup end function symbolic_setup( - ps::PETScSolver, + ps::PETScSolver, mat::AbstractSparseMatrix) return PETScSymbolicSetup(ps) end function numerical_setup!( - pns::PETScNumericalSetup, + pns::PETScNumericalSetup, mat::PetscMat) - if pns.mat.mat[] != mat.mat[] + if pns.mat.mat[] != mat.mat[] error = MatDestroy!(pns.mat) @assert iszero(error) pns.mat.mat[] = mat.mat[] @@ -43,7 +43,7 @@ function numerical_setup!( end function numerical_setup!( - pns::PETScNumericalSetup, + pns::PETScNumericalSetup, mat::AbstractSparseMatrix) GridapPETSC_mat_type = SparseMatrixCSR{0,PetscScalar,PetscInt} mat_type = typeof(mat) @@ -56,15 +56,15 @@ Converting $mat_type to $GridapPETSC_mat_type... end function numerical_setup!( - pns::PETScNumericalSetup, + pns::PETScNumericalSetup, mat::SparseMatrixCSR{0,PetscScalar,PetscInt}) m, n = size(mat) - Mat = MatCreateSeqBAIJWithArrays(MPI.COMM_SELF, 1, m, n, getptr(mat), getindices(mat), nonzeros(mat)) + Mat = MatCreateSeqAIJWithArrays(MPI.COMM_SELF, m, n, getptr(mat), getindices(mat), nonzeros(mat)) return numerical_setup!(pns, Mat) end function numerical_setup!( - pns::PETScNumericalSetup, + pns::PETScNumericalSetup, mat::SymSparseMatrixCSR{1}) GridapPETSC_mat_type = SymSparseMatrixCSR{0,PetscScalar,PetscInt} mat_type = typeof(mat) @@ -77,7 +77,7 @@ Converting $mat_type to $GridapPETSC_mat_type... end function numerical_setup!( - pns::PETScNumericalSetup, + pns::PETScNumericalSetup, mat::SymSparseMatrixCSR{0,PetscScalar,PetscInt}) m, n = size(mat) Mat = MatCreateSeqSBAIJWithArrays(MPI.COMM_SELF, 1, m, n, getptr(mat), getindices(mat), nonzeros(mat)) @@ -85,7 +85,7 @@ function numerical_setup!( end function numerical_setup( - pss::PETScSymbolicSetup, + pss::PETScSymbolicSetup, mat::AbstractSparseMatrix) GridapPETSC_mat_type = SparseMatrixCSR{0,PetscScalar,PetscInt} mat_type = typeof(mat) @@ -98,15 +98,15 @@ Converting $mat_type to $GridapPETSC_mat_type... end function numerical_setup( - pss::PETScSymbolicSetup, + pss::PETScSymbolicSetup, mat::SparseMatrixCSR{0,PetscScalar,PetscInt}) m, n = size(mat) - Mat = MatCreateSeqBAIJWithArrays(MPI.COMM_SELF, 1, m, n, getptr(mat), getindices(mat), nonzeros(mat)) + Mat = MatCreateSeqAIJWithArrays(MPI.COMM_SELF, m, n, getptr(mat), getindices(mat), nonzeros(mat)) return numerical_setup!(PETScNumericalSetup(Mat, pss.solver), Mat) end function numerical_setup( - pss::PETScSymbolicSetup, + pss::PETScSymbolicSetup, mat::SymSparseMatrixCSR{1}) GridapPETSC_mat_type = SymSparseMatrixCSR{0,PetscScalar,PetscInt} mat_type = typeof(mat) @@ -119,7 +119,7 @@ Converting $mat_type to $GridapPETSC_mat_type. end function numerical_setup( - pss::PETScSymbolicSetup, + pss::PETScSymbolicSetup, mat::SymSparseMatrixCSR{0,PetscScalar,PetscInt}) m, n = size(mat) Mat = MatCreateSeqSBAIJWithArrays(MPI.COMM_SELF, 1, m, n, getptr(mat), getindices(mat), nonzeros(mat)) @@ -127,8 +127,8 @@ function numerical_setup( end function solve!( - x::Vector{PetscScalar}, - ns::PETScNumericalSetup, + x::Vector{PetscScalar}, + ns::PETScNumericalSetup, b::Vector{PetscScalar}) B = VecCreateSeqWithArray(MPI.COMM_SELF, 1, length(b), b) X = VecCreateSeqWithArray(MPI.COMM_SELF, 1, length(x), x) @@ -139,4 +139,3 @@ function solve!( error = VecDestroy!(X) @assert iszero(error) end - diff --git a/src/load.jl b/src/load.jl index 6c2af67..b61f9bf 100644 --- a/src/load.jl +++ b/src/load.jl @@ -14,6 +14,7 @@ const PetscFinalized_ptr = Ref{Ptr}() const VecCreateSeqWithArray_ptr = Ref{Ptr}() const VecDestroy_ptr = Ref{Ptr}() const VecView_ptr = Ref{Ptr}() +const MatCreateSeqAIJWithArrays_ptr = Ref{Ptr}() const MatCreateSeqBAIJWithArrays_ptr = Ref{Ptr}() const MatCreateSeqSBAIJWithArrays_ptr = Ref{Ptr}() const MatGetSize_ptr = Ref{Ptr}() @@ -45,6 +46,7 @@ function __init__() GridapPETSc.VecDestroy_ptr[] = Libdl.dlsym(PETSC,:VecDestroy) GridapPETSc.VecView_ptr[] = Libdl.dlsym(PETSC,:VecView) # Mat + GridapPETSc.MatCreateSeqAIJWithArrays_ptr[] = Libdl.dlsym(PETSC,:MatCreateSeqAIJWithArrays) GridapPETSc.MatCreateSeqBAIJWithArrays_ptr[] = Libdl.dlsym(PETSC,:MatCreateSeqBAIJWithArrays) GridapPETSc.MatCreateSeqSBAIJWithArrays_ptr[] = Libdl.dlsym(PETSC,:MatCreateSeqSBAIJWithArrays) GridapPETSc.MatGetSize_ptr[] = Libdl.dlsym(PETSC,:MatGetSize) @@ -77,4 +79,3 @@ end const PetscScalar = PETSC_SCALAR_DATATYPE const PetscReal = PETSC_REAL_DATATYPE const PetscInt = PETSC_INT_DATATYPE - diff --git a/src/mat.jl b/src/mat.jl index eb1d431..27a79cc 100644 --- a/src/mat.jl +++ b/src/mat.jl @@ -1,5 +1,5 @@ -struct PetscMat +struct PetscMat mat::Ref{Ptr{Cvoid}} function PetscMat() mat = Ref{Ptr{Cvoid}}() @@ -7,6 +7,67 @@ struct PetscMat end end +""" + function MatCreateSeqAIJWithArrays!( + comm::MPI.Comm, + m::Int, + n::Int, + i::Vector{PetscInt}, + j::Vector{PetscInt}, + a::Vector{PetscScalar}, + mat::PetscMat) + +Creates a sequential AIJ matrix using matrix elements +(in CSR format) provided by the user. +""" +function MatCreateSeqAIJWithArrays!( + comm::MPI.Comm, + m::Int, + n::Int, + i::Vector{PetscInt}, + j::Vector{PetscInt}, + a::Vector{PetscScalar}, + mat::PetscMat) + @check_if_loaded + @check_if_initialized + error = ccall( MatCreateSeqAIJWithArrays_ptr[], + PetscErrorCode, + (MPI.Comm, + PetscInt, + PetscInt, + Ptr{PetscInt}, + Ptr{PetscInt}, + Ptr{PetscScalar}, + Ptr{Cvoid}), + comm, m, n, i, j, a, mat.mat) + return error +end + +""" + function MatCreateSeqAIJWithArrays( + comm::MPI.Comm, + m::Int, + n::Int, + i::Vector{PetscInt}, + j::Vector{PetscInt}, + a::Vector{PetscScalar}) + +Returns a sequential AIJ matrix using matrix elements +(in CSR format) provided by the user. +""" +function MatCreateSeqAIJWithArrays( + comm::MPI.Comm, + m::Int, + n::Int, + i::Vector{PetscInt}, + j::Vector{PetscInt}, + a::Vector{PetscScalar}) + Mat = PetscMat() + error = MatCreateSeqAIJWithArrays!(comm, m, n, i, j, a, Mat) + @assert iszero(error) + return Mat +end + """ function MatCreateSeqBAIJWithArrays!( comm::MPI.Comm, @@ -18,8 +79,8 @@ end a::Vector{PetscScalar}, mat::PetscMat) -Creates a sequential block AIJ matrix using matrix elements -(in CSR format) provided by the user. +Creates a sequential block AIJ matrix using matrix elements +(in CSR format) provided by the user. """ function MatCreateSeqBAIJWithArrays!( comm::MPI.Comm, @@ -56,8 +117,8 @@ end j::Vector{PetscInt}, a::Vector{PetscScalar}) -Returns a sequential block AIJ matrix using matrix elements -(in CSR format) provided by the user. +Returns a sequential block AIJ matrix using matrix elements +(in CSR format) provided by the user. """ function MatCreateSeqBAIJWithArrays( comm::MPI.Comm, @@ -84,8 +145,8 @@ end a::Vector{PetscScalar}, mat::PetscMat) -Creates a sequential symmetric block AIJ matrix using -matrix elements (in CSR format) provided by the user. +Creates a sequential symmetric block AIJ matrix using +matrix elements (in CSR format) provided by the user. """ function MatCreateSeqSBAIJWithArrays!( comm::MPI.Comm, @@ -122,8 +183,8 @@ end j::Vector{PetscInt}, a::Vector{PetscScalar}) -Returns a sequential symmetric block AIJ matrix using -matrix elements (in CSR format) provided by the user. +Returns a sequential symmetric block AIJ matrix using +matrix elements (in CSR format) provided by the user. """ function MatCreateSeqSBAIJWithArrays( comm::MPI.Comm, @@ -150,10 +211,10 @@ function MatGetSize(A::PetscMat) m = Vector{PetscInt}(undef,1) n = Vector{PetscInt}(undef,1) error = ccall( MatGetSize_ptr[], - PetscErrorCode, + PetscErrorCode, (Ptr{Cvoid}, Ptr{PetscInt}, - Ptr{PetscInt}), + Ptr{PetscInt}), A.mat[], m, n) @assert iszero(error) return (m[1], n[1]) @@ -169,10 +230,10 @@ function MatEqual(A::PetscMat, B::PetscMat) @check_if_initialized is_equal = Vector{PetscBool}(undef,1) error = ccall( MatEqual_ptr[], - PetscErrorCode, + PetscErrorCode, (Ptr{Cvoid}, Ptr{Cvoid}, - Ptr{PetscBool}), + Ptr{PetscBool}), A.mat[], B.mat[], is_equal) @assert iszero(error) return is_equal[1] == PETSC_TRUE @@ -181,14 +242,14 @@ end """ function MatDestroy!(mat::PetscMat) -Frees space taken by a matrix. +Frees space taken by a matrix. """ function MatDestroy!(mat::PetscMat) @check_if_loaded @check_if_initialized error = ccall( MatDestroy_ptr[], - PetscErrorCode, - (Ptr{Cvoid},), + PetscErrorCode, + (Ptr{Cvoid},), mat.mat) return error end @@ -196,18 +257,15 @@ end """ function MatView(mat::PetscMat, viewer::PetscViewer=C_NULL) -Visualizes a matrix object. +Visualizes a matrix object. """ function MatView(mat::PetscMat, viewer::PetscViewer=C_NULL) @check_if_loaded @check_if_initialized error = ccall( MatView_ptr[], - PetscErrorCode, - (Ptr{Cvoid}, - Ptr{Cvoid}), + PetscErrorCode, + (Ptr{Cvoid}, + Ptr{Cvoid}), mat.mat[], viewer); return error end - - - diff --git a/test/PETSc.jl b/test/PETSc.jl index a43dcab..9e3a832 100644 --- a/test/PETSc.jl +++ b/test/PETSc.jl @@ -10,7 +10,7 @@ tol = 1.0e-13 # Define 0-based CSR sparse matrix data m = 5 n = 5 -I_ = [1,1,1,2,2,3,3,3,4,4,4,5,5] +I_ = [1,1,1,2,2,3,3,3,4,4,4,5,5] J_ = [1,2,4,1,2,3,4,5,1,3,4,2,5] V_ = [1.0,-1,-3,-2,5,4,6,4,-4,2,7,8,-5] I = Vector{GridapPETSc.PetscInt}() @@ -31,12 +31,12 @@ X = ones(GridapPETSc.PetscScalar, n) # PETSc basic workflow ##################################### # Initialization -GridapPETSc.Init(["-info","-malloc_debug","-malloc_dump","-malloc_test","-mat_view", "::ascii_info_detail"]) +GridapPETSc.Init(["-info","-malloc_debug","-malloc_dump","-malloc_test","-mat_view", "::ascii_info_detail"]) # Create objects b = GridapPETSc.VecCreateSeqWithArray(MPI.COMM_SELF, 1, m, B) x = GridapPETSc.VecCreateSeqWithArray(MPI.COMM_SELF, 1, n, X) -Mat = GridapPETSc.MatCreateSeqBAIJWithArrays(MPI.COMM_SELF, 1, m, n, getptr(A), getindices(A), nonzeros(A)) +Mat = GridapPETSc.MatCreateSeqAIJWithArrays(MPI.COMM_SELF, m, n, getptr(A), getindices(A), nonzeros(A)) Ksp = GridapPETSc.KSPCreate(MPI.COMM_SELF) # Show data objects @@ -71,4 +71,3 @@ error = GridapPETSc.VecDestroy!(x) # Finalization GridapPETSc.Finalize() - diff --git a/test/femdriver.jl b/test/femdriver.jl index 40ca249..df020cf 100644 --- a/test/femdriver.jl +++ b/test/femdriver.jl @@ -5,8 +5,24 @@ using Gridap using GridapPETSc tol = 1e-10 - -GridapPETSc.Init(["-ksp_rtol","$tol"]) +maxits = 1000 +GridapPETSc.Init(["-ksp_type", "cg", + "-ksp_monitor", + "-ksp_rtol", "$tol", + "-ksp_converged_reason", + "-ksp_max_it", "$maxits", + "-ksp_norm_type", "unpreconditioned", + "-ksp_view", + "-pc_type","gamg", + "-pc_gamg_type","agg", + "-pc_gamg_est_ksp_type","cg", + "-mg_levels_esteig_ksp_type","cg", + "-mg_coarse_sub_pc_type","cholesky", + "-mg_coarse_sub_pc_factor_mat_ordering_type","nd", + "-pc_gamg_process_eq_limit","50", + "-pc_gamg_square_graph","0", + "-pc_gamg_agg_nsmooths","1", + "-build_twosided","redscatter"]) domain = (0,1,0,1,0,1) cells = (10,10,10) diff --git a/test/runtests.jl b/test/runtests.jl index 9647507..5f63df0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,8 +8,8 @@ if GridapPETSc.PETSC_LOADED[] MPI.Init() end - @testset "PETSc tests" begin include("PETSc.jl") end - @testset "Linear Solver tests" begin include("LinearSolver.jl") end + # @testset "PETSc tests" begin include("PETSc.jl") end + # @testset "Linear Solver tests" begin include("LinearSolver.jl") end @testset "FEM driver" begin include("femdriver.jl") end if MPI.Initialized() & !MPI.Finalized() @@ -17,7 +17,7 @@ if GridapPETSc.PETSC_LOADED[] end else @warn """ - PETSc library is not properly loaded. + PETSc library is not properly loaded. GridapPETSc tests are not going to be performed. """ end From 3bbcc5b48afa22c42dde9c38fabbd9f2795f5ade Mon Sep 17 00:00:00 2001 From: eneiva Date: Mon, 22 Feb 2021 18:00:56 +0100 Subject: [PATCH 18/23] Implemented PETSc_get_number_of_iterations --- src/GridapPETSc.jl | 2 ++ src/LinearSolver.jl | 5 ++++- src/ksp.jl | 27 +++++++++++++++++++++------ src/load.jl | 2 ++ test/femdriver.jl | 7 ++++--- test/runtests.jl | 4 ++-- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/GridapPETSc.jl b/src/GridapPETSc.jl index c575f13..1c5efad 100644 --- a/src/GridapPETSc.jl +++ b/src/GridapPETSc.jl @@ -21,6 +21,8 @@ export PETScSolver export PETScSymbolicSetup export PETScNumericalSetup +export PETSc_get_number_of_iterations + include("load.jl") include("const.jl") include("init.jl") diff --git a/src/LinearSolver.jl b/src/LinearSolver.jl index 95b666e..5a7419c 100644 --- a/src/LinearSolver.jl +++ b/src/LinearSolver.jl @@ -9,7 +9,6 @@ end PETScSolver() = PETScSolver(MPI.COMM_SELF) - struct PETScSymbolicSetup <: SymbolicSetup solver :: PETScSolver end @@ -19,6 +18,10 @@ struct PETScNumericalSetup <: NumericalSetup solver :: PETScSolver end +function PETSc_get_number_of_iterations(ps::PETScSolver) + KSPGetIterationNumber!(ps.ksp) +end + function symbolic_setup( ps::PETScSolver, mat::AbstractSparseMatrix) diff --git a/src/ksp.jl b/src/ksp.jl index 18533b4..fc46c31 100644 --- a/src/ksp.jl +++ b/src/ksp.jl @@ -10,7 +10,7 @@ end """ function KSPCreate!(comm::MPI.Comm, ksp::PetscKSP) -Creates the default KSP context. +Creates the default KSP context. """ function KSPCreate!(comm::MPI.Comm, ksp::PetscKSP) @check_if_loaded @@ -26,7 +26,7 @@ end """ function KSPCreate(comm::MPI.Comm) -Returns the default KSP context. +Returns the default KSP context. """ function KSPCreate(comm::MPI.Comm) ksp = PetscKSP() @@ -68,7 +68,7 @@ end """ function KSPSetOperators!(ksp::PetscKSP, A::PetscMat, P:: PetscMat) -Sets the matrix associated with the linear system and a (possibly) different one associated with the preconditioner. +Sets the matrix associated with the linear system and a (possibly) different one associated with the preconditioner. """ function KSPSetOperators!(ksp::PetscKSP, A::PetscMat, P:: PetscMat) @check_if_loaded @@ -85,7 +85,7 @@ end """ function KSPSetOperators!(ksp::PetscKSP, A::PetscMat, P:: PetscMat) -Sets the matrix associated with the linear system and a (possibly) different one associated with the preconditioner. +Sets the matrix associated with the linear system and a (possibly) different one associated with the preconditioner. """ function KSPSetTolerances!(ksp::PetscKSP, rtol::AbstractFloat, abstol::AbstractFloat, dtol::AbstractFloat, maxits::Integer) @check_if_loaded @@ -121,7 +121,7 @@ end """ function KSPSolveTranspose!(arg1::Ptr{Cvoid}, arg2::AbstractArray, arg3::AbstractArray) -Solves the transpose of a linear system. +Solves the transpose of a linear system. """ function KSPSolveTranspose!(arg1::Ptr{Cvoid}, arg2::AbstractArray, arg3::AbstractArray) @check_if_loaded @@ -138,7 +138,7 @@ end """ function KSPDestroy!(ksp::PetscKSP) -Destroys KSP context. +Destroys KSP context. """ function KSPDestroy!(ksp::PetscKSP) @check_if_loaded @@ -150,4 +150,19 @@ function KSPDestroy!(ksp::PetscKSP) return error end +""" + function KSPGetIterationNumber!(ksp::PetscKSP, its::Integer) +Gets the current iteration number; if the KSPSolve() is complete, returns the number of iterations used. +""" +function KSPGetIterationNumber!(ksp::PetscKSP) + @check_if_loaded + @check_if_initialized + its = Vector{PetscInt}(undef,1) + error = ccall( KSPGetIterationNumber_ptr[], + PetscErrorCode, + (Ptr{Cvoid},Ptr{PetscInt}), + ksp.ksp[], its ) + @assert iszero(error) + return its[1] +end diff --git a/src/load.jl b/src/load.jl index b61f9bf..7999898 100644 --- a/src/load.jl +++ b/src/load.jl @@ -29,6 +29,7 @@ const KSPSetUp_ptr = Ref{Ptr}() const KSPSolve_ptr = Ref{Ptr}() const KSPSolveTranspose_ptr = Ref{Ptr}() const KSPDestroy_ptr = Ref{Ptr}() +const KSPGetIterationNumber_ptr = Ref{Ptr}() const PETSC_LOADED = Ref(false) function __init__() @@ -62,6 +63,7 @@ function __init__() GridapPETSc.KSPSolve_ptr[] = Libdl.dlsym(PETSC,:KSPSolve) GridapPETSc.KSPSolveTranspose_ptr[] = Libdl.dlsym(PETSC,:KSPSolveTranspose) GridapPETSc.KSPDestroy_ptr[] = Libdl.dlsym(PETSC,:KSPDestroy) + GridapPETSc.KSPGetIterationNumber_ptr[] = Libdl.dlsym(PETSC,:KSPGetIterationNumber) PETSC_LOADED[] = true end diff --git a/test/femdriver.jl b/test/femdriver.jl index df020cf..17ebb38 100644 --- a/test/femdriver.jl +++ b/test/femdriver.jl @@ -15,14 +15,13 @@ GridapPETSc.Init(["-ksp_type", "cg", "-ksp_view", "-pc_type","gamg", "-pc_gamg_type","agg", - "-pc_gamg_est_ksp_type","cg", + "-pc_gamg_esteig_ksp_type","cg", "-mg_levels_esteig_ksp_type","cg", "-mg_coarse_sub_pc_type","cholesky", "-mg_coarse_sub_pc_factor_mat_ordering_type","nd", "-pc_gamg_process_eq_limit","50", "-pc_gamg_square_graph","0", - "-pc_gamg_agg_nsmooths","1", - "-build_twosided","redscatter"]) + "-pc_gamg_agg_nsmooths","1"]) domain = (0,1,0,1,0,1) cells = (10,10,10) @@ -52,6 +51,8 @@ solver = LinearFESolver(ls) uh = solve(solver,op) +iters = PETSc_get_number_of_iterations(ls) + x = get_free_values(uh) A = get_matrix(op) b = get_vector(op) diff --git a/test/runtests.jl b/test/runtests.jl index 5f63df0..4c5497f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,8 +8,8 @@ if GridapPETSc.PETSC_LOADED[] MPI.Init() end - # @testset "PETSc tests" begin include("PETSc.jl") end - # @testset "Linear Solver tests" begin include("LinearSolver.jl") end + @testset "PETSc tests" begin include("PETSc.jl") end + @testset "Linear Solver tests" begin include("LinearSolver.jl") end @testset "FEM driver" begin include("femdriver.jl") end if MPI.Initialized() & !MPI.Finalized() From 9353cb42c782fc68305528c6af9aed1a5b89d1cb Mon Sep 17 00:00:00 2001 From: eneiva Date: Thu, 18 Feb 2021 07:47:31 +0100 Subject: [PATCH 19/23] Downgrade CI tests to Ubuntu 18.04 --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_x86.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4ad1d5..3db26b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: version: - '1.5' os: - - ubuntu-latest + - ubuntu-18.04 arch: - x64 steps: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 3486e62..69a953b 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -16,7 +16,7 @@ jobs: version: - '1.5' os: - - ubuntu-latest + - ubuntu-18.04 arch: - x86 steps: From 819d48cf0c55c76239ca0c21d3a1d4e7bcdbc94a Mon Sep 17 00:00:00 2001 From: eneiva Date: Tue, 2 Mar 2021 11:02:05 +0100 Subject: [PATCH 20/23] test ci_x86 on push --- .github/workflows/ci_x86.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 69a953b..329bff5 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -1,11 +1,5 @@ name: CI_X86 -on: - push: - branches: - - master - pull_request: - branches: - - master +on: [push, pull_request] jobs: test: name: Tests ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} From 9a5e329e16e9b3989a8245e95b85997af4e8d1b8 Mon Sep 17 00:00:00 2001 From: eneiva Date: Tue, 2 Mar 2021 12:15:49 +0100 Subject: [PATCH 21/23] Tell Ci_X86 workflow where mpi is --- .github/workflows/ci.yml | 1 + .github/workflows/ci_x86.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3db26b9..ad5dd18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system + JULIA_MPI_PATH: /usr - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index 329bff5..f5e2432 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -34,4 +34,5 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system + JULIA_MPI_PATH: /usr - uses: julia-actions/julia-runtest@v1 \ No newline at end of file From 15890079b6d72ec749dc8d8c10907e17244e633a Mon Sep 17 00:00:00 2001 From: eneiva Date: Tue, 2 Mar 2021 13:04:29 +0100 Subject: [PATCH 22/23] Try different MPI lib for Ubuntu 20 --- .github/workflows/ci.yml | 5 ++--- .github/workflows/ci_x86.yml | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad5dd18..72319e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,12 @@ jobs: version: - '1.5' os: - - ubuntu-18.04 + - ubuntu-20.04 arch: - x64 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev + run: sudo apt-get update; sudo apt-get install libopenmpi-dev petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: @@ -34,7 +34,6 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system - JULIA_MPI_PATH: /usr - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml index f5e2432..cadf297 100644 --- a/.github/workflows/ci_x86.yml +++ b/.github/workflows/ci_x86.yml @@ -10,12 +10,12 @@ jobs: version: - '1.5' os: - - ubuntu-18.04 + - ubuntu-20.04 arch: - x86 steps: - name: Install dependencies - run: sudo apt-get update; sudo apt-get install openmpi-bin petsc-dev + run: sudo apt-get update; sudo apt-get install libopenmpi-dev petsc-dev - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: @@ -34,5 +34,4 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 env: JULIA_MPI_BINARY: system - JULIA_MPI_PATH: /usr - uses: julia-actions/julia-runtest@v1 \ No newline at end of file From 178bba8b9d8a5150f100a64a495a8d068b038e34 Mon Sep 17 00:00:00 2001 From: eneiva Date: Tue, 2 Mar 2021 13:25:25 +0100 Subject: [PATCH 23/23] delete ci_x86.yml workflow --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_x86.yml | 37 ------------------------------------ 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 .github/workflows/ci_x86.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72319e1..fd43d18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: version: - '1.5' os: - - ubuntu-20.04 + - ubuntu-18.04 arch: - x64 steps: diff --git a/.github/workflows/ci_x86.yml b/.github/workflows/ci_x86.yml deleted file mode 100644 index cadf297..0000000 --- a/.github/workflows/ci_x86.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: CI_X86 -on: [push, pull_request] -jobs: - test: - name: Tests ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - version: - - '1.5' - os: - - ubuntu-20.04 - arch: - - x86 - steps: - - name: Install dependencies - run: sudo apt-get update; sudo apt-get install libopenmpi-dev petsc-dev - - uses: actions/checkout@v2 - - uses: julia-actions/setup-julia@v1 - with: - version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - uses: actions/cache@v1 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- - - uses: julia-actions/julia-buildpkg@v1 - env: - JULIA_MPI_BINARY: system - - uses: julia-actions/julia-runtest@v1 \ No newline at end of file