...
> srun --mpi=pmi2 ./myprogram
Pay attention in putting the flag --mpi=pmi2 immediatly after srun.
SLURM automatically exports the environment variables you defined in the source shell, so that if you need to run your program myprogram in a controlled environment (i.e. specific library paths or options), you can prepare the environment in the origin shell being sure to find it in the interactive shell.
...