Undefined Variables It is defined above, but it is still called undefined

{

	 double* d_ZRAYu;

	 cudaMalloc((void**) &d_ZRAYu, sizeof(ZRAYu));

	 double* d_TRAYu;

	 cudaMalloc((void**) &d_TRAYu, sizeof(TRAYu));

	 double* d_PCOSu;

	 cudaMalloc((void**) &d_PCOSu, sizeof(PCOSu));  

	 double* d_PSINu;

	 cudaMalloc((void**) &d_PSINu, sizeof(PSINu));

	 double* d_NSRFu;

	 cudaMalloc((void**) &d_NSRFu, sizeof(NSRFu));

	 double* d_NBTMu;

	 cudaMalloc((void**) &d_NBTMu, sizeof(NBTMu)); 

	 double* d_NUPRu;

	 cudaMalloc((void**) &d_NUPRu, sizeof(NUPRu));

	 double* d_NLWRu;

	 cudaMalloc((void**) &d_NLWRu, sizeof(NLWRu));

	 double* d_ORAYu;bales

	 cudaMalloc((void**) &d_ORAYu, sizeof(ORAYu)); 

	 } 

	 // copy host memory to device

	 cudaMemcpy(d_ZRAYu,ZRAYu,sizeof(ZRAYu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_TRAYu,TRAYu,sizeof(TRAYu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_PCOSu,PCOSu,sizeof(PCOSu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_PSINu,PSINu,sizeof(PSINu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_NSRFu,NSRFu,sizeof(NSRFu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_NBTMu,NBTMu,sizeof(NBTMu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_NUPRu,NUPRu,sizeof(NUPRu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_NLWRu,NLWRu,sizeof(NLWRu),cudaMemcpyHostToDevice);

	 cudaMemcpy(d_ORAYu,ORAYu,sizeof(ORAYu),cudaMemcpyHostToDevice);

The above code generates the following error set:

test4.c:101: error: ‘d_ZRAYu’ undeclared (first use in this function)

test4.c:101: error: (Each undeclared identifier is reported only once

test4.c:101: error: for each function it appears in.)

test4.c:102: error: ‘d_TRAYu’ undeclared (first use in this function)

test4.c:103: error: ‘d_PCOSu’ undeclared (first use in this function)

test4.c:104: error: ‘d_PSINu’ undeclared (first use in this function)

test4.c:105: error: ‘d_NSRFu’ undeclared (first use in this function)

test4.c:106: error: ‘d_NBTMu’ undeclared (first use in this function)

test4.c:107: error: ‘d_NUPRu’ undeclared (first use in this function)

test4.c:108: error: ‘d_NLWRu’ undeclared (first use in this function)

test4.c:109: error: ‘d_ORAYu’ undeclared (first use in this function)

I define each variable d_ZRAYu, d_TRAYu and so on right before I transfer it to the device memory. Yet it says starting with line 101 that

d_ZRAYu is not defined. I do not understand why I am getting these errors. It seems that these variables are defined. Whta is going on here?

Newport_j

The aren’t defined at the scope you are using them at. The braces {} surrounding the declarations and cudaMalloc calls put them at a different scope to the cudaMemcpy calls.