# Sequential Decision Making Under Uncertainty
This program models a simple problem illustrating sequential decision making
under uncertainty: ordering supplies for a restaurant. This program evaluates
the "order up to" policy. In such a policy, a minimum threshold is set for an
inventory item (sausage in this case). When the inventory level drops below the
minimum threshold, more of the item is ordered "up to" the maximum value (the
second policy parameter). By generating a set of stochastic demand data, we can
evaluate the effectiveness of each set of policy parameters.
This model includes some additional details such as shipping fees and free
shipping over a certain quantity. This reflects additional details of the real
world problem domain where shipping fees are a real concern for supply orders.
## Building (GNU)
Determine the number of workers you'd like, generally this should be less than
or equal to the number of cores on each node. Build with (for 128 workers):
make -f Makefile.gnumake MT=128 FAST=1
Then run with `sbatch slurm-job.sh` for a slurm system or use `mpirun`
otherwise. See the `run` target in `Makefile` for an example of using `mpirun`.
## Building (OpenBSD)
Determine the number of workers you'd like, generally this should be less than
or equal to the number of cores on each node. Build with (for 128 workers):
export OMPI_CC=/usr/bin/clang
make MT=128 FAST=1
Then run with `sbatch slurm-job.sh` for a slurm system or use `mpirun`
otherwise. See the `run` target in `Makefile` for an example of using `mpirun`.
## Use of OpenMPI
This program uses OpenMPI for increased parallelism. Subsequently, the
`openmpi` package must be installed. By incorporating OpenMPI, the tasks can be
shared across cores spanning different physical nodes within the same program. I
believe the communication overhead from remote memory access within OpenMPI is
less than would be incurred using some other scatter-gather setup.
## pledge(2) and OpenMPI
OpenMPI requires use of `shmget(2)`, meaning `pledge(2)` cannot be used by an
OpenMPI program.
## Concurrency Design
The process that is identified as rank 0 is the leader. All others are
considered worker processes.
The leader will generate the scenario data and share it with the worker
processes. The leader will then divide the range of policy parameters to be
searched between itself and the other worker processes.
Each of the processes will then calculate the best values from the range of
policy values it was tasked with searching. The resulting parameter set and
associated profit value will be provided back to the leader.
The leader will then select the best of the results and emit them to `STDOUT`.
# References
[ENCCS Intermediate
MPI](https://enccs.github.io/intermediate-mpi/one-sided-routines/)
# To Do
## Use of Unveil
Can unveil(2) be used? What path(s) would require unveiling?
## Release work queue memory on GNU systems
In `wq.c`, the queue memory is freed for OpenBSD systems. This needs to be
implemented for GNU systems as well.
# Bugs
As mentioned above, work queue memory is leaked at program exit.