Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AStupidBear committed May 12, 2020
1 parent d387308 commit 6daff60
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GCMAES"
uuid = "4aa9d100-eb0f-11e8-15f1-25748831eb3b"
authors = ["Yao Lu <[email protected]>"]
version = "0.1.4"
version = "0.1.5"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down
44 changes: 44 additions & 0 deletions src/util.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export @mpirun

minibatch(x, b) = [x[i:min(end, i + b - 1)] for i in 1:b:max(1, length(x) - b + 1)]

sample(lo, hi) = lo .+ rand(size(lo)) .* (hi .- lo)
Expand Down Expand Up @@ -39,4 +41,46 @@ end

worldsize() = @isdefined(MPI) && nworkers() == 1 ? MPI.Comm_size(MPI.COMM_WORLD) : nworkers()

function processname(pid)
@static if Sys.iswindows()
split(read(`wmic process where processid=$pid get executablepath`, String))[end]
else
strip(read(`ps -p $pid -o comm=`, String))
end
end

function pstree(pid = getpid())
pids = Int[]
while !isnothing(pid)
push!(pids, pid)
pid = getppid(pid)
end
pop!(pids)
return pids
end

function inmpi()
try
@static if Sys.iswindows()
occursin("mpi", join(processname.(pstree())))
else
ps = read(`pstree -s $(getpid())`, String)
occursin("mpi", ps) || occursin("slurm", ps)
end
catch
false
end
end

macro mpirun(ex)
!inmpi() && return esc(ex)
quote
@eval using MPI
!MPI.Initialized() && MPI.Init()
MPI.Barrier(MPI.COMM_WORLD)
$(esc(ex))
MPI.Barrier(MPI.COMM_WORLD)
end
end

deigen(x) = eigen(Symmetric(x, :U))

2 comments on commit 6daff60

@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/14622

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.5 -m "<description of version>" 6daff6074cd091e39cd5e590a9fc6c6487c91b4b
git push origin v0.1.5

Please sign in to comment.