Home > Enterprise >  What does &array[element] means and why?
What does &array[element] means and why?

Time:01-07

I was coding in MPI using C. I don't understand how the MPI_Send() works or if maybe &array[element] works.

MPI_Send(&array[element],element_left,MPI_INT,i,0,MPI_COMM_WORLD);

here array[]={1,2,3,4,5,6,7,8,9,10} and element = 6 and element_left = 4. I understand array[element]=array[6]=7 but why this function picks 7,8,9,10? I know it will pick 4 elements from the array but why do we need & here and by only giving starting entry array[6] how is this function able to pick the next 3 as well?

I thought I have to add one after another using a for loop or something, but when I searched something on Google I got this code and after going through so much I still didn't understand. Please help me understand the backwardness of this code.

CodePudding user response:

Most MPI routines take a trio of arguments:

  • address of buffer
  • count of elements
  • datatype of elements

So by &array[element],element_left,MPI_INT you specify the elements element as the start of the buffer, and then you take element_left many integers to send. Kinda strange that you name the count element_left which is more like a name for an index, but that's what happens.

CodePudding user response:

&array[element] is the same expression as array element and means the address of the elementth element of the array array.

The function you call wants this address as the first argument, and takes the number of elements to process as the second argument.

  •  Tags:  
  • cmpi
  • Related