Last active
November 9, 2022 14:22
-
-
Save hamidhaghdoost/aac4198dfb18a5301ffec76e6d486010 to your computer and use it in GitHub Desktop.
MPI_Scatter example in c
This file contains 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
// This code creates an array as count as our processes count and send every value of array to coresponding process and prints it in process... | |
#include "stdafx.h" | |
#include <iostream> | |
#include <time.h> | |
using namespace std; | |
#include "mpi.h" | |
#pragma comment(lib, "msmpi.lib") | |
void main(int argc, char *argv[]) | |
{ | |
int myid, numprocs; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size(MPI_COMM_WORLD, &numprocs); | |
MPI_Comm_rank(MPI_COMM_WORLD, &myid); | |
int *InputArr = new int[numprocs]; | |
if(myid == 0) | |
{ | |
srand(time(NULL)); | |
for(int i = 0; i < numprocs; i++) | |
InputArr[i] = rand() % 100; | |
} | |
int *rec = new int[1]; | |
MPI_Scatter(InputArr, 1, MPI_INT, rec, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
printf("data in process[%d] = %d", myid, rec[0]); | |
MPI_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment