Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mpi.h"
- #include <stdio.h>
- #define MSG_HELLO 100
- #define MSG_SIZE 100
- int x = 250;
- int main(int argc, char **argv)
- {
- int rank,size,receiver=0;
- int msg[MSG_SIZE];
- int division[MSG_SIZE];
- for(int i =0; i< MSG_SIZE; i++) {
- division[i] = -1;
- }
- int counter = 0;
- MPI_Status status;
- MPI_Init(&argc, &argv);
- MPI_Comm_rank( MPI_COMM_WORLD, &rank );
- MPI_Comm_size( MPI_COMM_WORLD, &size );
- for(int i= (x/size)*rank; i< ((x/size))*(rank+1); i++) {
- int reszta = 0;
- if(i != 0) {
- reszta = x%i;
- }
- if(reszta == 0) {
- division[counter] = i;
- counter++;
- }
- }
- if ( rank == receiver)
- {
- for(int i=0; i <size-1; i++) {
- MPI_Recv(msg, MSG_SIZE, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
- for(int j =0; j < MSG_SIZE; j++) {
- if(msg[j] != -1) {
- division[counter] = msg[j];
- counter++;
- }
- }
- }
- for(int i=0; i< counter; i++) {
- printf("dzielnik %d\n ", division[i]);
- }
- }
- else
- {
- MPI_Send(division, MSG_SIZE, MPI_INT, receiver, MSG_HELLO, MPI_COMM_WORLD );
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement