diff --git a/Parallel_mpi/Farm.ml b/Parallel_mpi/Farm.ml index 7da1fbe..3a8b7f3 100644 --- a/Parallel_mpi/Farm.ml +++ b/Parallel_mpi/Farm.ml @@ -48,7 +48,13 @@ let run_parallel_server ~ordered stream = let fetch_result () : (task_id * 'a) option * int = let (message, rank, _tag) : (task_id * 'a) option * int * int = debug "Before receive_status"; - Mpi.receive_status Mpi.any_source Mpi.any_tag Mpi.comm_world + (* Avoid busy receive *) + let rec wait_and_receive () = + match Mpi.iprobe Mpi.any_source Mpi.any_tag Mpi.comm_world with + | Some _ -> Mpi.receive_status Mpi.any_source Mpi.any_tag Mpi.comm_world + | None -> (Unix.sleepf 0.001 ; wait_and_receive ()) + in + wait_and_receive () in debug @@ Printf.sprintf "After receive_status %d %d" rank _tag; message, rank