def get_local_rank_size(comm):
this_node = platform.node()<EOL>ranks_nodes = comm.allgather((comm.Get_rank(), this_node))<EOL>node2rankssofar = defaultdict(int)<EOL>local_rank = None<EOL>for (rank, node) in ranks_nodes:<EOL><INDENT>if rank == comm.Get_rank():<EOL><INDENT>local_rank = node2rankssofar[node]<EOL><DEDENT>node2rankssofar[node] += <NUM_LIT:1><EOL><DEDENT>assert local_rank is not None<EOL>return local_rank, node2rankssofar[this_node]<EOL>
Returns the rank of each process on its machine
The processes on a given machine will be assigned ranks
    0, 1, 2, ..., N-1,
where N is the number of processes on this machine.

Useful if you want to assign one gpu per machine