Create opam switches in parallel

[found the answer]
I’d like to do some testing on a bunch of different ocaml versions, and for this I need to create a bunch of switches for different ocaml versions. Is there a way I can create them all in parallel ? There’s a lock that gets held during switch creation, but maybe there’s a way to create the switch but without populating it with the compiler? And then I could “switch” to the switch (using opam env) and build/install the compiler package – so these could all happen in parallel in these N different switches ?

Does anybody know how to do this?

Ah, this was the answer: Newbie tip: using multiple projects/switches from command line and emacs

For your specific need, you can first create sequentially all needed empty switches, then parallelise their needed packages. For switch creation, a lock is taken on global state, while for install or invariant setting, only a switch lock is taken.
For example

switches="4.08.0 4.09.0 4.10.0 4.11.0"
for s in $switches; do
  opam switch create $s --empty
done

for s in $switches; do
  # parallelise this command
  opam set-invariant ocaml.$s -n && opam install ocaml.$s
  # if you want to set an invariant
  # or just `ocaml`,
  # or another package
done

Yep, I did that, once I figured out that I needed to do more than just set the environment variable (that’s what the inopam script taught me). Then I hit what appears to be a global lock in opam during population of switches (I opened an issue on github for it). But yep, this is the key thing: create the empty switches first, then populate them with the compiler and packages.