title: MPI SEND / RECV ARRAY OF STRINGS in standard C
body: <p>Okay, so I've been struggling with this problem for a few days. I'm trying to distribute an array of strings to various nodes in my Raspberry Pi 4 computing cluster using its most recent version of openmpi. I figured this was a perfect way to learn how clustering works, but I am completely lost at this point and have no direction. For the current set of code, I'm getting a segmentation fault, but when I follow other sets of instructions, I will sometimes receive only the first character of the first string, and null every other character. Those times are when instead of the current array send line, the first argument would be &amp;(NodeOne[0][0]). Most of these sets of instructions are 6-9 years old.
  Does anyone have any ideas to make the code do more than compile?</p>
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;curl/curl.h&gt;
  #include &lt;string.h&gt;
  #include &lt;mpi.h&gt;
  
  #define NUMC 4
  
  void *set_Stats(void *z);
  struct Tickers {
      char ** x;
      int length;
  };
  struct Tickers getTickers()
  {
      CURL *curl = curl_easy_init();
      char line[300];
      struct Tickers tickers;
      int length = 0;
      char url[60] = &quot;ftp://ftp.nasdaqtrader.com/symboldirectory/nasdaqtraded.txt&quot;;
      if(curl)
      {
          FILE *temp = tmpfile();
          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)temp);
          curl_easy_perform(curl);
          if(temp)
          {
              rewind(temp);
              char c = fgetc(temp);
              while (fgets(line,sizeof(line),temp)) 
              {
                  length++;
              }
              rewind(temp);
              length = length - 2;
              tickers.length = length;
              tickers.x = malloc(length * sizeof(char*));
              fgets(line, sizeof(line), temp);
              fgets(line, sizeof(line), temp);
              for(int count = 0; count &lt; length; count++)
              {
                  char *string = line + 2;
                  int tickLen = strstr(string, &quot;|&quot;) - string;
                  char sub[tickLen]; 
                  tickers.x[count] = malloc(tickLen);
                  strncpy(sub, string, tickLen);
                  sub[tickLen] = '\0';
                  strcpy(tickers.x[count], sub);
                  fgets(line, sizeof(line), temp);
              }
              fclose(temp);
          }
      }
      curl_easy_cleanup(curl);
      return tickers;
  }
  char ** allocate_DD(int rows, int cols)
  {
      char *data = (char *)malloc(rows*cols);
      char **array= (char **)malloc(rows*sizeof(char*));
      for(int i = 0; i &lt; rows; i++)
          array[i] = &amp;(data[cols*i]);
      return array;
  }
  
  
  int main() //Designed for one master, three slaves
  {
      int my_id;
      MPI_Init(NULL,NULL);
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;my_id);
      MPI_Status status;
      int firstNodeLength;
      if(my_id == 0) // meaning this process is a host job
      {
          struct Tickers tickers = getTickers();
          int length = tickers.length / 3;
          int remainder = tickers.length % 3;
          char ** NodeOneTicks = allocate_DD(length + remainder, 6);
          //char ** NodeTwoTicks = allocate_DD(length, 6);
          //char ** NodeThrTicks = allocate_DD(length, 6);
          int count = 0;
          int x = 0;
          while(count &lt; length + remainder)
          {
              strcpy(NodeOneTicks[x], tickers.x[count]);
              NodeOneTicks[x][5] = '\0';
              count++;
              x++;
          }
          x = 0;
          firstNodeLength = length + remainder;
          printf(&quot;%d\n&quot;, firstNodeLength);
          MPI_Send(&amp;firstNodeLength,1, MPI_INT,1,1000,MPI_COMM_WORLD);
          MPI_Send(NodeOneTicks,firstNodeLength,MPI_CHAR,1,1001,MPI_COMM_WORLD);
          
      }
      else // must be slave process
      {
          int myLen;
          int x = 0;
          
          int ierr = MPI_Recv(&amp;myLen,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD,&amp;status);
          printf(&quot;%d\n&quot;, myLen);
          char ** myTicks = allocate_DD(myLen,6);
          ierr = MPI_Recv(myTicks[0], myLen,MPI_CHAR,0,MPI_ANY_TAG,MPI_COMM_WORLD,&amp;status);
          myTicks[0][5] = '\0';
          printf(&quot;%s\n&quot;, myTicks[0]);
      }
      MPI_Finalize();
  
  }
  
  </code></pre>