hello i am trying to broadcast some values, but i dont see the function of broadcast happening....the code i had written to broadcast is

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>


int main(int argc, char *argv[])
{
int rank, size, i, n, num, send;


n=atoi(argv[1]);


MPI_Init(&argc, &argv);


MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);



if(rank==0)
{
num=1234;
send=rank;


MPI_Bcast(&num, 4, MPI_INT, rank, MPI_COMM_WORLD);
MPI_Bcast(&send, 4, MPI_INT, rank, MPI_COMM_WORLD);
printf("broadcasted num : %d send : %d", num, send);
}


printf("\n rank %d : num %d : send %d", rank, num, send);


MPI_Finalize();
return 0;
}

Recommended Answers

All 3 Replies

Member Avatar for Mouche

MPI_Bcast() needs to be called in all processes, not just rank 0. It acts as the send and receive function for broadcasts.

MPI_Bcast() needs to be called in all processes, not just rank 0. It acts as the send and receive function for broadcasts.

i tried doing it but sometimes before the next function related to the data broadcasted is reached the process is executing it, so i tried to put a barrier, but its giving an error so i found that barrier can't be used if i have to broadcast something. donno how to make other processes continue the execution until the broadcasted message is reached.

Member Avatar for Mouche

I don't quite understand your problem. What error were you getting?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.