# Nested Zip\_Iterator for output in THRUST

**URL:** <https://forums.developer.nvidia.com/t/nested-zip-iterator-for-output-in-thrust/37370>\
**Category:** GPU-Accelerated Libraries\
**Created:** [March 26, 2015, 8:34am UTC](https://forums.developer.nvidia.com/t/nested-zip-iterator-for-output-in-thrust/37370 "2015-03-26T08:34:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FrankyBoy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@FrankyBoy](https://forums.developer.nvidia.com/u/FrankyBoy)\
**Post date:** [March 26, 2015, 8:34am UTC](https://forums.developer.nvidia.com/t/nested-zip-iterator-for-output-in-thrust/37370/1 "2015-03-26T08:34:15Z")

</div>

Hello everybody,

i have a foreach call function that is getting nested zip(tuple(zip(tuple()),zip(tuple()))) iterators because the tuples. THis is becuase i have more than ten in- and output vectors. WHen i trry to modify the output vectors it has no effect tho when doping it like

thrust::tuple\<double,double,double,double\> outputs=get\<0\>(thewholeinputtoforeach);  
thrust::get\<0\>(output)= SOMEFUNCTION OF OTHER STUFF

I believe this doesnt work because the first line creates a deep copy of the output and changes the copy, not the output.

Trying it like this

thrust::get\<0\>(thrust::get\<0\>(thewholeinputtoforeach)= SOMEFUNCTION OF OTHER STUFF

errors with “error: expression must be a modifiable lvalue”

SO somehow i guess i have to create reference to the output iterator with pointers, but i don’t manage to.

Nay tips and ideas are highly appreciated.  
best regards  
Franz

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [April 2, 2015, 7:38pm UTC](https://forums.developer.nvidia.com/t/nested-zip-iterator-for-output-in-thrust/37370/2 "2015-04-02T19:38:10Z")

</div>

It’s not clear what the problem is. The following seems to work for me:

```auto
$ cat t687.cu
#include <thrust/iterator/zip_iterator.h>
#include <thrust/device_vector.h>
#include <thrust/for_each.h>
#include <iostream>

#define DSIZE 10
#define ZIP(X,Y) thrust::make_zip_iterator(thrust::make_tuple(X,Y))

struct incr
{
  template <typename T>
  __host__  __device__
  void operator()(T d1){
  thrust::get<0>(thrust::get<0>(d1))++;
  thrust::get<1>(thrust::get<0>(d1))++;
  thrust::get<0>(thrust::get<1>(d1))++;
  thrust::get<1>(thrust::get<1>(d1))++;
  }
};

int main(){
  thrust::device_vector<int> d1(DSIZE);
  thrust::device_vector<int> d2(DSIZE);
  thrust::device_vector<int> d3(DSIZE);
  thrust::device_vector<int> d4(DSIZE);
  std::cout << d1[0] << std::endl;
  thrust::for_each(ZIP(ZIP(d1.begin(),d2.begin()), ZIP(d3.begin(),d4.begin())), ZIP(ZIP(d1.end(), d2.end()), ZIP(d3.end(), d4.end())), incr());
  std::cout << d1[0] << std::endl;

}

$ nvcc -o t687 t687.cu
$ ./t687
0
1
$

```

---

<div class="post-metadata">

**Author:** ![FrankyBoy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@FrankyBoy](https://forums.developer.nvidia.com/u/FrankyBoy)\
**Post date:** [April 3, 2015, 8:02am UTC](https://forums.developer.nvidia.com/t/nested-zip-iterator-for-output-in-thrust/37370/3 "2015-04-03T08:02:42Z")

</div>

ok, thanks for the reply.  
apperently my problem was that i didnt use a template functor but gave the types myself instead. ANd probably i messed up references and copies somewhere around there.

Thanks again, now it works.

best regards  
Franz
