Skip to content

Commit

Permalink
Merge pull request #11 from gridap/P4est_wrapper
Browse files Browse the repository at this point in the history
P4est wrapper
  • Loading branch information
amartinhuertas authored Sep 21, 2021
2 parents 1579110 + a71d00b commit 268593c
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "p4est_wrapper"
name = "P4est_wrapper"
uuid = "3743d7c0-8adf-11ea-380b-7d33b0ecc1da"
authors = ["Victor Sande <[email protected]>", "Alberto F. Martin <[email protected]>"]
version = "0.1.0"
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# p4est_wrapper
# P4est_wrapper

Julia wrappers for p4est library ([Parallel AMR on Forests of Octrees](http://www.p4est.org/))

[![Build Status](https://github.com/gridap/p4est_wrapper.jl/workflows/CI/badge.svg?branch=master)](https://github.com/gridap/p4est_wrapper.jl/actions)
[![Codecov](https://codecov.io/gh/gridap/p4est_wrapper.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/gridap/p4est_wrapper.jl)
[![Build Status](https://github.com/gridap/P4est_wrapper.jl/workflows/CI/badge.svg?branch=master)](https://github.com/gridap/P4est_wrapper.jl/actions)
[![Codecov](https://codecov.io/gh/gridap/P4est_wrapper.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/gridap/P4est_wrapper.jl)


## Basic Usage

```julia
using MPI
using p4est_wrapper
using P4est_wrapper
using Test

sc_init(MPI.COMM_WORLD, Cint(true), Cint(true), C_NULL, p4est_wrapper.SC_LP_DEFAULT)
p4est_init(C_NULL, p4est_wrapper.SC_LP_DEFAULT)
sc_init(MPI.COMM_WORLD, Cint(true), Cint(true), C_NULL, P4est_wrapper.SC_LP_DEFAULT)
p4est_init(C_NULL, P4est_wrapper.SC_LP_DEFAULT)
unitsquare_connectivity = p4est_connectivity_new_unitsquare()
unitsquare_forest = p4est_new(MPI.COMM_WORLD, unitsquare_connectivity, 0, C_NULL, C_NULL)
...
Expand All @@ -28,38 +28,38 @@ MPI.Finalize()

## Installation

**p4est_wrapper.jl** itself is installed when you add and use it into another project.
**P4est_wrapper.jl** itself is installed when you add and use it into another project.

Please, ensure that your system fulfill the requirements.

To include into your project form Julia REPL, use the following commands:

```
pkg> add p4est_wrapper
julia> using p4est_wrapper
pkg> add P4est_wrapper
julia> using P4est_wrapper
```

If, for any reason, you need to manually build the project, write down the following commands in Julia REPL:
```
pkg> add p4est_wrapper
pkg> build p4est_wrapper
julia> using p4est_wrapper
pkg> add P4est_wrapper
pkg> build P4est_wrapper
julia> using P4est_wrapper
```

### Requirements

- `p4est >= 2.2`
- `MPI`

`p4est_wrapper` julia package requires `p4est` library ([Parallel AMR on Forests of Octrees](http://www.p4est.org/)), and (optionally) `MPI` to work correctly.
`P4est_wrapper` julia package requires `p4est` library ([Parallel AMR on Forests of Octrees](http://www.p4est.org/)), and (optionally) `MPI` to work correctly.
- Latests versions of julia `MPI` use artifacts to locally install a MPI distribution. You should take care with the compatibility (version/vendor/distribution) between the parallel `p4est` and `MPI` libraries. If you want julia `MPI` library to wrap your local MPI library, you must export `JULIA_MPI_BINARY="system"` before installing the package.
- Parallel `p4est` library can be manually installed in a custom path on your local machine. In order to succesfull describe your custom installation to be discovered by `p4est_wrapper`, you must export `P4EST_ROOT_DIR` environment variable pointing to the installation directory. If this environment variable is not available, and `julia >= 1.3`, `p4est_wrapper` will try to use [`P4est_jll` artifact](https://github.com/JuliaBinaryWrappers/P4est_jll.jl), but you should take into account that this artifact is not for parallel computations (MPI not enabled). Finally, in other case `p4est_wrapper` will try to find the `p4est` library in the usual linux user library directory (`/usr/lib`).
- Parallel `p4est` library can be manually installed in a custom path on your local machine. In order to succesfull describe your custom installation to be discovered by `P4est_wrapper`, you must export `P4EST_ROOT_DIR` environment variable pointing to the installation directory. If this environment variable is not available, and `julia >= 1.3`, `P4est_wrapper` will try to use [`P4est_jll` artifact](https://github.com/JuliaBinaryWrappers/P4est_jll.jl), but you should take into account that this artifact is not for parallel computations (MPI not enabled). Finally, in other case `P4est_wrapper` will try to find the `p4est` library in the usual linux user library directory (`/usr/lib`).

#### Basic OpenMPI installation in debian based systems

`MPI` can be obtained from the default repositories of your Debian-based OS by means of `apt` tool.

Basic `MPI` installation in order to use it from `p4est_wrapper` julia package is as follows:
Basic `MPI` installation in order to use it from `P4est_wrapper` julia package is as follows:

```
apt-get update
Expand Down Expand Up @@ -102,8 +102,8 @@ Note: you need the following tools:

## Automated p4est wrapper generator

`p4est_wrapper` bindings are automatically generated by using [Clang](https://github.com/JuliaInterop/Clang.jl) package.
`P4est_wrapper` bindings are automatically generated by using [Clang](https://github.com/JuliaInterop/Clang.jl) package.

To learn more about how it works, please read the README file at [gen directory](https://github.com/gridap/p4est_wrapper.jl/tree/master/gen).
To learn more about how it works, please read the README file at [gen directory](https://github.com/gridap/P4est_wrapper.jl/tree/master/gen).


10 changes: 5 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Documenter, p4est_wrapper
using Documenter, P4est_wrapper

makedocs(;
modules=[p4est_wrapper],
modules=[P4est_wrapper],
format=Documenter.HTML(),
pages=[
"Home" => "index.md",
],
repo="https://github.com/gridap/p4est_wrapper.jl/blob/{commit}{path}#L{line}",
sitename="p4est_wrapper.jl",
repo="https://github.com/gridap/P4est_wrapper.jl/blob/{commit}{path}#L{line}",
sitename="P4est_wrapper.jl",
authors="Víctor Sande <[email protected]>, Large Scale Scientific Computing",
assets=String[],
)

deploydocs(;
repo="github.com/gridap/p4est_wrapper.jl",
repo="github.com/gridap/P4est_wrapper.jl",
)
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# p4est_wrapper.jl
# P4est_wrapper.jl

```@index
```

```@autodocs
Modules = [p4est_wrapper]
Modules = [P4est_wrapper]
```
12 changes: 6 additions & 6 deletions src/p4est_wrapper.jl → src/P4est_wrapper.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module p4est_wrapper
module P4est_wrapper

################################################################
# Check correct installation
################################################################
# Load in `deps.jl`, complaining if it does not exist
const depsjl_path = joinpath(@__DIR__, "..", "deps", "deps.jl")
if !isfile(depsjl_path)
error("p4est_wrapper was not build properly. Please run Pkg.build(\"p4est.jl\").")
error("P4est_wrapper was not build properly. Please run Pkg.build(\"p4est.jl\").")
end
include(depsjl_path)
# Check if p4est library was found
if(!P4EST_FOUND)
error("p4est_wrapper was not build properly. Please run Pkg.build(\"p4est.jl\").")
error("P4est_wrapper was not build properly. Please run Pkg.build(\"p4est.jl\").")
end

# Use library path from build process
const p4est_lib = P4EST_LIB

################################################################
# Use dependencies
# Use dependencies
################################################################
using Libdl
using MPI
Expand All @@ -32,7 +32,7 @@ export Ctm, Ctime_t, Cclock_t

# Include P4EST bindings

# The following file fix and/or complete
# The following file fix and/or complete
# the automated generation of types and data structures
include(joinpath(@__DIR__, "common_fixes.jl"))

Expand All @@ -56,7 +56,7 @@ include(joinpath(@__DIR__, "api_fixes.jl"))
# Export everything starting with ...
################################################################
foreach(names(@__MODULE__, all=true)) do s
if startswith(string(s), "sc") || startswith(string(s), "p4est") || startswith(string(s), "p6est") || startswith(string(s), "p8est")
if startswith(string(s), "sc") || startswith(string(s), "p4est") || startswith(string(s), "p6est") || startswith(string(s), "p8est")
@eval export $s
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/example_1.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MPI
using p4est_wrapper
using P4est_wrapper
using Test

# Initialize MPI if not initialized yet
Expand Down Expand Up @@ -38,17 +38,17 @@ const search_point_fn_c = @cfunction(search_point_fn, Cint, (Ptr{p4est_t}, p4est
# Main program
#############################################################################

mpicomm = p4est_wrapper.P4EST_ENABLE_MPI ? MPI.COMM_WORLD : Cint(0)
mpicomm = P4est_wrapper.P4EST_ENABLE_MPI ? MPI.COMM_WORLD : Cint(0)

# Create a connectivity structure for the unit square.
unitsquare_connectivity = p4est_connectivity_new_unitsquare()
unitsquare_connectivity = p4est_connectivity_new_unitsquare()
@test unitsquare_connectivity != C_NULL

# Create a new forest
unitsquare_forest = p4est_new(mpicomm, unitsquare_connectivity, 0, C_NULL, C_NULL)
unitsquare_forest = p4est_new(mpicomm, unitsquare_connectivity, 0, C_NULL, C_NULL)
@test unitsquare_forest != C_NULL

# Register callback function to decide for refinement.
# Register callback function to decide for refinement.
p4est_refine(unitsquare_forest, 1, my_refine_c, C_NULL)

# Create a new sc_array
Expand All @@ -59,7 +59,7 @@ ptr_to_points_sc_array = sc_array_new_count(sizeof(point_t), 2)
points_sc_array = ptr_to_points_sc_array[]
@test points_sc_array.elem_count == 2 && points_sc_array.elem_size == sizeof(point_t)

# Obtain reference to first point_t
# Obtain reference to first point_t
ptr_to_points_array = Ptr{point_t}(sc_array_index(ptr_to_points_sc_array,0))
@test ptr_to_points_array != C_NULL

Expand Down
16 changes: 8 additions & 8 deletions test/example_2.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MPI
using p4est_wrapper
using P4est_wrapper
using Test

# Initialize MPI if not initialized yet
Expand All @@ -26,24 +26,24 @@ const my_refine_c = @cfunction(my_refine, Cint, (Ptr{p4est_t}, p4est_topidx_t, P
# Main program
#############################################################################

mpicomm = p4est_wrapper.P4EST_ENABLE_MPI ? MPI.COMM_WORLD : Cint(0)
mpicomm = P4est_wrapper.P4EST_ENABLE_MPI ? MPI.COMM_WORLD : Cint(0)

# Create a connectivity structure for the unit square.
unitsquare_connectivity = p4est_connectivity_new_unitsquare()
unitsquare_connectivity = p4est_connectivity_new_unitsquare()
@assert Bool(p4est_connectivity_is_valid(unitsquare_connectivity))

# Create a new forest
unitsquare_forest = p4est_new(mpicomm, unitsquare_connectivity, sizeof(p4est_quadrant_t), C_NULL, C_NULL)
unitsquare_forest = p4est_new(mpicomm, unitsquare_connectivity, sizeof(p4est_quadrant_t), C_NULL, C_NULL)
@test unitsquare_forest != C_NULL

# Register callback function to decide for refinement.
# Register callback function to decide for refinement.
p4est_refine(unitsquare_forest, 1, my_refine_c, C_NULL)

# Equally partition the forest. The partition can be by element count or by a user-defined weight.
p4est_partition(unitsquare_forest, 0, C_NULL);

# Build the ghost layer.
ptr_to_p4est_ghost = p4est_ghost_new(unitsquare_forest, p4est_wrapper.P4EST_CONNECT_FULL)
# Build the ghost layer.
ptr_to_p4est_ghost = p4est_ghost_new(unitsquare_forest, P4est_wrapper.P4EST_CONNECT_FULL)
p4est_ghost = ptr_to_p4est_ghost[]

# Obtain ghost quadrants
Expand All @@ -56,7 +56,7 @@ for i=1:p4est_ghost.mpisize
quadrant = ptr_ghost_quadrants[j+1]
piggy3 = quadrant.p.piggy3
@test Bool(p4est_quadrant_is_valid(ptr_ghost_quadrants+(sizeof(p4est_quadrant_t)*j)))
p4est_quadrant_print(p4est_wrapper.SC_LP_INFO, ptr_ghost_quadrants+(sizeof(p4est_quadrant_t)*j))
p4est_quadrant_print(P4est_wrapper.SC_LP_INFO, ptr_ghost_quadrants+(sizeof(p4est_quadrant_t)*j))
print("(i, j, local_num, which_tree) ($(i),$(j),$(piggy3.local_num),$(piggy3.which_tree)) \n")
end
end
Expand Down
36 changes: 18 additions & 18 deletions test/example_3.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MPI
using p4est_wrapper
using P4est_wrapper
using Test

# Initialize MPI if not initialized yet
Expand Down Expand Up @@ -27,8 +27,8 @@ const coarsen_flag = Cint(2)
# back function to an array of ints with as many entries as forest quadrants. This call back function
# initializes the quadrant->p.user_data void * pointer of all quadrants such that it
# points to the corresponding entry in the global array mentioned in the previous sentence.
function init_fn_callback_2d(forest_ptr::Ptr{p4est_t},
which_tree::p4est_topidx_t,
function init_fn_callback_2d(forest_ptr::Ptr{p4est_t},
which_tree::p4est_topidx_t,
quadrant_ptr::Ptr{p4est_quadrant_t})
@assert which_tree == 0
# Extract a reference to the first (and uniquely allowed) tree
Expand All @@ -45,8 +45,8 @@ end

const init_fn_callback_2d_c = @cfunction(init_fn_callback_2d, Cvoid, (Ptr{p4est_t}, p4est_topidx_t, Ptr{p4est_quadrant_t}))

function refine_callback_2d(::Ptr{p4est_t},
which_tree::p4est_topidx_t,
function refine_callback_2d(::Ptr{p4est_t},
which_tree::p4est_topidx_t,
quadrant_ptr::Ptr{p4est_quadrant_t})
@assert which_tree == 0
quadrant = quadrant_ptr[]
Expand All @@ -58,17 +58,17 @@ const refine_callback_2d_c = @cfunction(refine_callback_2d, Cint, (Ptr{p4est_t},
# For each refined quadrant:
# num_calls is even -> leave untouched all children
# num_calls is odd -> mark all children for coarsening
function refine_replace_callback_2d(forest_ptr::Ptr{p4est_t},
which_tree::p4est_topidx_t,
num_outgoing::Cint,
outgoing_ptr::Ptr{Ptr{p4est_quadrant_t}},
num_incoming::Cint,
function refine_replace_callback_2d(forest_ptr::Ptr{p4est_t},
which_tree::p4est_topidx_t,
num_outgoing::Cint,
outgoing_ptr::Ptr{Ptr{p4est_quadrant_t}},
num_incoming::Cint,
incoming_ptr::Ptr{Ptr{p4est_quadrant_t}})
@assert which_tree == 0
@assert num_outgoing == 1
@assert num_incoming == p4est_wrapper.P4EST_CHILDREN
incoming = unsafe_wrap(Array, incoming_ptr, p4est_wrapper.P4EST_CHILDREN)
for quadrant_index = 1:p4est_wrapper.P4EST_CHILDREN
@assert num_incoming == P4est_wrapper.P4EST_CHILDREN
incoming = unsafe_wrap(Array, incoming_ptr, P4est_wrapper.P4EST_CHILDREN)
for quadrant_index = 1:P4est_wrapper.P4EST_CHILDREN
quadrant = incoming[quadrant_index][]
if (num_calls % 2 == 0)
unsafe_store!(Ptr{Cint}(quadrant.p.user_data), nothing_flag, 1)
Expand All @@ -87,8 +87,8 @@ function coarsen_callback_2d(forest_ptr::Ptr{p4est_t},
quadrants_ptr::Ptr{Ptr{p4est_quadrant_t}})
@assert which_tree == 0
coarsen = Cint(1)
quadrants = unsafe_wrap(Array, quadrants_ptr, p4est_wrapper.P4EST_CHILDREN)
for quadrant_index = 1:p4est_wrapper.P4EST_CHILDREN
quadrants = unsafe_wrap(Array, quadrants_ptr, P4est_wrapper.P4EST_CHILDREN)
for quadrant_index = 1:P4est_wrapper.P4EST_CHILDREN
quadrant = quadrants[quadrant_index][]
coarsen = Cint(unsafe_wrap(Array, Ptr{Cint}(quadrant.p.user_data), 1)[] == coarsen_flag)
if (!Bool(coarsen)) return coarsen end
Expand Down Expand Up @@ -119,9 +119,9 @@ end
# Main program
#############################################################################

mpicomm = p4est_wrapper.P4EST_ENABLE_MPI ? MPI.COMM_WORLD : Cint(0)
sc_init(mpicomm, Cint(true), Cint(true), C_NULL, p4est_wrapper.SC_LP_DEFAULT)
p4est_init(C_NULL, p4est_wrapper.SC_LP_DEFAULT)
mpicomm = P4est_wrapper.P4EST_ENABLE_MPI ? MPI.COMM_WORLD : Cint(0)
sc_init(mpicomm, Cint(true), Cint(true), C_NULL, P4est_wrapper.SC_LP_DEFAULT)
p4est_init(C_NULL, P4est_wrapper.SC_LP_DEFAULT)

unitsquare_connectivity = p4est_connectivity_new_unitsquare()
unitsquare_forest = p4est_new(mpicomm, unitsquare_connectivity, 0, C_NULL, C_NULL)
Expand Down
16 changes: 8 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
using MPI
using p4est_wrapper
using P4est_wrapper
using Test


# Skip tests if library was not properly loaded
if p4est_wrapper.P4EST_FOUND
if P4est_wrapper.P4EST_FOUND


nprocs = min(Sys.CPU_THREADS, 2)
dir = dirname(@__FILE__)
julia = Base.julia_cmd()
mpiexec = MPI.mpiexec_path
@testset "Test SC bindings" begin
@testset "Test SC bindings" begin
cmd = `$mpiexec -n $nprocs --allow-run-as-root --tag-output $(julia) $(joinpath(dir, "test_sc_bindings.jl"))`
@show cmd
run(cmd)
end
@testset "Test P4EST bindings" begin
@testset "Test P4EST bindings" begin
cmd = `$mpiexec -n $nprocs --allow-run-as-root --tag-output $(julia) $(joinpath(dir, "test_p4est_bindings.jl"))`
@show cmd
run(cmd)
end
@testset "Test P8EST bindings" begin
@testset "Test P8EST bindings" begin
cmd = `$mpiexec -n $nprocs --allow-run-as-root --tag-output $(julia) $(joinpath(dir, "test_p8est_bindings.jl"))`
@show cmd
run(cmd)
end
@testset "Example 1" begin
@testset "Example 1" begin
cmd = `$mpiexec -n $nprocs --allow-run-as-root --tag-output $(julia) $(joinpath(dir, "example_1.jl"))`
@show cmd
run(cmd)
end
@testset "Example 2" begin
@testset "Example 2" begin
cmd = `$mpiexec -n $nprocs --allow-run-as-root --tag-output $(julia) $(joinpath(dir, "example_2.jl"))`
@show cmd
run(cmd)
end
@testset "Example 3" begin
@testset "Example 3" begin
cmd = `$mpiexec -n $nprocs --allow-run-as-root --tag-output $(julia) $(joinpath(dir, "example_3.jl"))`
@show cmd
run(cmd)
Expand Down
Loading

2 comments on commit 268593c

@amartinhuertas
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/45264

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 268593cdd609940a23343c92f570c3119500fdc1
git push origin v0.1.0

Please sign in to comment.