I am new to julia.
I have a question about MPI parallel computing.
I would like to communicate the matrices in each process as follows.
The code I have created is shown below.
I would like this code to send the matrix in the i-th process to the i-1st and i+1st processes, but so far it is not working.
Thank you in advance for your help.
using StaticArrays
using LinearAlgebra
using MPI
L=500
k_mesh=range(-π, length=L, step=2π / L)
function Hamiltonian(kx,ky)
return @SMatrix[cos(kx) im*sin(ky);-im*sin(ky) cos(kx)]
end
function main()
comm = MPI.COMM_WORLD
myrank = MPI.Comm_rank(comm)
size = MPI.Comm_size(comm)
function start_and_end(N, comm)
nprocs = MPI.Comm_size(comm)
myrank = MPI.Comm_rank(comm)
if N % nprocs != 0
println("エラー! N % プロセス数 は0である必要があります。")
MPI.Abort(comm, 1) # MPIを正しく終了させます
end
nbun = div(N, nprocs)
ista = myrank * nbun + 1
iend = ista + nbun - 1
return ista, iend, nbun
end
dst = mod(myrank+1, size)
src = mod(myrank-1, size)
ista, iend , nbun = start_and_end(L,comm)
k_mesh_i=deepcopy(k_mesh[ista:iend])
Ham_i = Hamiltonian.(k_mesh,k_mesh_i')
Ham_upper=deepcopy(Ham_i[1,:])
Ham_downer=deepcopy(Ham_i[nbun,:])
rreq = MPI.Irecv!(Ham_upper, comm; source=src, tag=src+32)
sreq = MPI.Isend(Ham_downer, comm; dest=dst, tag=myrank+32)
stats = MPI.Waitall([rreq, sreq])
print("$rank: Sending $rank -> $dst = $sreq\n")
print("$rank: Received $src -> $rank = $rreq\n")
end
MPI.Init()
main()
MPI.Finalize()