#include "BSprivate.h" /*@ BSoffset - Find a consistent global numbering Input Parameters: . length - number of classes of things to order . array - the number of things in each class on this processor . procinfo - the usual processor stuff Output Parameters: . offsets - the beginning number for each class on this processor in the global numbering Returns: the number of classes across all the processors Notes: This routine, given a list of totals, finds where we should be numbered. For example, if proc 0 submits a list of 10 and 20 and proc 1 submits a list of 5 and 11 and proc 2 submits a list of 6 and 9, we want to do a tree ordering where proc 0 gets back 5 and 32, proc 1 gets back 0 and 21 and proc 2 gets back 15 and 52. @*/ int BSoffset(int length, int *array, int **offsets, BSprocinfo *procinfo) { int global_len, work; int parent, l_child, r_child; int *t_offsets; int *recv_buf; int i; int num_msg, num_children; int *l_buffer, *r_buffer; int count; BSmsg_list *msg_list = NULL; MPI_Status mpi_status; /* first, agree on global length */ global_len = length; GIMAX(&global_len,1,&work,procinfo->procset); CHKERRN(0); /* allocate and initialize offsets buffer */ MY_MALLOCN(t_offsets,(int *),sizeof(int)*global_len,1); (*offsets) = t_offsets; for (i=0;iprocset); PSNbrTree(PS_LCHILD,l_child,procinfo->procset); PSNbrTree(PS_RCHILD,r_child,procinfo->procset); /* collect messages from children */ num_children = 0; if (l_child >= 0) num_children++; if (r_child >= 0) num_children++; l_buffer = NULL; r_buffer = NULL; num_msg = 0; while (num_msg < num_children) { MY_MALLOCN(recv_buf,(int *),sizeof(int)*global_len,2); RECVSYNCNOMEM(OFFSETU_MSG,recv_buf,global_len,MPI_INT,procinfo, mpi_status); CHKERRN(0); num_msg++; for (i=0;i