c++ - Weird output in MPI using MPI_Comm_spawn to spawn processes -


amaey helped me fix problem.

i trying learn mpi_comm_spawn function spawn processes, because i'm working on migrating project pvm mpi. found example program here. decided change bit make parent process send message 2 child processes, , make child processes output message. thing child process rank 0 doesn't receive message properly, receives part of it, while child process rank 1 receives message , outputs normally. can please explain why happening, i'm doing wrong or how can fix this. lot can help!

#include "mpi.h" #include <stdio.h> #include <stdlib.h> #include <iostream>  #define num_spawns 2 // based on example from: http://mpi.deino.net/mpi_functions/mpi_comm_spawn.html int main( int argc, char *argv[] ) {     int my_rank;     int size;     int np = num_spawns;     int errcodes[num_spawns];     mpi_comm parentcomm, intercomm;     char greeting[100];     char greeting2[100];     char greeting3[100];     mpi_init( &argc, &argv );     mpi_status stat;     mpi_comm_get_parent( &parentcomm );     if (parentcomm == mpi_comm_null)     {         /* create 2 more processes - example must called spawn_example.exe work. */         mpi_comm_spawn( "spawn_example", mpi_argv_null, np, mpi_info_null, 0, mpi_comm_world, &intercomm, errcodes );         mpi_comm_rank(mpi_comm_world, &my_rank);         mpi_comm_size(mpi_comm_world, &size);         // called jreeting because process 0 in new mpi_comm_world receiving part of string.         sprintf(greeting2, "jreeting master1 %d of %d\n", my_rank, size);         sprintf(greeting3, "greeting master2 %d of %d\n", my_rank, size);         for(int = 0; i<np;i++)         {             if(i == 0)             {                 mpi_send(greeting2, strlen(greeting)+1, mpi_byte, i,1,intercomm);             }             if(i == 1)             {                 mpi_send(greeting3, strlen(greeting)+1, mpi_byte, i,1,intercomm);             }             mpi_recv(greeting, sizeof(greeting), mpi_byte, i, 1, intercomm, &stat);             fputs (greeting, stdout);         }     }     else     {         mpi_comm_rank(mpi_comm_world, &my_rank);         mpi_comm_size(mpi_comm_world, &size);         if(my_rank == 0)         {             mpi_recv(greeting2, sizeof(greeting2), mpi_byte, 0, 1, parentcomm, &stat);             std::cout << greeting2 << "\n";         }         if(my_rank == 1)         {             mpi_recv(greeting3, sizeof(greeting3), mpi_byte, 0, 1, parentcomm, &stat);             std::cout << greeting3 << "\n";         }         sprintf(greeting, "hello world: processor %d of %d\n", my_rank, size);         mpi_send(greeting, strlen(greeting)+1, mpi_byte, 0,1,parentcomm);     }     fflush(stdout);     mpi_finalize();     return 0; } 

when compile have warnings...:

hrognkelsi:mpi_tutorial gumundureinarsson$ mpic++ spawn_example.cc -o spawn_example spawn_example.cc: in function ‘int main(int, char**)’: spawn_example.cc:24: warning: deprecated conversion string constant ‘char*’ 

when run:

hrognkelsi:mpi_tutorial gumundureinarsson$ mpirun spawn_example jre hello world: processor 0 of 2 greeting master2 0 of 1 hello world: processor 1 of 2 

as can see, child process outputs jre instead of jreeting master1 0 of 1 supposed to. what's going on? why work other child process?

look @ line: mpi_send(greeting2, strlen(greeting)+1, mpi_byte, i,1,intercomm);

so unless i've overlooked isn't 'strlen(greeting)' 0. putting more things in send buffer 1 element. think want put 'strlen(greeting2)' in there.

what think happening parent process sends truncated string , gets reply process 0, populates 'greeting'. on second mpi_send 'sizeof(greeting)' non-zero hence you're able send entire message through.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -