Changeset 5710 in /cluster/svnroot


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

assign balance of rows to last rank

File:
1 edited

Legend:

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

    r5709 r5710  
    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);
     
    5858    }
    5959
    60     dst_m.rows = m1.rows;
    61     dst_m.cols = m2.cols;
    6260
    6361    m1.matrix       = safe_malloc_int(
     
    6967            "Allocating second matrix"
    7068            );
    71     dst_m.matrix    = safe_malloc_int(
    72             dst_m.rows*dst_m.cols,
    73             "Allocating destination matrix"
    74             );
    7569
    7670    if(rank == FIRST_RANK) {
     
    7973        init_matrix(&m1,random_seeds);
    8074        init_matrix(&m2,random_seeds);
     75
     76        // Declare and allocate full destination matrix
     77        // 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                );
    8185
    8286        if(print) {
     
    102106    stride = m1.rows/size;
    103107    start_row = rank*stride;
    104     stop_row = stride*(rank+1);
     108
     109    // Assign an even number of rows to each rank, except for the last rank
     110    // whiich gets the remainder
     111    if(rank<(size-1)) {
     112        stop_row = stride*(rank+1);
     113    }
     114    else {
     115        stop_row = m1.rows;
     116    }
    105117#ifdef DEBUG
    106118    fprintf(stderr,"Rank %d - Stride %u, start_row %u, stop_row %u\n",
Note: See TracChangeset for help on using the changeset viewer.