cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

AptypR
Journeyman III

OpenCL Tutorial:N-Body Simulation

I tried to compile example,given in this(http://browndeertechnology.com/docs/BDT_OpenCL_Tutorial_NBody.html) article,but i just got error nbody_output.c:14: error: invalid operands to binary + (have ‘cl_float4’ and ‘cl_float4&rsquo
nbody_output.c:16: error: invalid operands to binary / (have ‘cl_float4’ and ‘cl_float4&rsquo

nbody_output.c was changed a little,and now look like

 

/* nbody_output.c */ #include <stdio.h> #include <stdcl.h> void nbody_output( int n, cl_float4* pos ) { int i; cl_float4 ave_pos = (cl_float4){0.0f,0.0f,0.0f,0.0f}; for(i=0;i<n;i++) ave_pos+=pos; ave_pos/=(cl_float4){n,n,n,n}; printf("ave_pos = {%e,%e,%e}\n", cl_float4_x(ave_pos),cl_float4_y(ave_pos),cl_float4_z(ave_pos) ); }

0 Likes
8 Replies
genaganna
Journeyman III

Originally posted by: AptypR I tried to compile example,given in this(http://browndeertechnology.com/docs/BDT_OpenCL_Tutorial_NBody.html) article,but i just got error nbody_output.c:14: error: invalid operands to binary + (have ‘cl_float4’ and ‘cl_float4&rsquo nbody_output.c:16: error: invalid operands to binary / (have ‘cl_float4’ and ‘cl_float4&rsquo

 

nbody_output.c was changed a little,and now look like

 

 



Please check whether + and / operators supported on cl_float4 in stdcl.h or not.

0 Likes

Originally posted by: genaganna
Originally posted by: AptypR I tried to compile example,given in this(http://browndeertechnology.com/docs/BDT_OpenCL_Tutorial_NBody.html) article,but i just got error nbody_output.c:14: error: invalid operands to binary + (have ‘cl_float4’ and ‘cl_float4&rsquo nbody_output.c:16: error: invalid operands to binary / (have ‘cl_float4’ and ‘cl_float4&rsquo

 

 

 

nbody_output.c was changed a little,and now look like

 

 

 

 



 

Please check whether + and / operators supported on cl_float4 in stdcl.h or not.

 

0 Likes
dar
Journeyman III

Originally posted by: dar
Originally posted by: genaganna
Originally posted by: AptypR I tried to compile example,given in this(http://browndeertechnology.com/docs/BDT_OpenCL_Tutorial_NBody.html) article,but i just got error nbody_output.c:14: error: invalid operands to binary + (have ‘cl_float4’ and ‘cl_float4&rsquo nbody_output.c:16: error: invalid operands to binary / (have ‘cl_float4’ and ‘cl_float4&rsquo

 

 

 

 

 

 

 

nbody_output.c was changed a little,and now look like

 

 

 

 

 

 

 

 



 

 

 

Please check whether + and / operators supported on cl_float4 in stdcl.h or not.

 

 

 

 

0 Likes
jross
Adept I

AptypR,

I believe what dar, the libstdcl developer, was trying to say using an iPhone4 was that the tutorial was written using the beta4 version of OpenCL.  The original version did compile and run.  Expect the tutorial code to be updated on the website in the next couple of hours or days and in the mean time, you can try component-wise addition and division like this:

 

/* nbody_output.c */ #include <stdio.h> #include <stdcl.h> void nbody_output( int n, cl_float4* pos, cl_float4* vel ) { int i; cl_float4 center = (cl_float4){0.0f,0.0f,0.0f,0.0f}; for(i=0;i<n;i++) { cl_float4_x(center) += cl_float4_x(pos); cl_float4_y(center) += cl_float4_y(pos); cl_float4_z(center) += cl_float4_z(pos); cl_float4_w(center) += cl_float4_w(pos); } cl_float4_x(center) /= n; cl_float4_y(center) /= n; cl_float4_z(center) /= n; cl_float4_w(center) /= n; printf("ave_pos => {%f,%f,%f}\n", cl_float4_x(center),cl_float4_y(center),cl_float4_z(center) ); }

0 Likes

Thanks for answer,I'll try it.

0 Likes

I did what you said.

now it crashes with "segmentation fault":-)

0 Likes
dar
Journeyman III

a new version of libstdcl is being released wihin next few days that works against the latest SDK.  improved documentation, other improvements.  tutorial is also being updated with extension to multiple-GPUs.  check the website in a day or so. 

0 Likes
dar
Journeyman III

Tutorial was recently updated, now includes discussion of using two GPUs.

New release of libstdcl is available, now distributed as part of coprthr SDK v1.0-RC2.  Can be downloaded from here http://www.browndeertechnology.com/coprthr.html

If you download coprthr SDK you will get everything now, includes tutorial, tutorial code and a new ref manual for STDCL that is also available online.

Also include NBody demo with display.  More will be included in v1.1 soon.

Tutorial code was tested agains the ATI SDK v2.1, Catalyst 10.3 running on CentOS 5.4 with a Radeon 5870 and 5970.

Let me know if you have trouble. 

 

0 Likes