0

In one part of my agent-based model, I collect all agents with the same type from different ranks by using MPI.COMM_WORLD.gather. Then I'm trying to send the gathered agents to a function that needs to perform some computations on the gathered agents. These agents are from different ranks and when I am trying to get the attribute of the agent by calling the agent with ctx.agent(id, type, rank) I encounter an error as the self.context is distributed on different ranks. My code looks like the following:

self.context = ctx.SharedContext(comm) 
new_data=MPI.COMM_WORLD.gather(data, root=0)

if self.rank==0:
   function(new_data, self.context)

How can I gather all self.context of different ranks into one place and send it to the function?

Also, I tried to use request_agents as follows but I couldn't make it work:

if self.rank==0:
    self.context.request_agents(((1,0,3),3),creart_agent)
...
Ak2495
  • 1

1 Answers1

0
if self.rank==0:
    self.context.request_agents(((1,0,3),3),creart_agent)
...

This second piece of code won't work because it is only called from rank 0. The function request_agents is a collective operation that needs to be called from all ranks.

You can instead call as

self.context.request_agents(...)
mpw2
  • 148
  • 8