#include #include #include "mpi.h" #define MAXTAM 20000000 #define BASE 915000 int main(int argc,char** argv) { unsigned long int i; int * vet; int cont, rank, size; double inittime,totaltime; vet = calloc (MAXTAM,sizeof(int)); cont = 0; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&size); inittime = MPI_Wtime(); for (i=(rank*(MAXTAM/size)); i<((rank+1)*(MAXTAM/size)); i++) { if ((i%BASE)==0) { vet[i] = 1; cont ++; } } totaltime = MPI_Wtime() - inittime; if (rank == 0) { printf ("Tempo final de execucao = %f\n", totaltime); } printf ("Processo %d: foram encontrados %d multiplos de %u\n",rank,cont, BASE); for (i=(rank*(MAXTAM/size)); i<((rank+1)*(MAXTAM/size)); i++) { if (vet[i] == 1) { printf ("Processo %d: %u eh multiplo\n", rank, i); } } MPI_Finalize(); return 0; }