Skip to content

Instantly share code, notes, and snippets.

@wtneal
Created September 24, 2014 23:49
Show Gist options
  • Save wtneal/f490b06def383b933ec9 to your computer and use it in GitHub Desktop.
Save wtneal/f490b06def383b933ec9 to your computer and use it in GitHub Desktop.
/* Set the chunk size (amount of work for each process */
chunk = dim / sqrt(num_proc);
/* Get the process id */
rank = getpid() - base_pid;
/* Calculate the offsets for the result matrix */
offset_row = (rank % (dim / chunk)) * chunk;
offset_col = floor((rank * chunk) / dim) * chunk;
/* Multiply the matricies */
for (i = offset_row; i < (offset_row + chunk); i++) {
for (j = offset_col; j < (offset_col + chunk); j++) {
for (k = 0; k < dim; k++) {
shmatrices->C[i][j] += shmatrices->A[i][k] * shmatrices->B[k][j];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment