Skip to content

Instantly share code, notes, and snippets.

@qqwqqw689
Last active February 23, 2024 07:55
Show Gist options
  • Save qqwqqw689/813d92443dbc736d20a63f193c90e565 to your computer and use it in GitHub Desktop.
Save qqwqqw689/813d92443dbc736d20a63f193c90e565 to your computer and use it in GitHub Desktop.
MPI-split-loop
#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