Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:35:26+00:00 2026-06-11T05:35:26+00:00

I am trying to perform a thrust::reduce_by_key using zip and permutation iterators. i.e. doing

  • 0

I am trying to perform a thrust::reduce_by_key using zip and permutation iterators.
i.e. doing this on a zipped array of several ‘virtual’ permuted arrays.
I am having trouble in writing the syntax for the functor density_update.

But first the setup of the problem.

Here is my function call:

thrust::reduce_by_key(  dflagt,
                        dflagtend,
                        thrust::make_zip_iterator( 
                            thrust::make_tuple(
                                thrust::make_permutation_iterator(dmasst, dmapt), 
                                thrust::make_permutation_iterator(dvelt, dmapt),
                                thrust::make_permutation_iterator(dmasst, dflagt),
                                thrust::make_permutation_iterator(dvelt, dflagt)
                            )
                        ),
                        thrust::make_discard_iterator(),
                        danswert,
                        thrust::equal_to<int>(),
                        density_update()
                  ) 

dmapt, dflagt are of type thrust::device_ptr<int> and dvelt , dmasst and danst are of type
thrust::device_ptr<double>.

(They are thrust wrappers to my raw cuda arrays)

The arrays mapt and flagt are both index vectors from which I need to perform a gather operation from the arrays dmasst and dvelt.

After the reduction step I intend to write my data to the danswert array. Since multiple arrays are being used in the reduction, obviously I am using zip iterators.

My problem lies in writing the functor density_update which is binary operation.

struct density_update
{
  typedef thrust::device_ptr<double> ElementIterator;
  typedef thrust::device_ptr<int>   IndexIterator;
  typedef thrust::permutation_iterator<ElementIterator,IndexIterator> PIt;

  typedef thrust::tuple< PIt , PIt , PIt, PIt> Tuple;
  __host__ __device__
  double operator()(const Tuple& x , const Tuple& y)
  {   
      return    thrust::get<0>(*x) * (thrust::get<1>(*x) - thrust::get<3>(*x)) + \
                thrust::get<0>(*y) * (thrust::get<1>(*y) - thrust::get<3>(*y));
  }
};

The value being returned is a double . Why the binary operation looks like the above functor is
not important. I just want to know how I would go about correcting the above syntactically.
As shown above the code is throwing a number of compilation errors. I am not sure where I have gone wrong.

I am using CUDA 4.0 on GTX 570 on Ubuntu 10.10

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:35:28+00:00Added an answer on June 11, 2026 at 5:35 am

    density_update should not receive tuples of iterators as parameters — it needs tuples of the iterators’ references.

    In principle you could write density_update::operator() in terms of the particular reference type of the various iterators, but it’s simpler to have the compiler infer the type of the parameters:

    struct density_update
    {
      template<typename Tuple>
      __host__ __device__
      double operator()(const Tuple& x, const Tuple& y)
      {   
        return thrust::get<0>(x) * (thrust::get<1>(x) - thrust::get<3>(x)) + \
               thrust::get<0>(y) * (thrust::get<1>(y) - thrust::get<3>(y));
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying perform a relatively basic TCP socket send/receive operation on Windows CE using
I'm trying to perform a DISTINCT clause on a query like this SELECT DISTINCT
I am trying to perform a Calculus Cross Product calculation using Linq and trying
I am trying to perform a binary search on an array, and I must
I'm trying to perform a complex issue, I have a query structured like this:
I am trying to perform a method in a background thread using a NSOperationQueue
I'm trying to perform a hierarchical clustering using a custom distance measure. I perform
I`m trying to perform a linq query in a friends JsonArray using Facebook C#
Im trying to perform a mod rewriting to my web site. And I used
I am trying to perform an automatic login when the user clicks a link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.