Beispiel #1
0
/*-------------------------------------------------------------------*/
int main(void) {
   double* A = NULL;
   double* x = NULL;
   double* y = NULL;
   int m, n;

   Get_dims(&m, &n);
   A = malloc(m*n*sizeof(double));
   x = malloc(n*sizeof(double));
   y = malloc(m*sizeof(double));
   if (A == NULL || x == NULL || y == NULL) {
      fprintf(stderr, "Can't allocate storage\n");
      exit(-1);
   }
   Read_matrix("A", A, m, n);
#  ifdef DEBUG
   Print_matrix("A", A, m, n);
#  endif
   Read_vector("x", x, n);
#  ifdef DEBUG
   Print_vector("x", x, n);
#  endif

   Mat_vect_mult(A, x, y, m, n);

   Print_vector("y", y, m);

   free(A);
   free(x);
   free(y);
   return 0;
}  /* main */
Beispiel #2
0
int main(int argc, char *argv[]) {
   double* A = NULL;
   double* x = NULL;
   double* y = NULL;
   long long int size;
   int m, n;

   n= atoi(argv[1]);
   m= n;

   size=m*n*sizeof(double);
   A = malloc(size);
   x = malloc(n*sizeof(double));
   y = malloc(m*sizeof(double));
   
   Read_matrix("A", A, m, n);
   Read_vector("x", x, n);

   gettimeofday(&start_time, NULL);
   Mat_vect_mult(A, x, y, m, n);

   gettimeofday(&end_time, NULL);
   print_times();

   free(A);
   free(x);
   free(y);
   return 0;
}  /* main */
Beispiel #3
0
int main(void) {
    float* x;
    float* y;
    int    n;
    float  dot;

    printf("Enter the order of the vectors\n");
    scanf("%d", &n);
    x = malloc(n*sizeof(float));
    y = malloc(n*sizeof(float));
    Read_vector("the first vector", x, n);
    Read_vector("the second vector", y, n);

    dot = Serial_dot(x, y, n);
    printf("The dot product is %f\n", dot);

    free(x);
    free(y);
    return 0;
}  /* main */
Beispiel #4
0
int main(void) {
    float*   local_x;
    float*   local_y;
    int      n;
    int      local_n;  /* = n/p */
    float    dot;
    int      p;
    int      my_rank;
    MPI_Comm comm;

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

    if (my_rank == 0) {
        printf("Enter the order of the vectors\n");
        scanf("%d", &n);
    }
    MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
    local_n = n/p;

    local_x = malloc(local_n*sizeof(float));
    local_y = malloc(local_n*sizeof(float));
    Read_vector("the first vector", local_x, local_n, n, my_rank, comm);
    Read_vector("the second vector", local_y, local_n, n, my_rank, comm);

    dot = Parallel_dot(local_x, local_y, local_n, comm);

    Print_results(dot, p, my_rank, comm);

    free(local_x);
    free(local_y);
    MPI_Finalize();

    return 0;
}  /* main */
/*------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
    int     thread_count;
    int     m, n;
    double* A;
    double* x;
    double* y;

    Get_args(argc, argv, &thread_count, &m, &n);

    A = malloc(m*n*sizeof(double));
    x = malloc(n*sizeof(double));
    y = malloc(m*sizeof(double));

#  ifdef DEBUG
    Read_matrix("Enter the matrix", A, m, n);
    Print_matrix("We read", A, m, n);
    Read_vector("Enter the vector", x, n);
    Print_vector("We read", x, n);
#  else
    Gen_matrix(A, m, n);
    /* Print_matrix("We generated", A, m, n); */
    Gen_vector(x, n);
    /* Print_vector("We generated", x, n); */
#  endif

    Omp_mat_vect(A, x, y, m, n, thread_count);

#  ifdef DEBUG
    Print_vector("The product is", y, m);
#  else
    /* Print_vector("The product is", y, m); */
#  endif

    free(A);
    free(x);
    free(y);

    return 0;
}  /* main */
Beispiel #6
0
main(int argc, char* argv[]) {
    int        p;
    int        my_rank;
    MATRIX_T   A_local;
    float      x_local[MAX_DIM];
    float      b_local[MAX_DIM];
    int        n;
    float      tol;
    int        max_iter;
    int        converged;

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

    if (my_rank == 0) {
        printf("Enter n, tolerance, and max number of iterations\n");
        scanf("%d %f %d", &n, &tol, &max_iter);
    }
    MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Bcast(&tol, 1, MPI_FLOAT, 0, MPI_COMM_WORLD);
    MPI_Bcast(&max_iter, 1, MPI_INT, 0, MPI_COMM_WORLD);

    Read_matrix("Enter the matrix", A_local, n, my_rank, p);
    Read_vector("Enter the right-hand side", b_local, n, my_rank, p);

    converged = Parallel_jacobi(A_local, x_local, b_local, n,
        tol, max_iter, p, my_rank);

    if (converged)
        Print_vector("The solution is", x_local, n, my_rank, p);
    else
        if (my_rank == 0)
            printf("Failed to converge in %d iterations\n", max_iter);

    MPI_Finalize();
}  /* main */