title: Renderscript, forEach_root, and porting from OpenCL
body: <p><strong>1) How can I access in forEach_root() other elements except for the current one?</strong></p>
  
  <p>In OpenCL we have pointer to the first element and then can use get_global_id(0) to get current index. But we can still access all other elements. In Renderscript, do we only have pointer to the current element?</p>
  
  <p><strong>2) How can I loop through an Allocation in forEach_root()?</strong></p>
  
  <p>I have a code that uses nested (double) loop in java. Renderscript automates the outer loop, but I can't find any information on implementing the inner loop. Below is my best effort:</p>
  
  <pre><code>void root(const float3 *v_in, float3 *v_out) {
    rs_allocation alloc = rsGetAllocation(v_in);
    uint32_t cnt = rsAllocationGetDimX(alloc);
    *v_out = 0;
    for(int i=0; i&lt;cnt; i++)  
      *v_out += v_in[i];
  }
  </code></pre>
  
  <p>But here rsGetAllocation() fails when called from forEach_root().</p>
  
  <pre><code>05-11 21:31:29.639: E/RenderScript(17032): ScriptC::ptrToAllocation, failed to find 0x5beb1a40
  </code></pre>
  
  <p>Just in case I add my <strong>OpenCL</strong> code that works great under Windows. I'm trying to port it to Renderscript</p>
  
  <pre><code>typedef float4 wType;
  
  __kernel void gravity_kernel(__global wType *src,__global wType *dst)
  {
    int id = get_global_id(0);
    int count = get_global_size(0);
    double4 tmp = 0;
    for(int i=0;i&lt;count;i++) {
      float4 diff = src[i] - src[id];
      float sq_dist = dot(diff, diff);
      float4 norm = normalize(diff);
      if (sq_dist&lt;0.5/60)
        tmp += convert_double4(norm*sq_dist);
      else
        tmp += convert_double4(norm/sq_dist);
    }
    dst[id] = convert_float4(tmp);
  }
  </code></pre>