8 Replies Latest reply on Aug 15, 2010 3:39 AM by dar

    OpenCL Tutorial:N-Body Simulation

    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

       

      /* 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[i]; 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) ); }

        • OpenCL Tutorial:N-Body Simulation
          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.

            • OpenCL Tutorial:N-Body Simulation
              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.

               

                • OpenCL Tutorial:N-Body Simulation
                  dar

                   

                  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.

                   

                   

                   

                   

              • OpenCL Tutorial:N-Body Simulation
                jross

                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[i]); cl_float4_y(center) += cl_float4_y(pos[i]); cl_float4_z(center) += cl_float4_z(pos[i]); cl_float4_w(center) += cl_float4_w(pos[i]); } 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) ); }