0

I need to Scatter my string array. The problem is, I'm not sure, how to do it correctly, I'm used to it only in C.

My program has the array scatterArr which contains several strings (one for every process, so this number is changing). String length is changing too - my program loads text from a file, so, it depends on the word count.

Example of scatterArr (just for this example I assigned strings manually):

int world_size = 4; // number of processes

string * scatterArr = new string[world_size];
scatterArr[0] = "Hello;How;";
scatterArr[1] = "I;are;";
scatterArr[2] = "am;you;";
scatterArr[3] = "John;"; // only one word loaded

And now Scatter():

int arrCharCount = 21;

char * recvArr = new char[ ??? ]; // I'm not sure what size to expect
COMM_WORLD.Scatter( scatterArr, arrCharCount, CHAR, recvArr, ???, CHAR, 0 );

Here I'm not sure about using char * as a recvArr type (maybe string would be better?) and about the size I should allocate for my recvArr array.

So, could you please help me with this and explain it, if possible, more thoroughly? I've found this question, but I've not understood, how can I determine the size of recvArr when I don't know the exact number of CHARS which will come.

Community
  • 1
  • 1
Eenoku
  • 2,741
  • 4
  • 32
  • 64
  • You cannot scatter strings like this because they are not guaranteed to be stored at adjacent addresses. – sharptooth Feb 17 '15 at 12:46
  • Ok, how should I scatters string like this? :D – Eenoku Feb 17 '15 at 12:50
  • 2
    Well, you could for example, allocate a N*M array and assume that every row of that array is a separate string and then you would scatter the array row-wise. – sharptooth Feb 17 '15 at 12:52

0 Answers0