Exemplo n.º 1
0
/*-------------------------------------------------------------------
 * Function:    Odd_even_iter
 * Purpose:     One iteration of Odd-even transposition sort
 * In args:     local_n, phase, my_rank, p, comm
 * In/out args: local_A
 * Scratch:     temp_B, temp_C
 */
void Odd_even_iter(int local_A[], int temp_B[], int temp_C[],
        int local_n, int phase, int even_partner, int odd_partner,
        int my_rank, int p, MPI_Comm comm) {
   MPI_Status status;

   if (phase % 2 == 0) {  /* Even phase, odd process <-> rank-1 */
      if (even_partner >= 0) {
         MPI_Sendrecv(local_A, local_n, MPI_INT, even_partner, 0, 
            temp_B, local_n, MPI_INT, even_partner, 0, comm,
            &status);
         if (my_rank % 2 != 0)
            Merge_split_high(local_A, temp_B, temp_C, local_n);
         else
            Merge_split_low(local_A, temp_B, temp_C, local_n);
      }
   } else { /* Odd phase, odd process <-> rank+1 */
      if (odd_partner >= 0) {
         MPI_Sendrecv(local_A, local_n, MPI_INT, odd_partner, 0, 
            temp_B, local_n, MPI_INT, odd_partner, 0, comm,
            &status);
         if (my_rank % 2 != 0)
            Merge_split_low(local_A, temp_B, temp_C, local_n);
         else
            Merge_split_high(local_A, temp_B, temp_C, local_n);
      }
   }
}  /* Odd_even_iter */
Exemplo n.º 2
0
/* ============================================================================
Function:     =        Merge_split
Purpose:      =        The root itteration logic for the merge split sort.
==============================================================================
Input arg:  =        1. my_slope: The direction to sort the list.
            =        2. my_rank: The processors rank.
            =        3. list_size: The size of each processors array.
            =        4. my_list[]: A pointer to an array.
            =        5. neighbors_list[]: A pointer to an array.
            =        6. my_partner: The processor to sendrecv with.
            =        7. comm: The mpi communicator channel.
=========================================================================== */
void Merge_split(int my_slope, int my_rank, int list_size, int my_list[],
                    int neighbors_list[], int my_partner, MPI_Comm comm)
{
    MPI_Status status;

    MPI_Sendrecv(my_list, list_size, MPI_INT,
                 my_partner, 0, neighbors_list, list_size,
                 MPI_INT, my_partner, 0, comm, &status);

    if(my_slope == 0)
    {
        Merge_split_high(my_list, neighbors_list, list_size);
    }
    else
    {
        Merge_split_low(my_list, neighbors_list, list_size);
    }
}