Ejemplo n.º 1
0
HYPRE_Int MH_Send(void* buf, hypre_uint count, HYPRE_Int dest, HYPRE_Int mid, MPI_Comm comm )
{
   HYPRE_Int my_id;
   HYPRE_Int retcode = hypre_MPI_Send( buf, (HYPRE_Int) count, hypre_MPI_BYTE, dest, mid, comm);
   if ( retcode != 0 )
   {
      hypre_MPI_Comm_rank(comm, &my_id);
      hypre_printf("%d : MH_Send warning : retcode = %d\n", my_id, retcode);
   }
   return 0;
}
Ejemplo n.º 2
0
HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, 
                                 HYPRE_Int *contact_proc_list,
                                 void *contact_send_buf, 
                                 HYPRE_Int *contact_send_buf_starts,
                                 HYPRE_Int contact_obj_size, 
                                 HYPRE_Int response_obj_size,
                                 hypre_DataExchangeResponse *response_obj,
                                 HYPRE_Int max_response_size, 
                                 HYPRE_Int rnum, MPI_Comm comm,
                                 void **p_response_recv_buf, 
                                 HYPRE_Int **p_response_recv_buf_starts)
{
   /*-------------------------------------------
    *  parameters: 
    *   
    *    num_contacts              = how many procs to contact
    *    contact_proc_list         = list of processors to contact 
    *    contact_send_buf          = array of data to send
    *    contact_send_buf_starts   = index for contact_send_buf corresponding to 
    *                                contact_proc_list
    *    contact_obj_size          = sizeof() one obj in contact list  
   
    *    response_obj_size          = sizeof() one obj in response_recv_buf 
    *    response_obj              = this will give us the function we need to 
    *                                fill the reponse as well as 
    *                                any data we might need to accomplish that 
    *    max_response_size         = max size of a single response expected (do NOT
    *                                need to be an absolute upper bound)  
    *    rnum                      = two consequentive exchanges should have different 
    *                                rnums. Alternate rnum = 1 
    *                                and rnum=2  - these flags will be even (so odd
    *                                numbered tags could be used in calling code) 
    *    p_response_recv_buf       = where to receive the reponses - will be allocated 
    *                                in this function  
    *    p_response_recv_buf_starts  = index of p_response_buf corresponding to 
    *                                contact_buf_list - will be allocated here  

    *-------------------------------------------*/

   HYPRE_Int  num_procs, myid;
   HYPRE_Int  i;
   HYPRE_Int  terminate, responses_complete;
   HYPRE_Int  children_complete;
   HYPRE_Int  contact_flag;
   HYPRE_Int  proc;
   HYPRE_Int  contact_size;

   HYPRE_Int  size, post_size, copy_size;
   HYPRE_Int  total_size, count;      

   void *start_ptr = NULL, *index_ptr=NULL;
   HYPRE_Int  *int_ptr=NULL;  

   void *response_recv_buf = NULL;
   void *send_response_buf = NULL;

   HYPRE_Int  *response_recv_buf_starts = NULL;
   void *initial_recv_buf = NULL;  

   void *recv_contact_buf = NULL;
   HYPRE_Int  recv_contact_buf_size = 0;
   
   HYPRE_Int  response_message_size = 0;

   HYPRE_Int  overhead;
 
   HYPRE_Int  max_response_size_bytes;
   
   HYPRE_Int  max_response_total_bytes;
   
   void **post_array = NULL;  /*this must be set to null or realloc will crash */
   HYPRE_Int  post_array_storage = 0;
   HYPRE_Int  post_array_size = 0;
   HYPRE_Int   num_post_recvs =0;
   
   void **contact_ptrs = NULL, **response_ptrs=NULL, **post_ptrs=NULL;
   
   hypre_BinaryTree tree;

   hypre_MPI_Request *response_requests, *contact_requests;
   hypre_MPI_Status  *response_statuses, *contact_statuses;
   
   hypre_MPI_Request  *post_send_requests = NULL, *post_recv_requests = NULL;
   hypre_MPI_Status   *post_send_statuses = NULL, *post_recv_statuses = NULL;

   hypre_MPI_Request *term_requests, term_request1, request_parent;
   hypre_MPI_Status  *term_statuses, term_status1, status_parent;
   hypre_MPI_Status  status, fill_status;

   const HYPRE_Int contact_tag = 1000*rnum;
   const HYPRE_Int response_tag = 1002*rnum;
   const HYPRE_Int term_tag =  1004*rnum;  
   const HYPRE_Int post_tag = 1006*rnum;
   
   hypre_MPI_Comm_size(comm, &num_procs );
   hypre_MPI_Comm_rank(comm, &myid );

   /* ---------initializations ----------------*/ 

   /* if the response_obj_size or contact_obj_size is 0, set to sizeof(HYPRE_Int) */
   if (!response_obj_size) response_obj_size = sizeof(HYPRE_Int);
   if (!contact_obj_size) contact_obj_size = sizeof(HYPRE_Int);

   max_response_size_bytes = max_response_size*response_obj_size;
 
                   
   /* pre-allocate the max space for responding to contacts */
   overhead = ceil((HYPRE_Real) sizeof(HYPRE_Int)/response_obj_size); /*for appending an integer*/
   
   max_response_total_bytes = (max_response_size+overhead)*response_obj_size;

   response_obj->send_response_overhead = overhead;
   response_obj->send_response_storage = max_response_size;

   /*send_response_buf = hypre_MAlloc(max_response_total_bytes);*/
   send_response_buf = hypre_CAlloc(max_response_size+overhead, response_obj_size);
      
   /*allocate space for inital recv array for the responses - give each processor
     size max_response_size */

   initial_recv_buf = hypre_MAlloc(max_response_total_bytes*num_contacts);
   response_recv_buf_starts =   hypre_CTAlloc(HYPRE_Int, num_contacts+1);  

   contact_ptrs = hypre_TAlloc( void *, num_contacts);
   response_ptrs = hypre_TAlloc(void *, num_contacts);
   
   /*-------------SEND CONTACTS AND POST RECVS FOR RESPONSES---*/

   for (i=0; i<= num_contacts; i++)
   {
      response_recv_buf_starts[i] = i*(max_response_size+overhead);
   }
   
   /* Send "contact" messages to the list of processors and 
      pre-post receives to wait for their response*/

   responses_complete = 1;
   if (num_contacts > 0 )
   {
      responses_complete = 0;
      response_requests = hypre_CTAlloc(hypre_MPI_Request, num_contacts);
      response_statuses = hypre_CTAlloc(hypre_MPI_Status, num_contacts);
      contact_requests = hypre_CTAlloc(hypre_MPI_Request, num_contacts);
      contact_statuses = hypre_CTAlloc(hypre_MPI_Status, num_contacts);

      /* post receives - could be confirmation or data*/
      /* the size to post is max_response_total_bytes*/     
      
      for (i=0; i< num_contacts; i++) 
      {
         /* response_ptrs[i] =  initial_recv_buf + i*max_response_total_bytes ; */
         response_ptrs[i] = (void *)((char *) initial_recv_buf +
                                     i*max_response_total_bytes) ; 

         hypre_MPI_Irecv(response_ptrs[i], max_response_total_bytes,
                         hypre_MPI_BYTE, contact_proc_list[i], 
                         response_tag, comm, &response_requests[i]);
      }

      /* send out contact messages */
      start_ptr = contact_send_buf;
      for (i=0; i< num_contacts; i++) 
      {
         contact_ptrs[i] = start_ptr; 
         size =  contact_send_buf_starts[i+1] - contact_send_buf_starts[i]  ; 
         hypre_MPI_Isend(contact_ptrs[i], size*contact_obj_size,
                         hypre_MPI_BYTE, contact_proc_list[i], 
                         contact_tag, comm, &contact_requests[i]); 
         /*  start_ptr += (size*contact_obj_size); */        
         start_ptr = (void *) ((char *) start_ptr  + (size*contact_obj_size)); 
      }
   }

   /*------------BINARY TREE-----------------------*/

   /*Now let's find out our binary tree information and
     initialize for the termination check sweep */
   terminate = 1; /*indicates whether we can stop probing for contact */
   children_complete = 1;/*indicates whether we have recv. term messages 
                           from our children*/
 
   if (num_procs > 1)
   { 
      hypre_CreateBinaryTree(myid, num_procs, &tree);

      /* we will get a message from all of our children when they 
         have received responses for all of their contacts.  
         So post receives now */
   
      term_requests = hypre_CTAlloc(hypre_MPI_Request, tree.num_child); 
      term_statuses = hypre_CTAlloc(hypre_MPI_Status, tree.num_child);

      for (i=0; i< tree.num_child; i++) 
      {
	 hypre_MPI_Irecv(NULL, 0, HYPRE_MPI_INT, tree.child_id[i], term_tag, comm, 
                         &term_requests[i]);
      }

      terminate = 0;
 
      children_complete = 0;
   }
   else if (num_procs ==1 && num_contacts > 0 ) /* added 11/08 */
   {
      terminate = 0;
   }

   /*---------PROBE LOOP-----------------------------------------*/

   /*Look for incoming contact messages - don't know how many I will get!*/
  
   while (!terminate)
   {
      /* did I receive any contact messages? */
      hypre_MPI_Iprobe(hypre_MPI_ANY_SOURCE, contact_tag, comm,
                       &contact_flag, &status);

      while (contact_flag)
      {
         /* received contacts - from who and what do we do ?*/
         proc = status.hypre_MPI_SOURCE;
         hypre_MPI_Get_count(&status, hypre_MPI_BYTE, &contact_size);

         contact_size = contact_size/contact_obj_size;
         
         /*---------------FILL RESPONSE ------------------------*/

         /*first receive the contact buffer - then call a function
           to determine how to populate the send buffer for the reponse*/

         /* do we have enough space to recv it? */
         if(contact_size > recv_contact_buf_size) 
         {
            recv_contact_buf = hypre_ReAlloc(recv_contact_buf, 
                                             contact_obj_size*contact_size);
            recv_contact_buf_size = contact_size;
         } 

         /* this must be blocking - can't fill recv without the buffer*/         
         hypre_MPI_Recv(recv_contact_buf, contact_size*contact_obj_size,
                        hypre_MPI_BYTE, proc, contact_tag, comm, &fill_status);

         response_obj->fill_response(recv_contact_buf, contact_size, proc,
                                     response_obj, comm, &send_response_buf,
                                     &response_message_size );

         /* we need to append the size of the send obj */
         /* first we copy out any part that may be needed to send later so we don't overwrite */
         post_size = response_message_size - max_response_size; 
         if (post_size > 0) /*we will need to send the extra information later */   
         {
            /*hypre_printf("myid = %d, post_size = %d\n", myid, post_size);*/

            if (post_array_size == post_array_storage)
             
            {
               /* allocate room for more posts  - add 20*/
               post_array_storage += 20;       
               post_array = hypre_TReAlloc(post_array, void *, post_array_storage); 
               post_send_requests =
                  hypre_TReAlloc(post_send_requests, hypre_MPI_Request,
                                 post_array_storage);
            }
            /* allocate space for the data this post only*/
            /* this should not happen often (unless a poor max_size has been chosen)
               - so we will allocate space for the data as needed */
            size = post_size*response_obj_size;
            post_array[post_array_size] =  hypre_MAlloc(size); 
            /* index_ptr =  send_response_buf + max_response_size_bytes */;
            index_ptr = (void *) ((char *) send_response_buf +
                                  max_response_size_bytes);
               
            memcpy(post_array[post_array_size], index_ptr, size);
    
            /*now post any part of the message that is too long with a non-blocking
              send and a different tag */

            hypre_MPI_Isend(post_array[post_array_size], size,
                            hypre_MPI_BYTE, proc, post_tag, 
                            /*hypre_MPI_COMM_WORLD, */
                            comm,
                            &post_send_requests[post_array_size]); 

            post_array_size++;
         }

         /*now append the size information into the overhead storage */
         /* index_ptr =  send_response_buf + max_response_size_bytes; */
         index_ptr = (void *) ((char *) send_response_buf +
                               max_response_size_bytes);

         memcpy(index_ptr, &response_message_size, sizeof(HYPRE_Int));
         
         /*send the block of data that includes the overhead */        
         /* this is a blocking send - the recv has already been posted */
         hypre_MPI_Send(send_response_buf, max_response_total_bytes, 
                        hypre_MPI_BYTE, proc, response_tag, comm); 

         /*--------------------------------------------------------------*/
      
         /* look for any more contact messages*/
         hypre_MPI_Iprobe(hypre_MPI_ANY_SOURCE, contact_tag, comm,
                          &contact_flag, &status);
      }
    
      /* no more contact messages waiting - either 
         (1) check to see if we have received all of our response messages
         (2) participate in termination (check for messages from children)
         (3) participate in termination sweep (check for message from parent) */
    
      if (!responses_complete) 
      {
         hypre_MPI_Testall(num_contacts, response_requests, &responses_complete, 
                           response_statuses);
         if (responses_complete && num_procs == 1) terminate = 1; /*added 11/08 */

      }
      else if(!children_complete) /* have all of our children received all of their 
                                     response messages?*/
      {
         hypre_MPI_Testall(tree.num_child, term_requests, &children_complete, 
                           term_statuses);

         /* if we have gotten term messages from all of our children, send a term 
            message to our parent.  Then post a receive to hear back from parent */ 
	 if (children_complete & (myid > 0)) /*root does not have a parent*/ 
         {
            hypre_MPI_Isend(NULL, 0, HYPRE_MPI_INT, tree.parent_id, term_tag,
                            comm, &request_parent);
            
            hypre_MPI_Irecv(NULL, 0, HYPRE_MPI_INT, tree.parent_id, term_tag,
                            comm, &term_request1);
         }
      }
      else /*have we gotten a term message from our parent? */
      {
         if (myid == 0) /* root doesn't have a parent */
         {
            terminate = 1;
         } 
         else  
         {
            hypre_MPI_Test(&term_request1, &terminate, &term_status1);
         }  
         if (terminate) /*tell children to terminate */
	 {
            if (myid > 0 ) hypre_MPI_Wait(&request_parent, &status_parent);
            
	    for (i=0; i< tree.num_child; i++)
	    {  /*a blocking send  - recv has been posted already*/
	       hypre_MPI_Send(NULL, 0, HYPRE_MPI_INT, tree.child_id[i],
                              term_tag, comm);
	    }
	 }
      } 
   }
Ejemplo n.º 3
0
HYPRE_Int HYPRE_ParCSRMLConstructMHMatrix(HYPRE_ParCSRMatrix A, MH_Matrix *mh_mat,
                             MPI_Comm comm, HYPRE_Int *partition,MH_Context *obj) 
{
    HYPRE_Int         i, j, index, my_id, nprocs, msgid, *tempCnt;
    HYPRE_Int         sendProcCnt, *sendLeng, *sendProc, **sendList;
    HYPRE_Int         recvProcCnt, *recvLeng, *recvProc;
    HYPRE_Int         rowLeng, *colInd, startRow, endRow, localEqns;
    HYPRE_Int         *diagSize, *offdiagSize, externLeng, *externList, ncnt, nnz;
    HYPRE_Int         *rowptr, *columns, num_bdry;
    double      *colVal, *values;
    hypre_MPI_Request *Request;
    hypre_MPI_Status  status;

    /* -------------------------------------------------------- */
    /* get machine information and local matrix information     */
    /* -------------------------------------------------------- */
    
    hypre_MPI_Comm_rank(comm, &my_id);
    hypre_MPI_Comm_size(comm, &nprocs);

    startRow  = partition[my_id];
    endRow    = partition[my_id+1] - 1;
    localEqns = endRow - startRow + 1;

    /* -------------------------------------------------------- */
    /* probe A to find out about diagonal and off-diagonal      */
    /* block information                                        */
    /* -------------------------------------------------------- */

    diagSize    = (HYPRE_Int*) malloc( sizeof(HYPRE_Int) * localEqns );
    offdiagSize = (HYPRE_Int*) malloc( sizeof(HYPRE_Int) * localEqns );
    num_bdry = 0;
    for ( i = startRow; i <= endRow; i++ )
    {
       diagSize[i-startRow] = offdiagSize[i-startRow] = 0;
       HYPRE_ParCSRMatrixGetRow(A, i, &rowLeng, &colInd, &colVal);
       for (j = 0; j < rowLeng; j++)
          if ( colInd[j] < startRow || colInd[j] > endRow )
          {
             //if ( colVal[j] != 0.0 ) offdiagSize[i-startRow]++;
             offdiagSize[i-startRow]++;
          }
          else
          {
             //if ( colVal[j] != 0.0 ) diagSize[i-startRow]++;
             diagSize[i-startRow]++;
          }
       HYPRE_ParCSRMatrixRestoreRow(A, i, &rowLeng, &colInd, &colVal);
       if ( diagSize[i-startRow] + offdiagSize[i-startRow] == 1 ) num_bdry++;
    }

    /* -------------------------------------------------------- */
    /* construct external node list in global eqn numbers       */
    /* -------------------------------------------------------- */

    externLeng = 0;
    for ( i = 0; i < localEqns; i++ ) externLeng += offdiagSize[i];
    if ( externLeng > 0 )
         externList = (HYPRE_Int *) malloc( sizeof(HYPRE_Int) * externLeng);
    else externList = NULL;
    externLeng = 0;
    for ( i = startRow; i <= endRow; i++ )
    {
       HYPRE_ParCSRMatrixGetRow(A, i, &rowLeng, &colInd, &colVal);
       for (j = 0; j < rowLeng; j++)
       {
          if ( colInd[j] < startRow || colInd[j] > endRow )
             //if ( colVal[j] != 0.0 ) externList[externLeng++] = colInd[j];
             externList[externLeng++] = colInd[j];
       }
       HYPRE_ParCSRMatrixRestoreRow(A, i, &rowLeng, &colInd, &colVal);
    }
    qsort0( externList, 0, externLeng-1 );
    ncnt = 0;
    for ( i = 1; i < externLeng; i++ )
    {
       if ( externList[i] != externList[ncnt] ) 
          externList[++ncnt] = externList[i];
    }
    externLeng = ncnt + 1;

    /* -------------------------------------------------------- */
    /* allocate the CSR matrix                                  */
    /* -------------------------------------------------------- */ 

    nnz = 0; 
    for ( i = 0; i < localEqns; i++ ) nnz += diagSize[i] + offdiagSize[i]; 
    rowptr  = (HYPRE_Int *)    malloc( (localEqns + 1) * sizeof(HYPRE_Int) ); 
    columns = (HYPRE_Int *)    malloc( nnz * sizeof(HYPRE_Int) ); 
    values  = (double *) malloc( nnz * sizeof(double) ); 
    rowptr[0] = 0; 
    for ( i = 1; i <= localEqns; i++ ) 
       rowptr[i] = rowptr[i-1] + diagSize[i-1] + offdiagSize[i-1];
    free( diagSize );
    free( offdiagSize );

    /* -------------------------------------------------------- */ 
    /* put the matrix data in the CSR matrix                    */
    /* -------------------------------------------------------- */ 

    rowptr[0] = 0; 
    ncnt      = 0;
    for ( i = startRow; i <= endRow; i++ )
    {
       HYPRE_ParCSRMatrixGetRow(A, i, &rowLeng, &colInd, &colVal);
       for (j = 0; j < rowLeng; j++)
       {
          index = colInd[j];
          //if ( colVal[j] != 0.0 ) 
          {
             if ( index < startRow || index > endRow )
             {
                columns[ncnt] = hypre_BinarySearch(externList,index,
                                                   externLeng );
                columns[ncnt] += localEqns;
                values [ncnt++] = colVal[j];
             }
             else
             {
                columns[ncnt] = index - startRow;
                values[ncnt++] = colVal[j];
             }
          }
       }
       rowptr[i-startRow+1] = ncnt;
       HYPRE_ParCSRMatrixRestoreRow(A, i, &rowLeng, &colInd, &colVal);
    }
    assert( ncnt == nnz );
   
    /* -------------------------------------------------------- */ 
    /* initialize the MH_Matrix data structure                  */
    /* -------------------------------------------------------- */ 

    mh_mat->Nrows       = localEqns;
    mh_mat->rowptr      = rowptr;
    mh_mat->colnum      = columns;
    mh_mat->values      = values;
    mh_mat->sendProcCnt = 0;
    mh_mat->recvProcCnt = 0;
    mh_mat->sendLeng    = NULL;
    mh_mat->recvLeng    = NULL;
    mh_mat->sendProc    = NULL;
    mh_mat->recvProc    = NULL;
    mh_mat->sendList    = NULL;
    mh_mat->map         = externList;
 
    /* -------------------------------------------------------- */ 
    /* form the remote portion of the matrix                    */
    /* -------------------------------------------------------- */ 

    if ( nprocs > 1 ) 
    {
       /* ----------------------------------------------------- */ 
       /* count number of elements to be received from each     */
       /* remote processor (assume sequential mapping)          */
       /* ----------------------------------------------------- */ 

       tempCnt = (HYPRE_Int *) malloc( sizeof(HYPRE_Int) * nprocs );
       for ( i = 0; i < nprocs; i++ ) tempCnt[i] = 0;
       for ( i = 0; i < externLeng; i++ )
       {
          for ( j = 0; j < nprocs; j++ )
          {
             if ( externList[i] >= partition[j] && 
                  externList[i] < partition[j+1] )
             {
                tempCnt[j]++;
                break;
             }
          }
       }

       /* ----------------------------------------------------- */ 
       /* compile a list processors data is to be received from */
       /* ----------------------------------------------------- */ 

       recvProcCnt = 0;
       for ( i = 0; i < nprocs; i++ )
          if ( tempCnt[i] > 0 ) recvProcCnt++;
       recvLeng = (HYPRE_Int*) malloc( sizeof(HYPRE_Int) * recvProcCnt );
       recvProc = (HYPRE_Int*) malloc( sizeof(HYPRE_Int) * recvProcCnt );
       recvProcCnt = 0;
       for ( i = 0; i < nprocs; i++ )
       {
          if ( tempCnt[i] > 0 ) 
          {
             recvProc[recvProcCnt]   = i;
             recvLeng[recvProcCnt++] = tempCnt[i];
          }
       }

       /* ----------------------------------------------------- */ 
       /* each processor has to find out how many processors it */
       /* has to send data to                                   */
       /* ----------------------------------------------------- */ 

       sendLeng = (HYPRE_Int *) malloc( nprocs * sizeof(HYPRE_Int) );
       for ( i = 0; i < nprocs; i++ ) tempCnt[i] = 0;
       for ( i = 0; i < recvProcCnt; i++ ) tempCnt[recvProc[i]] = 1;
       hypre_MPI_Allreduce(tempCnt, sendLeng, nprocs, HYPRE_MPI_INT, hypre_MPI_SUM, comm );
       sendProcCnt = sendLeng[my_id];
       free( sendLeng );
       if ( sendProcCnt > 0 )
       {
          sendLeng = (HYPRE_Int *)  malloc( sendProcCnt * sizeof(HYPRE_Int) );
          sendProc = (HYPRE_Int *)  malloc( sendProcCnt * sizeof(HYPRE_Int) );
          sendList = (HYPRE_Int **) malloc( sendProcCnt * sizeof(HYPRE_Int*) );
       }
       else 
       {
          sendLeng = sendProc = NULL;
          sendList = NULL;
       }

       /* ----------------------------------------------------- */ 
       /* each processor sends to all processors it expects to  */
       /* receive data about the lengths of data expected       */
       /* ----------------------------------------------------- */ 

       msgid = 539;
       for ( i = 0; i < recvProcCnt; i++ ) 
       {
          hypre_MPI_Send((void*) &recvLeng[i],1,HYPRE_MPI_INT,recvProc[i],msgid,comm);
       }
       for ( i = 0; i < sendProcCnt; i++ ) 
       {
          hypre_MPI_Recv((void*) &sendLeng[i],1,HYPRE_MPI_INT,hypre_MPI_ANY_SOURCE,msgid,
                   comm,&status);
          sendProc[i] = status.hypre_MPI_SOURCE;
          sendList[i] = (HYPRE_Int *) malloc( sendLeng[i] * sizeof(HYPRE_Int) );
          if ( sendList[i] == NULL ) 
             hypre_printf("allocate problem %d \n", sendLeng[i]);
       }

       /* ----------------------------------------------------- */ 
       /* each processor sends to all processors it expects to  */
       /* receive data about the equation numbers               */
       /* ----------------------------------------------------- */ 

       for ( i = 0; i < nprocs; i++ ) tempCnt[i] = 0; 
       ncnt = 1;
       for ( i = 0; i < externLeng; i++ ) 
       {
          if ( externList[i] >= partition[ncnt] )
          {
             tempCnt[ncnt-1] = i;
             i--;
             ncnt++;
          }
       }    
       for ( i = ncnt-1; i < nprocs; i++ ) tempCnt[i] = externLeng; 

       /* ----------------------------------------------------- */ 
       /* send the global equation numbers                      */
       /* ----------------------------------------------------- */ 

       msgid = 540;
       for ( i = 0; i < recvProcCnt; i++ ) 
       {
          if ( recvProc[i] == 0 ) j = 0;
          else                    j = tempCnt[recvProc[i]-1];
          rowLeng = recvLeng[i];
          hypre_MPI_Send((void*) &externList[j],rowLeng,HYPRE_MPI_INT,recvProc[i],
                    msgid,comm);
       }
       for ( i = 0; i < sendProcCnt; i++ ) 
       {
          rowLeng = sendLeng[i];
          hypre_MPI_Recv((void*)sendList[i],rowLeng,HYPRE_MPI_INT,sendProc[i],
                   msgid,comm,&status);
       }

       /* ----------------------------------------------------- */ 
       /* convert the send list from global to local numbers    */
       /* ----------------------------------------------------- */ 

       for ( i = 0; i < sendProcCnt; i++ )
       { 
          for ( j = 0; j < sendLeng[i]; j++ )
          {
             index = sendList[i][j] - startRow;
             if ( index < 0 || index >= localEqns )
             {
                hypre_printf("%d : Construct MH matrix Error - index out ");
                hypre_printf("of range%d\n", my_id, index);
             }
             sendList[i][j] = index;
          }
       }

       /* ----------------------------------------------------- */ 
       /* convert the send list from global to local numbers    */
       /* ----------------------------------------------------- */ 

       mh_mat->sendProcCnt = sendProcCnt;
       mh_mat->recvProcCnt = recvProcCnt;
       mh_mat->sendLeng    = sendLeng;
       mh_mat->recvLeng    = recvLeng;
       mh_mat->sendProc    = sendProc;
       mh_mat->recvProc    = recvProc;
       mh_mat->sendList    = sendList;

       /* ----------------------------------------------------- */ 
       /* clean up                                              */
       /* ----------------------------------------------------- */ 

       free( tempCnt );
    }

    return 0;
}