Skip to content

Instantly share code, notes, and snippets.

@rainiera
Created February 2, 2016 06:07
Show Gist options
  • Save rainiera/2a5afe763c13168c5810 to your computer and use it in GitHub Desktop.
Save rainiera/2a5afe763c13168c5810 to your computer and use it in GitHub Desktop.
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int rank;
int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
int slice = 45200/32;
// Let each processor search the space [1412*rank, 1412*(rank+1)]
int i = 0;
for (i = slice*rank; i < slice*(rank+1); i++) {
if (i != 0 && i != 1 && (2000000111 % i) == 0) {
printf("%d is a factor of 2,000,000,111.\n", i);
return 1;
}
}
MPI_Finalize();
printf("Yes, 2,000,000,111 is prime.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment