试图对缓存进行跨步测试,但程序并没有结束

trying to do a stride test of the cache but program is not ending

本文关键字:程序 并没有 结束 跨步测试 缓存      更新时间:2023-10-16

我正试图对缓存进行跨步测试,但我的代码中出现了一个错误,导致程序永远无法结束。我不得不自己终止我的文件。这应该是代码中的一个简单错误,但我真的找不到它在哪里。任何帮助都将不胜感激。这是代码:

#include <iostream>
using namespace std;
#include <fstream>
#include<time.h> 
#include<stdlib.h>
typedef unsigned char byte;
int main(int argc, char **argv)
{
if(argc!=3)
{
cout<<"Usage is: "<<argv[0]<< " [stride] [steps]"<<endl;
return 0;
}

int stride = atoi(argv[1]);
int steps  = atoi(argv[2]);
int totalSize = stride * steps;
// print some info about the system
cout<<"size of int: "<<sizeof(int)<<endl;
cout<<"stride: "<<stride<<endl;
cout<<"total size: "<<totalSize<<endl;
byte *dataArray = new byte[totalSize];
//  init array data
//for(int i=0;i<totalSize;i++)
//  dataArray[i] = 1;
// traverse array and measure time
struct timespec start, stop;
//save start time 
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
long result = 0;
for(int i=0; i<totalSize;i + stride)
{
result += dataArray[i];
}
for(int i=0;i<totalSize;i+=stride)
result += dataArray[i];
//save end time 
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop);
ofstream myfile;
// myfile.open("data.csv");
// calc elapsed time
double cpuTime = (stop.tv_sec - start.tv_sec) * 1e6 + (stop.tv_nsec - start.tv_nsec) / 1e3;    // in micros
// myfile << "%d",cpuTime;
// myfile.close();
// report results
cout<<"Calculation: "<<result<<endl;
cout<<"CPU time micro: "<<cpuTime<<endl;
return 0;
}
for(int i=0; i<totalSize;i + stride)

您永远不会递增i