首页 > 其他分享 >高Cache命中率的矩阵乘法

高Cache命中率的矩阵乘法

时间:2023-04-06 11:24:49浏览次数:36  
标签:rand clock int 命中率 Cache ++ C1 乘法

#include <ctime>
#include <iostream>

using namespace std;
 
int main(int argc, char** argv)
{
   int N = 500;
   int A[N][N];
   int B[N][N];
   double C1[N][N];
   double C2[N][N];
   for (int i = 0; i < N; i++) {
       for (int j = 0; j < N; j++) {
           A[i][j] = rand();
           B[i][j] = rand();
       }
   }
   clock_t t1 = clock();
   for (int i = 0; i < N; i++) {
       for (int j = 0; j < N; j++) {
           for (int k = 0; k < N; k++) {
               C1[i][j] += A[i][k] * B[k][j];
           }
       }
   }
   clock_t t2 = clock();
   cout << "Conventional method takes " << t2 - t1 << " milliseconds."  << endl;
   t1 = clock();
   for (int i = 0; i < N; i++) {
       for (int k = 0; k < N; k++) {
           for (int j = 0; j < N; j++) {
               C2[i][j] += A[i][k] * B[k][j];
           }
       }
   }
   t2 = clock();
   cout << "New method takes " << t2 - t1 << " milliseconds." << endl;
}

  

标签:rand,clock,int,命中率,Cache,++,C1,乘法
From: https://www.cnblogs.com/qiandeheng/p/17292197.html

相关文章

  • 使用benchmark比较循环嵌套与strassen求解矩阵乘法的性能
    #include<benchmark/benchmark.h>#include<iostream>#include<random>#include<vector>usingnamespacestd;staticconstintn=200;staticconstint_lrange=0;staticconstint_rrange=10;staticconstint_iter=1;us......
  • Linux Page Cache调优在Kafka中的应用
    作者:YangYijun本文主要描述LinuxPageCache优化的背景、PageCache的基本概念、列举之前针对Kafka的IO性能瓶颈采取的一些解决方案、如何进行PageCache相关参数调整以及性能优化前后效果对比。一、优化背景当业务快速增长,每天需要处理万亿记录级数据量时。在读写数据方面,Kafka......
  • How CloudFront works with regional edge caches
    Reference:  HowCloudFrontworkswithregionaledgecachesCloudFrontpointsofpresence(alsoknownasPOPsoredgelocations)makesurethatpopularcontentcanbeservedquicklytoyourviewers.CloudFrontalsohasregionaledgecachesthatbringmore......
  • LRU Cache
    ProblemStatementDesignandimplementadatastructureforLeastRecentlyUsed(LRU)cache.Itshouldsupportthefollowingoperations:getandset.get(key)-Getthevalue(willalwaysbepositive)ofthekeyifthekeyexistsinthecache,otherwis......
  • HJ70_矩阵乘法计算量估算_入门栈使用的典型题
    反思:这题咋一看不难,但是越做坑越多,按照一开始不完善的思路无法完全通过测试。参看高赞答案,代码行数特少。但是没考虑一个括号中有三个矩阵的情况。思路:1、判断哪两个矩阵开始相乘的条件:遇到“)”时,该字符前两个矩阵开始相乘。把相乘后矩阵行列数组压入栈栈中。该题默认不存在(A(......
  • 链表完成多项式乘法
    多项式乘法是在多项式加法的基础上完成的。1、多项式加法1#include<iostream>2usingnamespacestd;3typedefstructlnode{4intcoef;5intexp;6lnode*next;7}lnode;8classpoly{9lnode*head;10public:11voidcreate(in......
  • HJ69_矩阵乘法_数组
    思路:三层循环实现矩阵相乘。importsysa=[]forlineinsys.stdin:  a.append(list(map(int,line.strip().split())))#print(a)matrix1=a[3:3+a[0][0]]matrix2=a[3+a[0][0]:]nw=[[0foriinrange(a[2][0])]foriinrange(a[0][0])]forminrange(a[0][0]): ......
  • Redis基于@Cacheable注解实现接口缓存
    说明@Cacheable注解在方法上,表示该方法的返回结果是可以缓存的。也就是说,该方法的返回结果会放在缓存中,以便于以后使用相同的参数调用该方法时,会返回缓存中的值,而不会实际执行该方法。属性名称属性描述举例value/cacheNames指定缓存组件的名字@Cacheable(value="......
  • min 与 + 运算转换成类似于矩阵乘法的推导过程
    记录下由$\min$与$+$运算转换成类似于矩阵乘法的推导过程,有错误请在评论区指出qwq。我们先简单证明一下矩阵乘法的结合律。设有矩阵$A_{n\timesm}$,$B_{m......
  • 借助 mperf 进行矩阵乘法极致优化
    作者:旷视MegEngine架构师洪超前言单精度矩阵乘法(SGEMM)是非常典型的计算密集型算子,对SGEMM的优化也经常被当作算子优化从业人员的练手项目。本文将借助于mperf,在A......