title: MPI dynamically allocation arrays
body: <p>I have a problem with a dynamically allocation of arrays.</p>
  
  <p>This code, if I use a static allocation, runs without problem...</p>
  
  <pre><code>int main (int argc, char *argv[]){  
  
      int size, rank;
  
      MPI_Status status;
  
      MPI_Init(&amp;argc, &amp;argv);
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
      MPI_Comm_size(MPI_COMM_WORLD, &amp;size);
      int lowerBound = 0, upperBound = 0, dimArrayTemp, x, z;
      int dimBulk = size - 1, nPart, cnt;
  
  
      FILE *pf;
      pf = fopen("in.txt","r");
      int array_value = fscanf(pf,"%d",&amp;array_value);
      float ins_array_value;
  
      float *arrayTemp, *bulkSum,*s,*a;
  
      arrayTemp =(float*)malloc(array_value*sizeof(float));
      bulkSum = (float*)malloc(array_value*sizeof(float));
      s =(float*) malloc(array_value*sizeof(float));
      a =(float*) malloc(array_value*sizeof(float));
  
      int j=0;
  
      while(!feof(pf)){
          fscanf(pf,"%f",&amp;ins_array_value);
          a[j] = ins_array_value;
          j++;
      }
      fclose(pf); 
  
      float presum, valFinal;
  
      if(size &lt;= array_value){
          if (rank == MASTER){
              nPart = array_value/size; 
              int countPair;
              if((array_value % size) != 0){
                  countPair = 0;
              }
              for (int i = 0; i &lt; size; i++){
  
                  if(i == 0){
                      lowerBound = upperBound;
                      upperBound += nPart - 1; 
                  }
                  else{
                      lowerBound += nPart;
                      upperBound += nPart;
                      if(countPair == 0 &amp;&amp; i == size - 1)
                          upperBound = array_value - 1;
                  }
                  dimArrayTemp = upperBound - lowerBound;
                  //float arrayTemp[dimArrayTemp];
                  for( x = lowerBound, z = 0; x &lt;= upperBound; x++, z++){
                      arrayTemp[z] = a[x];
                  }
                  if (i &gt; 0){
                      //send array size
                      MPI_Send(&amp;z,1,MPI_INT,i,0,MPI_COMM_WORLD);
                      //send value array
                      MPI_Send(arrayTemp,z,MPI_INT,i,1,MPI_COMM_WORLD);
                  }
                  else{
  
                      for (int h = 1;h &lt;= dimArrayTemp; h++)
                          arrayTemp[h] = arrayTemp[h-1] + arrayTemp[h]; 
                      bulkSum[0] = arrayTemp[dimArrayTemp];
                      for (int h = 0; h &lt;= dimArrayTemp; h++)
                          s[h] = arrayTemp[h];
                  }
  
              }       
          }
          else{
                  //recieve array size
              MPI_Recv(&amp;z,1,MPI_INT,0,0,MPI_COMM_WORLD, &amp;status);
  
              MPI_Recv(arrayTemp,z,MPI_INT,0,1,MPI_COMM_WORLD,&amp;status);
              for(int h = 1; h &lt; z; h++){
                  arrayTemp[h] = arrayTemp[h-1] + arrayTemp[h];
                  presum = arrayTemp[h];
              }
  
  
              MPI_Send(&amp;presum,1,MPI_INT,0,1,MPI_COMM_WORLD);
          }
  
          //MPI_Barrier(MPI_COMM_WORLD);
          if (rank == MASTER){
  
              for (int i = 1; i&lt;size;i++){
                  MPI_Recv(&amp;presum,1,MPI_INT,i,1,MPI_COMM_WORLD,&amp;status);
                  bulkSum[i] = presum;
              }
              for (int i = 0; i&lt;=dimBulk; i++){
                  bulkSum[i] = bulkSum[i-1] +bulkSum[i];
              }
              for(int i = 0; i&lt;dimBulk;i++){
                  valFinal = bulkSum[i];
                  cnt = i+1;
                  MPI_Send(&amp;valFinal,1,MPI_INT,cnt,1,MPI_COMM_WORLD);
              }
          }
          else{
  
              MPI_Recv(&amp;valFinal,1,MPI_INT,0,1,MPI_COMM_WORLD,&amp;status);
              for(int i = 0; i&lt;z;i++){
                  arrayTemp[i] = arrayTemp[i] + valFinal;
              }
              MPI_Send(arrayTemp,z,MPI_INT,0,1,MPI_COMM_WORLD);
          }
  
          if(rank == MASTER){
              for(int i =1;i&lt;size;i++){
                  MPI_Recv(arrayTemp,z,MPI_INT,i,1,MPI_COMM_WORLD,&amp;status);
                  for(int v=0, w =dimArrayTemp+1 ;v&lt;z;v++, w++){
                      s[w] = arrayTemp[v];
                  }   
                  dimArrayTemp += z;
              }
              int count = 0;
              for(int c = 0;c&lt;array_value;c++){
                  printf("s[%d] = %f \n",count++,s[c]);
              }
  
          }
      }
      else{
          printf("ERROR!!!\t number of procs (%d) is higher than array size(%d)!\n", size, array_value);
          //fflush(stdout);
          MPI_Finalize();
      }
      free(arrayTemp);
      free(s);
      free(a);
      free(bulkSum);
      MPI_Finalize();
      return 0;   
  }
  </code></pre>
  
  <p>This is a specific declaration of arrays:</p>
  
  <pre><code>float *arrayTemp, *bulkSum,*s,*a;
  
  arrayTemp =(float*)malloc(array_value*sizeof(float));
  bulkSum = (float*)malloc(array_value*sizeof(float));
  s =(float*) malloc(array_value*sizeof(float));
  a =(float*) malloc(array_value*sizeof(float));
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>EDIT:
  I'm deleted reference for arrays in MPI_Send(); and MPI_Recv(); and condition master, the same error is occurred: a process exited on signal 6 (Aborted).</p>