#!/bin/bash

# This script runs the examples that require both spec and vmec. This script is used by the Github
# Actions continuous integration. Examples that can use MPI are run
# for various numbers of processes.

set -ex

# In the next line, ${GITHUB_ACTIONS:+--oversubscribe} evaluates to
# --oversubscribe if the environment variable GITHUB_ACTIONS is set,
# and evaluates to nothing if the variable is not set.  The motivation
# is that Github Actions only gives you 2 processors, so we have to
# "oversubscribe" to test on >2 mpi processes. But we don't want to
# set --oversubscribe when outside Github Actions, since other
# versions of mpi like mpich do not have this flag.
MPI_OPTIONS=${GITHUB_ACTIONS:+--oversubscribe}
echo MPI_OPTIONS=$MPI_OPTIONS

./stellarator_benchmarks/2DOF_vmecAndSpec.py
mpiexec $MPI_OPTIONS -n 2 ./stellarator_benchmarks/2DOF_vmecAndSpec.py

mpiexec $MPI_OPTIONS -n 2 ./3_Advanced/optimize_qs_and_islands_simultaneously.py
