Skip to content

Commit

Permalink
improve mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
AStupidBear committed Jun 3, 2020
1 parent 4324eeb commit caf3f96
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name = "GCMAES"
uuid = "4aa9d100-eb0f-11e8-15f1-25748831eb3b"
authors = ["Yao Lu <[email protected]>"]
version = "0.1.9"
version = "0.1.10"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down
2 changes: 1 addition & 1 deletion src/GCMAES.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __precompile__(true)
module GCMAES

using Printf, Distributed, LinearAlgebra
using Dates, Random, Statistics
using Dates, Random, Statistics, Pkg
using Requires, BSON, FastClosures

include("util.jl")
Expand Down
4 changes: 3 additions & 1 deletion src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ macro mpirun(ex)
!inmpi() && return esc(ex)
quote
@eval using MPI
if "Elemental" in keys(Pkg.installed())
@eval using Elemental
end
!MPI.Initialized() && MPI.Init()
MPI.Barrier(MPI.COMM_WORLD)
$(esc(ex))
MPI.Barrier(MPI.COMM_WORLD)
atexit(MPI.Finalize)
end
end

Expand Down
12 changes: 3 additions & 9 deletions test/mpi.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using GCMAES
using Zygote
using MPI
using Elemental
using Test

MPI.Initialized() || MPI.Init()

rastrigin(x) = 10length(x) + sum(x.^2 .- 10 .* cos.(2π .* x))

D = 5000
Expand All @@ -14,10 +10,8 @@ x0 = fill(0.3f0, D)
lo = fill(-5.12f0, D)
hi = fill(5.12f0, D)

GCMAES.minimize(rastrigin, x0, σ0, lo, hi, λ = 200, maxiter = 200)

GCMAES.minimize(rastrigin, x0, σ0, lo, hi, λ = 200, maxiter = 200, autodiff = true)
@mpirun GCMAES.minimize(rastrigin, x0, σ0, lo, hi, λ = 200, maxiter = 200)

rm("CMAES.bson", force = true)
@mpirun GCMAES.minimize(rastrigin, x0, σ0, lo, hi, λ = 200, maxiter = 200, autodiff = true)

MPI.Finalize()
rm("CMAES.bson", force = true)

2 comments on commit caf3f96

@AStupidBear
Copy link
Owner Author

Choose a reason for hiding this comment

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

@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 created: JuliaRegistries/General/15781

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.10 -m "<description of version>" caf3f9654aaa6f8f02e190edfdc4396a6d6da9fa
git push origin v0.1.10

Please sign in to comment.