1
votes

TL;DR I believe I am incorrectly transmitting a string with MPI_Send. What is the best way to send a string?


I'm trying to send a string from the master to the slave processes but I believe it's not sending the entire string or not reconstructi9ng it properly at the slave end.

Master MPI_Send code:

MPI_Send(&parent, sizeof(char) * selection::target_length(), MPI_BYTE, i, MSEND, MPI_COMM_WORLD);

Slave MPI_Recv Code:

char parentChars [selection::target_length()];

MPI_Recv(&parentChars, sizeof(char) * selection::target_length(), MPI_BYTE, 0, MSEND, MPI_COMM_WORLD, &status);

parent = parentChars;

The assertion assert(target.length() == candidate.length()); fails and gives the following results:

weasel: weaselparallel.cpp:34: static int selection::fitness(std::string): Assertion `target.length() == candidate.length()' failed.

↑ This is output for each slave process

And then there's the segmentation fault that I assume occurs because of the incorrectly transmitted string:

mpiexec noticed that process rank 2 with PID 23531 on node node02.emperor exited on signal 11 (Segmentation fault).

6 total processes killed (some possibly by mpiexec during cleanup)
1
sizeof(char) is 1. - Carl Norum
Can you show the definition of parent? - Carl Norum
It looks here like you're mixing C and C++, too. parentChars looks like a C VLA, but you have :: operators in there. Which is it, C or C++? - Carl Norum
You should know that this isn't pure C++ code, variable length arrays (i.e. your parentChars array) is not part of C++, though some compilers allow it as an extension. You should not use it if you want your code to be portable. - Some programmer dude
The :: operator is for accessing a public class used as a handler. I know the code is pretty horrible but it's the skeleton code I was given and have to use. I've done the rest but just need to get the send right. parent is just declared as a string ie: string parent; and parentChars is declared like this: char parentChars [selection::target_length()];. Portability isn't an issue. Thanks for your feedback so far. - Jarrod Cabalzar

1 Answers

0
votes
  • Check definition of MPI_Send and MPI_Recv, I think something is wrong with your first argument.
  • Try omitting the ampersand symbol( & ) of parent and/or parentChars depends on your definition
  • also check the status( speifically, MPI_ERROR ) return from MPI_Recv for more information on what is happening