Lance
Lance

Reputation: 39

using OpenACC ,error information displays :[if not already present]

When I compiled the code with OpenACC,I got the error information:[if not already present]

#include<iostream>

#include<openacc.h>

using namespace std;


int main(){
int i,j,sum=0;
#pragma acc parallel loop copyin(i,j) copyout(sum)
for(int i=0;i<100;i++){
           #pragma acc loop
    for(int j=0;j<200;j++){
           sum=i+j;
    }

  }
  cout<<sum<<endl;
}

Result shows:

main:

 8, Generating copyin(i) [if not already present]
    Generating copyout(sum) [if not already present]
    Generating copyin(j) [if not already present]
    Generating NVIDIA GPU code
   10, #pragma acc loop gang, vector(96) /* blockIdx.x >threadIdx.x */
    12, #pragma acc loop seq
13, Accelerator restriction: induction variable live-out from loop: sum

I don't quite understand why the error shows induction variable live-out from loop: sum.

Upvotes: 0

Views: 144

Answers (1)

Mat Colgrove
Mat Colgrove

Reputation: 5646

"live-out" means that a global device scalar variable is being assigned in the device kernel and then being used on the host. It inhibits auto-parallelization since it creates a dependency. Though since you've forced parallelization, consider it a warning that the code will likely result in a wrong answer.

The order in which a parallel loop executes the iterations is non-deterministic. Hence which ever thread happens to update 'sum' last, will be the result. To get the last value, the loops iterations would need to be run sequentially, hence the dependency.

Upvotes: 2

Related Questions