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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:10:02+00:00 2026-05-30T13:10:02+00:00

I need to minimize the total amount of flops in the following code, can

  • 0

I need to minimize the total amount of flops in the following code, can anyone please take a quick look and tell me where to put my effort?
I’ve tried several perfomance analyzers, but the results were irrelevant..

int twoDToOneD(int i, int j, int nRows)
{
return j*nRows + i;
}

double* addMatrices(int m, int n, double* A, double* B, bool add)
{
double* C = new double[m*n];
double* pA = A;
double* pB = B;
double* pC = C;

int i = m*n;

while(i--)
{
    if(add)
    {
        *pC = *pA + *pB;
    } else 
    {
        *pC = *pA - *pB;
    }

    pC++;
    pA++;
    pB++;
}

return C;
}

Thanks,
Cho

  • 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-30T13:10:03+00:00Added an answer on May 30, 2026 at 1:10 pm

    Right, I didn’t read every last line, but it looks like you are simply:

    1. generating random ints
    2. storing them as doubles
    3. adding them
    4. adding and multiplying them

    IOW – I don’t see any use of the fraction at all, and an appropriately sized integer will be superior. If that’s true, you can remove every FLOP in the program 😉

    If that’s not an accurate signal, you can still use it in an appropriate range, then just scale the signal up, store as an integer, and then bring the result back down to the proper range in some cases.

    For appropriately sized mul/add, using integers will be much faster and potentially require much less memory — you can also apply SIMD instructions to them.

    Beyond that – your improving cache locality, minimizing branching, and minimizing dynamic allocations could also make the program a few times faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to remove the maximize and minimize buttons from a JFrame . Please
Need some regular expressions help. So far I have my code working to allow
Am I doing this right? I went to look at some old PHP code
I need to programmatically minimize and maximize a fullscreen 16bit application. Unfortunately DosBox is
I need to perform several operations on a list of windows (minimize some of
In order to minimize the number of database queries I need some sort of
im developing a custom form and i need to put a button right next
I need to pull a large amount of data from various tables across a
I am using mfc CDialog. I need to show the close and minimize/maximize button,
Need to minimize the window of IE Browser using selenium webDriver using c#

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.