Dash

import dask

lazy_results = []
for a in A:
    for b in B:
        if a < b:
            c = dask.delayed(f)(a, b)  # add lazy task
        else:
            c = dask.delayed(g)(a, b)  # add lazy task
        lazy_results.append(c)

results = dask.compute(*lazy_results)  # compute all in parallel

https://docs.dask.org/en/latest/use-cases.html
https://towardsdatascience.com/speeding-up-your-algorithms-part-4-dask-7c6ed79994ef