module stack_manager
use, intrinsic :: iso_fortran_env, only: lock_type
type task
:
end type
type(lock_type), private :: stack_lock[*]
type(task), private :: stack(100)[*]
integer, private :: stack_size[*]
contains
subroutine get_task(job)
! Get a task from my stack
type(task),intent(out) :: job
lock(stack_lock)
job=stack(stack_size)
stack_size=stack_size-1
unlock(stack_lock)
end subroutine get_task
subroutine put_task(job,image)
! Put a task on the stack of image
type(task),intent(in) :: job
integer,intent(in) :: image
lock(stack_lock[image])
stack_size[image]=stack_size[image]+1
stack(stack_size[image])[image] = job
unlock(stack_lock[image])
end subroutine put_task
end module stack_manager