Skip to content

Commit

Permalink
Merge pull request #8 from viniciusjusten/vj/termination-message
Browse files Browse the repository at this point in the history
remove controller arg from send_termination_message
  • Loading branch information
guilhermebodin authored May 14, 2024
2 parents 46c9225 + ce842d0 commit 3aa47e9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/controller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,15 @@ function send_jobs_to_any_available_workers(controller::Controller)
end

"""
send_termination_message(controller::Controller)
send_termination_message()
Send a termination message to all workers.
"""
function send_termination_message(controller::Controller)
if !is_controller_process()
error("Only the controller process can send termination messages.")
end
function send_termination_message()
requests = Vector{JobRequest}()
for worker in 1:controller.n_workers
for worker in 1:num_workers()
request =
MPI.isend(Job(controller.last_job_id, TerminationMessage()), _mpi_comm(); dest = worker, tag = worker + 32)
controller.worker_status[worker] = WORKER_AVAILABLE
MPI.isend(Job(0, TerminationMessage()), _mpi_comm(); dest = worker, tag = worker + 32)
push!(requests, JobRequest(worker, request))
end
return _wait_all(requests)
Expand Down
4 changes: 2 additions & 2 deletions src/pmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function pmap(f::Function, jobs::Vector, data_defined_in_process = nothing)
end
end
end
send_termination_message(controller)
send_termination_message()
mpi_barrier()
return result
else
Expand All @@ -72,4 +72,4 @@ function pmap(f::Function, jobs::Vector, data_defined_in_process = nothing)
return result
end
return error("Should never get here")
end
end
2 changes: 1 addition & 1 deletion test/test_1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function job_queue(data)
end
end

JQM.send_termination_message(controller)
JQM.send_termination_message()

return new_data
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function divisors(data)
end
end

JQM.send_termination_message(controller)
JQM.send_termination_message()

return new_data
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_pmap_serial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ divisors_answer = JQM.pmap(get_divisors, collect(1:10))
[[1], [1, 2], [1, 3], [1, 2, 4], [1, 5], [1, 2, 3, 6], [1, 7], [1, 2, 4, 8], [1, 3, 9], [1, 2, 5, 10]]
end

JQM.mpi_finalize()
JQM.mpi_finalize()

0 comments on commit 3aa47e9

Please sign in to comment.