4 Replies Latest reply on May 17, 2013 10:26 AM by shunyo

    using cl::vector push_back


      Hi everyone, stuck with this very simple problem. I have a vector of points declared as: cl::vector<cl_float3> points. I also have a buffer declared as

      cl_float3 buff;

      Now I am trying to read in data from a file containing data point coordinates as x, y, z. So, to accomplish this, I use:


                          fscanf(FID,"%lf %lf %lf",&buff.s[0],&buff.s[1],&buff.s[2]);



      where FID is the file I have been reading from. The problem is while reading, points takes in data for 10 iterations and then doesnt furthur. The loop goes on operating, but I see nothing in the vector. What am I doing wrong? I used a struct of 3 floats which works perfectly, so I am at a loss figuring out where the problem lies.

        • using cl::vector push_back

          that because cl::vector is fixed sized vector with maximum default size 10. use normal std::vector

            • Re: using cl::vector push_back

              Thank you. I changed it.

                • Re: using cl::vector push_back

                  Here is sample example it works fine: (Sorry I m using bolt::cl::device_vector not cl::vector)


                  int main()


                      bolt::cl::device_vector<cl_float3> dv;



                      cl_float3 f = {1.0, 2.0, 3.0};


                      for(int i=0; i<10; i++)






                      std::cout << "\n Dev vec size: " << dv.size() << std::endl;    // output: 12


                      std::vector<cl_float3> v(12);


                          bolt::cl::device_vector<cl_float3>::pointer dp = dv.data();

                          memcpy(v.data(), dp.get(), sizeof(cl_float3) * 12);


                      for(int i=0; i<12; i++)

                          std::cout << v[i].s << " ";

                      std::cout << std::endl;


                      return 0;