Beispiel #1
0
/* ============================================================================
Function:     =        Scatter
Purpose:      =        Generate list on process 0, then scatter to others.
==============================================================================
Input arg:  =        1. generate_list_flag: Flag for list creation type.
            =        2. my_list[]: A pointer to an array.
            =        3. neighbors_list[]: A pointer to an array.
            =        4. merge_list[]: A pointer to an array.
            =        5. global_list_size: The size of the input array.
            =        6. list_size: The size of the processors array.
            =        7. my_rank: The size of the processors array.
            =        8. comm: The mpi communicator channel.
=========================================================================== */
void Scatter(char generate_list_flag, int my_list[], int neighbors_list[],
                int merge_list[], int global_list_size, int list_size,
                int my_rank, MPI_Comm comm)
{
    int *input_list = malloc(global_list_size*sizeof(int));;

    if (my_rank == 0)
    {
        if (generate_list_flag == 'g')
        {
            printf("Generating the list... \n");
            Gen_list(input_list, global_list_size);
        }
        else
        {
            printf("Please read in matrix into process 0.\n");
            Read_list("Enter the list", input_list, global_list_size);
        }

        Print_list_once("Orginal list:", input_list, global_list_size);
    }

    MPI_Scatter(input_list, list_size, MPI_INT,
                my_list, list_size, MPI_INT, 0, comm);

    free(input_list);
}  /* Scatter */
Beispiel #2
0
/*--------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   long       thread;
   pthread_t* thread_handles; 
   double     start, finish;
   int        gen_list, output_list;

   Get_args(argc, argv, &gen_list, &output_list);

   thread_handles = malloc (thread_count*sizeof(pthread_t));
// pthread_barrier_init(&barrier, NULL, thread_count);
   pthread_mutex_init(&bar_mutex, NULL);
   pthread_cond_init(&bar_cond, NULL);
   list1 = malloc(n*sizeof(int));
   list2 = malloc(n*sizeof(int));
   l_a = list1;
   l_b = list2;

   if (gen_list)
      Gen_list(list1, n);
   else
      Read_list("Enter the list", list1, n);
   if (output_list)
      Print_list("The input list is", list1, n);

   GET_TIME(start);
   for (thread = 0; thread < thread_count; thread++)
      pthread_create(&thread_handles[thread], NULL,
          Bitonic_sort, (void*) thread);

   for (thread = 0; thread < thread_count; thread++) 
      pthread_join(thread_handles[thread], NULL);
   GET_TIME(finish);
   printf("Elapsed time = %e seconds\n", finish - start);

   if (output_list)
      Print_list("The sorted list is", l_a, n);

   free(list1);
   free(list2);
// pthread_barrier_destroy(&barrier);
   pthread_mutex_destroy(&bar_mutex);
   pthread_cond_destroy(&bar_cond);
   free(thread_handles);
   return 0;
}  /* main */