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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:50:59+00:00 2026-05-22T16:50:59+00:00

I am making some matrix multiplication benchmarking, as previously mentioned in Why is MATLAB

  • 0

I am making some matrix multiplication benchmarking, as previously mentioned in
Why is MATLAB so fast in matrix multiplication?

Now I’ve got another issue, when multiplying two 2048×2048 matrices, there is a big difference between C# and others. When I try multiply only 2047×2047 matrices, it seems normal. Added some others for comparsion too.

1024×1024 – 10 seconds.

1027×1027 – 10 seconds.

2047×2047 – 90 seconds.

2048×2048 – 300 seconds.

2049×2049 – 91 seconds. (update)

2500×2500 – 166 seconds

That is three and a half minute difference for the 2k by 2k case.

using 2dim arrays

//Array init like this
int rozmer = 2048;
float[,] matice = new float[rozmer, rozmer];

//Main multiply code
for(int j = 0; j < rozmer; j++)
{
   for (int k = 0; k < rozmer; k++)
   {
     float temp = 0;
     for (int m = 0; m < rozmer; m++)
     {
       temp = temp + matice1[j,m] * matice2[m,k];
     }
     matice3[j, k] = temp;
   }
 }
  • 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-22T16:51:00+00:00Added an answer on May 22, 2026 at 4:51 pm

    This probably has do with conflicts in your L2 cache.

    Cache misses on matice1 are not the problem because they are accessed sequentially.
    However for matice2 if a full column fits in L2 (i.e when you access matice2[0, 0], matice2[1, 0], matice2[2, 0] … etc, nothing gets evicted) than there is no problem with cache misses with matice2 either.

    Now to go deeper in how caches works, if byte address of your variable is X, than the cache line for it would be (X >> 6) & (L – 1). Where L is total number of cache lines in your cache. L is always power of 2.
    The six comes from fact that 2^6 == 64 bytes is standard size of cache line.

    Now what does this mean? Well it means that if I have address X and address Y and
    (X >> 6) – (Y >> 6) is divisible by L (i.e. some large power of 2), they will be stored in the same cacheline.

    Now to go back to your problem what is the difference between 2048 and 2049,

    when 2048 is your size:

    if you take &matice2[x, k] and &matice2[y, k] the difference (&matice2[x, k] >> 6) – (&matice2[y,k] >> 6) will be divisible by 2048 * 4 (size of float). So a large power of 2.

    Thus depending on size of your L2 you will have a lot of cache line conflicts, and only utilize small portion of your L2 to store a column, thus you wont actually be able to store full column in your cache, thus you will get bad performance.

    When size is 2049, then the difference is 2049 * 4 which is not power of 2 thus you will have less conflicts and your column will safely fit into your cache.

    Now to test this theory there are couple things you can do:

    Allocate your array matice2 array like this matice2 [razmor, 4096], and run with razmor = 1024, 1025 or any size, and you should see very bad performance compared to what you had before. This is because you forcefully align all columns to conflict with each other.

    Then try matice2 [razmor, 4097] and run it with any size and you should see much better performance.

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

Sidebar

Related Questions

I'm making some pretty string-manipulation-intensive code in C#.NET and got curious about some Joel
I have some massive matrix computation to do in MATLAB. It's nothing complicated (see
I'm making some load test using Siege and Apache benchmarking tool . I count
After making some changes in my models (eg. new field in a model and
While making some final tests of a class-library that I'm writing for Windows Mobile
im making some script with mechanize.browser module. one of problem is all other thing
I'm making some changes to a legacy classic ASP application. I've made the changes
I am programatically making some LinkButtons, and they worked fine for a while, but
I happened to be making some changes to a WordPress blog and noticed that
We're making some calls to some very simple JSON web services in .NET CF

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.