Exemplo n.º 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 */
Exemplo n.º 2
0
/*-----------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   int  n;
   char g_i;
   int* a;
   double start, finish;

   Get_args(argc, argv, &n, &g_i);
   a = malloc(n*sizeof(int));
   if (g_i == 'g') {
      Generate_list(a, n);
#     ifdef DEBUG
      Print_list(a, n, "Before sort");
#     endif
   } else {
      Read_list(a, n);
   }

   start = omp_get_wtime();
   Odd_even(a, n);
   finish = omp_get_wtime();

#  ifdef DEBUG
   Print_list(a, n, "After sort");
#  endif
   
   printf("Elapsed time = %e seconds\n", finish - start);

   free(a);
   return 0;
}  /* main */
Exemplo n.º 3
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 */
Exemplo n.º 4
0
/*-------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   int my_rank, p;
   char g_i;
   int *local_A;
   int global_n;
   int local_n;
   MPI_Comm comm;
   double start, finish;

   MPI_Init(&argc, &argv);
   comm = MPI_COMM_WORLD;
   MPI_Comm_size(comm, &p);
   MPI_Comm_rank(comm, &my_rank);

   Get_args(argc, argv, &global_n, &local_n, &g_i, my_rank, p, comm);
   local_A = (int*) malloc(local_n*sizeof(int));
   if (g_i == 'g') {
      Generate_list(local_A, local_n, my_rank);
   } else {
      Read_list(local_A, local_n, my_rank, p, comm);
   }
#  ifdef DEBUG
   Print_local_lists(local_A, local_n, my_rank, p, comm);
#  endif

   start = MPI_Wtime();
   Sort(local_A, local_n, my_rank, p, comm);
   finish = MPI_Wtime();
   if (my_rank == 0)
      printf("Elapsed time = %e seconds\n", finish-start);

#  ifdef DEBUG
   Print_local_lists(local_A, local_n, my_rank, p, comm);
   fflush(stdout);
#  endif

   Print_global_list(local_A, local_n, my_rank, p, comm);

   free(local_A);

   MPI_Finalize();

   return 0;
}  /* main */
Exemplo n.º 5
0
/*-----------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   long  n;
   char g_i;
   long* a;

   Get_args(argc, argv, &n, &g_i);
   a = malloc(n*sizeof(long));
   if (g_i == 'g') {
      Generate_list(a, n);
      Print_list(a, n, "Before sort");
   } else {
      Read_list(a, n);
   }

   Bubble_sort(a, n);

   Print_list(a, n, "After sort");
   
   free(a);
   return 0;
}  /* main */
Exemplo n.º 6
0
/*-----------------------------------------------------------------*/
int main(int argc, char* argv[]) {
    int  n;
    char g_i;
    int* a;

    Get_args(argc, argv, &n, &g_i);
    a = (int*) malloc(n*sizeof(int));
    if (g_i == 'g') {
        Generate_list(a, n);
        Print_list(a, n, "Before sort");
    } else {
        Read_list(a, n);
    }

    Odd_even_sort(a, n);

    Print_list(a, n, "After sort");

    free(a);
    return 0;
}  /* main */