# This module reproduces the writer and reader scenario from the
# file example, but communicates through a named pipe instead of a
# plain file. fifo_writer declares its output FIFO with
# define_fifo_opt instead of a regular path, and fifo_reader
# obtains it the same way as before, through
# define_opt_from_proc_out. A FIFO must be open on both ends
# before either process can proceed, so an option connected to a
# FIFO gets no scheduling dependency by default: both processes are
# launched together, instead of the reader waiting for the writer to
# finish, as it would for a regular file. The define_opt_deps
# example shows how a reader can still ask to be launched only once
# the writer has started. A FIFO has a single reader, and the two
# processes must run on the same machine, so a program that uses
# FIFOs cannot run with the Slurm scheduler.
fifo_writer_document()
{
document_process "Prints a string to a FIFO."
}
fifo_writer_explain_opts()
{
# -outf option
local description="output fifo"
explain_opt "-outf" "<string>" "$description"
}
fifo_writer_identify_cmdline_opts()
{
:
}
fifo_writer_define_opts()
{
# Initialize variables
local cmdline=$1
local process_spec=$2
local process_name=$3
local process_outdir=$4
local optlist=""
# Define option for FIFO
local fifoname="fifo"
define_fifo_opt "-outf" "${fifoname}" optlist || return 1
# Save option list
save_opt_list optlist
}
fifo_writer()
{
# Initialize variables
local outf=$(read_opt_value_from_func_args "-outf" "$@")
# Write string to FIFO
echo "Hello World" > "${outf}"
}
fifo_reader_document()
{
document_process "Reads a string from a FIFO."
}
fifo_reader_explain_opts()
{
# -inf option
local description="input fifo"
explain_opt "-inf" "<string>" "$description"
}
fifo_reader_identify_cmdline_opts()
{
:
}
fifo_reader_define_opts()
{
# Initialize variables
local cmdline=$1
local process_spec=$2
local process_name=$3
local process_outdir=$4
local optlist=""
# Define option for input FIFO
define_opt_from_proc_out "-inf" "fifo_writer" "-outf" optlist || return 1
# Save option list
save_opt_list optlist
}
fifo_reader()
{
# Initialize variables
local inf=$(read_opt_value_from_func_args "-inf" "$@")
# Read string from FIFO
cat < "${inf}"
}
debasher_fifo_example_program()
{
add_debasher_process "fifo_writer" "cpus=1 mem=32 time=00:01:00"
add_debasher_process "fifo_reader" "cpus=1 mem=32 time=00:01:00"
}