-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An example that uses Scatterv
#468
Comments
What version of MPI.jl are you using? using MPI
using Printf
MPI.Init()
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
size = MPI.Comm_size(comm)
N = 10
### Find the split for each rank with a given size
if rank == 0
N_each = cld(N, size)
N_all = fill(N_each, size)
N_all[end] = N - size*N_each
end
RN_local = Ref{Int}()
MPI.Scatter!(rank == 0 ? N_all : nothing, RN_local, 0, comm)
N_local = RN_local[]
### Define a sample array of size N
if rank == 0
k = Float64[i for i in 1:N]
end
k_local = zeros(N_local)
### Scatter Array
MPI.Scatterv!(rank == 0 ? VBuffer(k, N_all) : nothing, k_local, 0, comm)
### Print Array
for i in 1:size
if rank==(i-1)
@printf("rank = %s k_local = %s \n", rank, k_local)
end
end
MPI.Finalize()
Not that I know of, but it is a fairly simple function to write.
Unfortunately there aren't any great solutions here. See #360
I'm not sure what you mean by this, could you expand further, or give an example? |
Also, for these sorts of questions, please ask on Discourse in future. |
Thank you @simonbyrne for the reply, and sorry for not using Discourse for this. I've since discovered where it is and will try that in the future. First, I am using v0.17.2, which I see is the latest version. Second, sorry for using the wrong function and will make sure to use the right functions. I asked for help on the function I was using and it showed the following, in case this is helpful.
Third, thanks for the revised code. I admit that I do find the code puzzling but I guess I need to learn how Fourth, sorry my output was hard to understand. I'll copy it below but parse it differently
If I am reading this correctly then rank 3 has the set of elemnts that follow rank 0, and before rank 1. This is going to be a problem when I gather the elements back together, which I want to do next, since the gathered vector will not be ordered correctly, I think. |
After doing some tests I'm not sure if I was parsing the output correctly. I decided to specify the displacements in the Below had both examples on how to scatter and then gather an array.
|
I think that is just the printing order getting messed up. |
I've put together an example (see below) that builds a vector of length N (=10) and then determines how to split this amoungst the different cores and then does just that.
I have a few questions in hopes of learning how to write better code.
Python
there is a functionnumpy.array_split
that does the splitting for you. Any chanceJulia
has something similar?MPI.jl
?Below is output that maybe shows what I mean about my output being messy and the ordering being a bit odd. It seems that rank 1 has [7, 8], and rank 3 has [4, 5, 6].
Any advice would be greatly appreciated.
Sample output
Code
The text was updated successfully, but these errors were encountered: