Example #1
0
/*--------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   int n;                      /* Total number of elements           */
   int loc_n;                  /* Number of elements on each process */
   int* loc_array;             /* Storage on each process for loc_n ints */

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

   Get_args(argc, argv, &n);
   loc_n = n/comm_sz;         /* n should be evenly divisible by comm_sz */

   loc_array = malloc(loc_n*sizeof(int));
   if (my_rank == 0) scratch = malloc(n*sizeof(int));
   
   Build_cyclic_mpi_type(loc_n);

   Get_array(loc_array, n, loc_n);
// Local_print(loc_array, loc_n);
// if (my_rank == 0) printf("\n");
   Print_loc_arrays(loc_array, n, loc_n);
   if (my_rank == 0) printf("\n");
   Print_array(loc_array, n, loc_n);

   MPI_Type_free(&cyclic_mpi_t);
   free(loc_array);
   if (my_rank == 0) free(scratch);

   MPI_Finalize();

   return 0;
}  /* main */
Example #2
0
int main(int argc, char* argv[]) {
    int *loc_arr;
    int n, loc_n, p, my_rank;
    MPI_Comm comm;
    
    MPI_Init(&argc, &argv);
    comm = MPI_COMM_WORLD;
    MPI_Comm_size(comm, &p);
    MPI_Comm_rank(comm, &my_rank);
    
    n = Read_n(my_rank, comm);
    loc_n = n/p;
    loc_arr = malloc(loc_n*sizeof(int));
    
    
#  ifdef DEBUG
    printf("Proc %d > p = %d, n = %d, loc_n = %d\n",
           my_rank, p, n, loc_n);
#  endif
    
    Get_array(loc_arr, n, loc_n, my_rank, comm);
    Print_loc_array(loc_arr, loc_n, my_rank);
    Print_array(loc_arr, n, loc_n, my_rank, comm);
    
    free(loc_arr);
    
    MPI_Finalize();
    return 0;
}  /* main */
Example #3
0
/*------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   long       thread;
   pthread_t* thread_handles;

   if (argc != 2) Usage(argv[0]);
   thread_count = strtol(argv[1], NULL, 10);
   thread_handles = malloc(thread_count*sizeof(pthread_t));

   printf("Enter n\n");
   scanf("%d", &n);
   
   x = malloc(n*sizeof(double)); /* one array */
   y = malloc(n*sizeof(double)); /* second array */ 

   
   Read_array("Enter the first matrix", x);
   
   Read_array("Enter the second matrix", y);
   
   printf("Please enter a numerical value for alpha\n");
   scanf("%lf", &alpha);
   
   for (thread = 0; thread < thread_count; thread++)
      pthread_create(&thread_handles[thread], NULL,
         DAXPY, (void*) thread);

   for (thread = 0; thread < thread_count; thread++)
      pthread_join(thread_handles[thread], NULL);
   
   
   Print_array("The answer is", y);

   free(x);
   free(y);
   free(thread_handles);

   return 0;
}  /* main */