nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: JuliaParallel/MPI.jl
Pull request #766 (2023-09-06 20:27:18)

Add non-blocking wait
A first implementation of non-blocking wait as discussed in #762

vchuravy: Should we also add a `MPI.wait(t::Task)`?

```
function wait(task::Task)
    while !Base.istaskdone(task)
        MPI.Iprobe(MPI.MPI_ANY_SOURCE, MPI.MPI_ANY_TAG, MPI.COMM_WORLD)
        yield()
    end
    wait(task)
end
```
luraess: > Should we also add a `MPI.wait(t::Task)`?

If so, should one add it in similar location as the `Base.wait`?
simonbyrne: I think leave that for a separate PR.
simonbyrne: Can you add it to the docs, and add a test?
luraess: > Can you add it to the docs, and add a test?

Done. Feel free to update the docstring @simonbyrne 
luraess: Could this be reviewed and finalised 🙏 ?

Patch:
diff --git a/docs/src/reference/pointtopoint.md b/docs/src/reference/pointtopoint.md
index 64d96bd..8da05d9 100644
--- a/docs/src/reference/pointtopoint.md
+++ b/docs/src/reference/pointtopoint.md
@@ -55,6 +55,7 @@ MPI.Testall
 MPI.Testany
 MPI.Testsome
 MPI.Wait
+Base.wait(req::MPI.Request)
 MPI.Waitall
 MPI.Waitany
 MPI.Waitsome
diff --git a/src/nonblocking.jl b/src/nonblocking.jl
index fef29ea..bfb9da7 100644
--- a/src/nonblocking.jl
+++ b/src/nonblocking.jl
@@ -774,3 +774,14 @@ function Cancel!(req::AbstractRequest)
     API.MPI_Cancel(req)
     nothing
 end
+
+"""
+    Base.wait(req::MPI.Request)
+
+Wait for an MPI request to complete. Unlike [`MPI.Wait`](@ref), it will yield to other Julia tasks resulting in a cooperative wait.
+"""
+function Base.wait(req::MPI.Request)
+    while !MPI.Test(req)
+        yield()
+    end
+end


Test patch:
diff --git a/test/test_cooperative_wait.jl b/test/test_cooperative_wait.jl
new file mode 100644
index 0000000..3219305
--- /dev/null
+++ b/test/test_cooperative_wait.jl
@@ -0,0 +1,37 @@
+# tests for the various kinds of waits
+include("common.jl")
+
+MPI.Init()
+
+myrank = MPI.Comm_rank(MPI.COMM_WORLD)
+commsize = MPI.Comm_rank(MPI.COMM_WORLD)
+
+nsends = 2
+send_arr = [ArrayType{Int}([i]) for i = 1:nsends]
+recv_arr = [ArrayType{Int}(undef,1) for i = 1:nsends]
+synchronize()
+
+send_check = zeros(Int, nsends)
+recv_check = zeros(Int, nsends)
+
+@sync for i = 1:nsends
+    Threads.@spawn begin
+        recv_req = MPI.Irecv!(recv_arr[i], MPI.COMM_WORLD; source=myrank, tag=i)
+        wait(recv_req)
+        @test MPI.isnull(recv_req)
+        recv_check[i] += 1
+    end
+    Threads.@spawn begin
+        send_req = MPI.Isend(send_arr[i], MPI.COMM_WORLD; dest=myrank, tag=i)
+        wait(send_req)
+        @test MPI.isnull(send_req)
+        send_check[i] += 1
+    end
+end
+
+@test recv_check == ones(Int, nsends)
+@test send_check == ones(Int, nsends)
+
+MPI.Barrier(MPI.COMM_WORLD)
+MPI.Finalize()
+@test MPI.Finalized()
Repository: JuliaParallel/MPI.jl
Pull request #798 (2023-11-06 04:54:55)

add c2f/f2c handle conversions
Part of #784 


Patch:
diff --git a/src/api/api.jl b/src/api/api.jl
index af58228..b46701c 100644
--- a/src/api/api.jl
+++ b/src/api/api.jl
@@ -135,6 +135,35 @@ end
 
 include("generated_api.jl")
 
+for handle in [
+    :MPI_Comm,
+    :MPI_Datatype,
+    :MPI_Errhandler,
+    :MPI_File,
+    :MPI_Group,
+    :MPI_Info,
+    :MPI_Message,
+    :MPI_Op,
+    :MPI_Request,
+    :MPI_Win,
+]
+    handle_f2c = Symbol(handle,:_f2c)
+    handle_c2f = Symbol(handle,:_c2f)
+    @eval begin
+        if $handle == Cint
+            $handle_f2c(fcomm::Cint) = fcomm
+            $handle_c2f(comm::Cint) = comm
+        else
+            function $handle_f2c(fcomm::Cint)
+                ccall(($(Meta.quot(handle_f2c)), libmpi), $handle, (Cint,), fcomm)
+            end
+            function $handle_c2f(comm::$handle)
+                ccall(($(Meta.quot(handle_c2f)), libmpi), Cint, ($handle,), comm)
+            end
+        end
+    end
+end
+
 # since this is called by invokelatest, it isn't automatically precompiled
 precompile(init_consts, ())
 


Test patch:
diff --git a/test/test_comm.jl b/test/test_comm.jl
index 1d0db03..20e8a4a 100644
--- a/test/test_comm.jl
+++ b/test/test_comm.jl
@@ -42,5 +42,8 @@ else
     @test splitcomm3 == MPI.COMM_NULL
 end
 
+# Fortran conversion
+@test MPI.API.MPI_Comm_f2c(MPI.API.MPI_Comm_c2f(MPI.COMM_SELF.val)) == MPI.COMM_SELF.val
+
 MPI.Finalize()
 @test MPI.Finalized()