Changeset 5712 in /cluster/svnroot


Ignore:
Timestamp:
May 26, 2016 8:59:29 PM (5 years ago)
Author:
skylar
Message:

local product matrix should start at 0

Location:
bccd-ng/bw-institute/2016/day06/matmul
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/bw-institute/2016/day06/matmul/matmul.c

    r5708 r5712  
    144144            fprintf(stderr,"Calculating (%d,%d)\n",dst_row,dst_col);
    145145#endif
    146             dst_coord = coord(dst_m,dst_row,dst_col);
     146            // Assign destination coordinates based on the start row offset
     147            dst_coord = coord(dst_m,(dst_row-start_dst_row),dst_col);
    147148            // Make sure destination matrix is initialized
    148149            dst_m->matrix[dst_coord] = 0;
  • bccd-ng/bw-institute/2016/day06/matmul/mpi.c

    r5711 r5712  
    1212    unsigned int start_row,stop_row,stride;
    1313    bool print;
    14     struct matrix m1,m2,dst_m;
     14    struct matrix m1,m2,local_dst_m;
    1515
    1616    MPI_Init(&argc,&argv);
     
    5959
    6060
    61     dst_m.rows = m1.rows;
    62     dst_m.cols = m2.cols;
    63 
    6461    m1.matrix       = safe_malloc_int(
    6562            m1.rows*m1.cols,
     
    6966            m2.rows*m2.cols,
    7067            "Allocating second matrix"
    71             );
    72     dst_m.matrix    = safe_malloc_int(
    73             dst_m.rows*dst_m.cols,
    74             "Allocating destination matrix"
    7568            );
    7669
     
    8376        // Declare and allocate full destination matrix
    8477        // Will be populated via MPI_Gather
     78        struct matrix dst_m;
     79        dst_m.rows = m1.rows;
     80        dst_m.cols = m2.cols;
     81        dst_m.matrix    = safe_malloc_int(
     82                dst_m.rows*dst_m.cols,
     83                "Allocating destination matrix"
     84                );
    8585
    8686        if(print) {
     
    104104
    105105    // Calculate row offset in product matrix to start and stop calculation
    106     stride = m1.rows/size;
    107     start_row = rank*stride;
     106    stride                  = m1.rows/size;
     107    start_row               = rank*stride;
    108108
    109109    // Assign an even number of rows to each rank, except for the last rank
     
    115115        stop_row = m1.rows;
    116116    }
     117
     118    // Only need to allocate enough for the local computation
     119    local_dst_m.cols        = m2.cols;
     120    local_dst_m.rows        = (stop_row-start_row),
     121    local_dst_m.matrix      = safe_malloc_int(
     122            local_dst_m.rows*local_dst_m.cols,
     123            "Allocating local destination matrix"
     124            );
     125
    117126#ifdef DEBUG
    118127    fprintf(stderr,"Rank %d - Stride %u, start_row %u, stop_row %u\n",
    119128            rank,stride,start_row,stop_row);
    120129#endif
    121     matmul(&m1,&m2,&dst_m,start_row,stop_row);
     130    matmul(&m1,&m2,&local_dst_m,start_row,stop_row);
     131
     132#ifdef DEBUG
     133    fprintf(stderr,"Rank %d local destination matrix:\n",rank);
     134    print_matrix(&local_dst_m);
     135#endif
    122136
    123137    MPI_Finalize();
    124138
     139    free(m1.matrix);
     140    free(m2.matrix);
     141    free(local_dst_m.matrix);
     142
    125143    exit(EXIT_SUCCESS);
    126144}
Note: See TracChangeset for help on using the changeset viewer.