c - MPI_Send to single variable destination -


i want send mpi_send message single variable host. mean dont know rank of host want send message to, @ compile time.

so naturally, wrote following:

mpi_send(&myintdata, 1, mpi_int, target_host, my_msgtag, mpi_comm_world);

where target_host integer, containing rank of destination.

when execute this, mpi ends timeout. if put printf before , after send, printf happens before displayed, means program stuck in mpi_send statement.

if change target_host 1, example, second printf displays , works fine.

so.. doesnt mpi support variable in destintation rank identifier?

what problem here?

mpi allow variable in rank argument. consider following example

#include <stdio.h> #include <stdlib.h> #include <mpi.h> #include <unistd.h> #include <string.h>  int main(int argc, char** argv){      int rank = 0;     int comm_size = 0;      mpi_init(&argc, &argv);      mpi_comm_size(mpi_comm_world, &comm_size);     mpi_comm_rank(mpi_comm_world, &rank);      printf("rank %d starting\n", rank);     unsigned int i;      if(rank == 0){          for(i = 1; < comm_size; i++){              char mystring[] = "string";             int len = strlen(mystring);             printf("sending %d\n", i);             mpi_send(mystring, len, mpi_char, i, 0, mpi_comm_world);          }     }     else{         char rbuf[4096];                     mpi_recv((void*)rbuf, 4096, mpi_char, mpi_any_source, 0, mpi_comm_world, mpi_status_ignore);         printf("[%d] got %s in recv\n", rank, rbuf);     }       mpi_finalize();  } 

compile mpicc -o my_program example.c , make sure run program mpiexec -n 2 my_program or number greater 2 -n parameter (which number of processes use). in case, need send rank 0 host message. then, in rank 0, need loop receive each rank. following

if(rank != 0){     mpi_send(host, host_msg_len, mpi_char, 0, 0, mpi_comm_world); } else{     for(i = 1; < comm_size; i++){         char rbuf[4096];                     mpi_recv((void*)rbuf, 4096, mpi_char, i, 0, mpi_comm_world, mpi_status_ignore);          if(strcmp(rbuf, target_host) == 0){             target_rank = i;             break;         }     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -