#include int min(int a1, int a2) { if (a1 < a2) return a1; else return a2; } int main(int argc, char* argv[ ]) { // cyclic information int cyclicLB; int cyclicUB; int cyclicStride; int cyclicEltCnt; int gub[ ] = {200, 101}; // num array elements for each problem int nprocs[ ] = {8, 7}; // num procs for each problem int bs[ ] = {5, 3}; // block size for each problem // block part for (int i = 0; i < 2; i++) { printf("\n\n\n Block distribution, the number of processors is %d, global array size is %d\n", nprocs[i], gub[i]); for (int pid = 0; pid < nprocs[i]; pid++) { int blockLB; int blockUB; int localBS; // compute block distribution parameters blockLB = pid*gub[i]/nprocs[i]; blockUB = min(gub[i], (pid+1)*gub[i]/nprocs[i] - 1); localBS = blockUB - blockLB + 1; printf("\nblock: on processor %d, the local bounds are [%d:%d], and the global bounds are [%d:%d]", pid, 0, localBS, blockLB, blockUB); } } // cyclic part for (int i = 0; i < 2; i++) { printf("\n\n\n Cyclic distribution, number of processors is %d, global array size is %d\n", nprocs[i], gub[i]); for (int pid = 0; pid < nprocs[i]; pid++) { int cyclicLB; int cyclicUB; int cyclicStride; int cyclicEltCnt; cyclicLB = pid; cyclicEltCnt = (int) (((float) (gub[i] -1 - pid) / nprocs[i])); // + 0.5)); cyclicUB = min(pid+(cyclicEltCnt)*nprocs[i], gub[i]-1); printf("\ncyclic: on processor %d, the local bounds are [%d:%d], and the global bounds are [%d:%d:%d]", pid, pid, cyclicEltCnt+pid, cyclicLB, cyclicUB, nprocs[i]); } } // block-cyclic part for (int i = 0; i < 2; i++) { printf("\n\n\n Block-cyclic distribution, number of processors is %d, global array size is %d, the blocksize is %d\n", nprocs[i], gub[i], bs[i]); for (int pid = 0; pid < nprocs[i]; pid++) { printf("On pid %d, elements are: ", pid); for (int b = bs[i]*pid; b < gub[i]; b+= nprocs[i]*bs[i]) { printf("[%d,%d]", b, min(b+bs[i]-1, gub[i]-1)); if (b+nprocs[i]*bs[i] <= gub[i]) printf(", "); } printf("\n"); } } return 0; }