Skip to content

Commit

Permalink
add mpi_id and mpi_nwork
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 2, 2023
1 parent e6df296 commit f56bff5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Ipaper"
uuid = "e58298cb-69f7-4186-aecd-5834b6793426"
authors = ["Dongdong Kong <[email protected]>"]
version = "0.1.11"
version = "0.1.12"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down Expand Up @@ -38,7 +38,7 @@ DocStringExtensions = "0.8, 0.9"
Glob = "1.3"
LambdaFn = "0.3"
MPI = "0.20"
PrecompileTools = "1.1"
PrecompileTools = "1.1, 1.2"
Reexport = "1.2"
Requires = "1.3"
StatsBase = "0.33, 0.34"
Expand Down
19 changes: 14 additions & 5 deletions src/par.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ if !isCurrentWorker(i); continue; end
```
"""
function isCurrentWorker(i = 0)
MPI.Init()
comm = MPI.COMM_WORLD
cluster = MPI.Comm_rank(comm)
ncluster = MPI.Comm_size(comm)
cluster = mpi_id()
ncluster = mpi_nwork()
# @show ncluster, cluster, i
mod(i, ncluster) == cluster
end

function mpi_id()
MPI.Init()
comm = MPI.COMM_WORLD
MPI.Comm_rank(comm) # id
end

function mpi_nwork()
MPI.Init()
comm = MPI.COMM_WORLD
MPI.Comm_size(comm)
end

export @par, get_clusters, isCurrentWorker
export @par, get_clusters, isCurrentWorker, mpi_id, mpi_nwork

0 comments on commit f56bff5

Please sign in to comment.