Resolved. I saved a global variable during the function f and returned the processor ID in addition to the usual returned value. Then, I replaced the second pmap with a bunch of @spawnat’s which match processor IDs to the correct task, and access the global variable saved by f.