Last active
February 23, 2024 07:55
-
-
Save qqwqqw689/813d92443dbc736d20a63f193c90e565 to your computer and use it in GitHub Desktop.
MPI-split-loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <mpi.h> | |
int main (int argc, char *argv[]) | |
{ | |
int rank, comm_size; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
MPI_Comm_size(MPI_COMM_WORLD, &comm_size); | |
for (int i = 0; i < 17; i++) | |
{ | |
if (i%comm_size != rank) continue; | |
printf("rank %i working on element %i\n", rank, i); | |
// rest of work ... | |
} | |
MPI_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment