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 3323074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:15:32+00:00 2026-05-17T23:15:32+00:00

Can someone comment on this, I want to do a vector dot product. My

  • 0

Can someone comment on this,

I want to do a vector dot product. My float vector are [2080:2131] and [2112:2163], each one of them contains 52 elements.

a[52] = {2080 2081 2082 ... ... 2129 2130 2131};
b[52] = {2112 2113 2114 ... ... 2161 2162 2163};

for (int i = 0; i < 52; i++)
{
    sum += a[i]*b[i];
}

The result sum for whole length (52 element)was 234038032 by my kernel while matlab gave 234038038. For 1 to 9 element sum of product, my kernel result agrees with matlab result. For 10 element sum, it is off by 1 and gradually increases. The results were reproducible. I checked all the elements and found no problem.

  • 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-05-17T23:15:32+00:00Added an answer on May 17, 2026 at 11:15 pm

    Since the vectors are float you are experiencing rounding errors. Matlab will store everything with much higher precision (double) and hence won’t see the rounding errors so early.

    You may want to check out What Every Computer Scientist Should Know About Floating Point by David Goldberg – invaluable reading.

    Simple demo in C++ (i.e. nothing to do with CUDA):

    #include <iostream>
    
    int main(void)
    {
      float a[52];
      float b[52];
      double c[52];
      double d[52];
    
      for (int i = 0 ; i < 52 ; i++)
      {
        a[i] = (float)(2080 + i);
        b[i] = (float)(2112 + i);
        c[i] = (double)(2080 + i);
        d[i] = (double)(2112 + i);
      }
    
      float fsum = 0.0f;
      double dsum = 0.0;
      for (int i = 0 ; i < 52 ; i++)
      {
        fsum += a[i]*b[i];
        dsum += c[i]*d[i];
      }
    
      std::cout.precision(20);
      std::cout << fsum << " " << dsum << std::endl;
    }
    

    Run this and you get:

    234038032 234038038
    

    So what can you do about this? There are several directions you could go in…

    • Use higher precision: this will affect performance and not all devices support double precision. It also just postpones the problem rather than fixing it, so I would not recommend it!
    • Do a tree based reduction: you could combin the techniques in the vectorAdd and reduction SDK samples.
    • Use Thrust: very straight-forward.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with someone else's code on a device which can put an image
I have a wordpress blog inside the company where I write blogs. I want
I guess I'm not linking something right? I want to call ABC.cpp which needs
I understand that they are compile time, so they can't be generic, and must
I have a developed a Restlet application. I would like to return a JSP
Does python have a full fledged email library with things for pop, smtp, pop3
I'm trying, in vain, to create a simple Django template tag to either show
I would like to perform an operation on an argument based on the fact
I'm developing a Windows Phome application. I have the following ListBox on a page:
I have a problem with the understanding MVC architecture. It's not that I don't

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.