-2

When I try and compile the my .cu file using nvcc -c, the following error occurs:

mag_cuda.cu(213): error: expression must have arithmetic or enum type

The line in question if part of a function that will carried out by the GPU given here:

__global__// all kernels are preceded by __global__ keyword
  void sum_all_indv_B(int No_poles, double *B_x, double *B_y, double 
*B_z, double *indv_B[][3])
  {
    // determine thread ID within block
    int index = blockIdx.x * blockDim.x + threadIdx.x;

    // determine stride of loop (more elements in array than threads)
    int stride = blockDim.x * gridDim.x;

    //loop over all the poles
    for(int counter_1 = index; counter_1 < No_poles; counter_1+=stride)
      {
    //sum the B field contribution from all poles in x,y and z directions
    B_x += indv_B[counter_1][0];
    B_y += indv_B[counter_1][1];
    B_z += indv_B[counter_1][2];

        //Divide total by number of Poles
    B_x = B_x/No_poles;
    B_y = B_y/No_poles;
    B_z = B_z/No_poles;
      }
  }

Error occurs at the "B_x += indv_B[counter_1][0];" ," B_x = B_x/No_poles;" and similar lines.

Any ideas as I'm not too up on my pointers

Aaron
  • 155
  • 3
  • 11
  • `indv_B[i][j]` is a pointer to a `double`. Assuming that the declaration `double *indv_B[][3]` is correct, use `B_x += *indv_B[counter_1][0];` – Gilles-Philippe Paillé Apr 26 '19 at 16:05
  • 2
    This is attempting to add two pointers: `B_x += indv_B[counter_1][0];` [That is illegal in C or C++](https://stackoverflow.com/questions/25667580/addition-of-two-pointers-in-c-or-c-not-supported-why). Perhaps what you want is this: `*B_x += *indv_B[counter_1][0];` and similarly for the other two, and `*B_x = *B_x/No_poles;`, and similarly for the other two. – Robert Crovella Apr 26 '19 at 16:39
  • @RobertCrovella Adding the * worked. Thank you very much for your help – Aaron Apr 26 '19 at 19:56

1 Answers1

1

B_x and indv_B[i][j] are pointers to double values. Assuming that the declarations double *B_x and double *indv_B[][3] are correct, use *B_x += *indv_B[counter_1][0];.

You will also have to change the lines below: *B_x = *B_x/No_poles;.