试图对缓存进行跨步测试,但程序并没有结束
trying to do a stride test of the cache but program is not ending
我正试图对缓存进行跨步测试,但我的代码中出现了一个错误,导致程序永远无法结束。我不得不自己终止我的文件。这应该是代码中的一个简单错误,但我真的找不到它在哪里。任何帮助都将不胜感激。这是代码:
#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
。
相关文章:
- 试图对缓存进行跨步测试,但程序并没有结束
- 通过 g++ 运行程序时没有这样的文件或目录
- 我怎样才能有 2 个程序并让用户选择他们想要使用的程序?
- 我的 c++ 程序似乎没有发现字符串和我拥有但输入使用 getline 的变量之间的比较
- 如果程序在没有 sudo 的情况下运行,gtk_init会导致 ubuntu 16.04 崩溃
- C++程序编译没有问题,但无法运行
- 如何使用CLion和MSVC编译器工具链编译wxWidgets Hello World应用程序而没有错误?
- 即使在我关闭应用程序并重新启动它后,如何保持我的 ID 被阻止?
- Cassandra C++ MacOS High Sierra上的驱动程序:make:没有规则来制作目标
- 否则在新程序中没有以前的 if 错误
- 是否有可能让 c++ dll 在后台运行 python 程序并让它填充向量图?如果是这样,如何?
- 编译 Fortran 和C++程序并从英特尔编译器链接
- 程序在没有操作系统信号的情况下在函数中的特定行挂起
- 程序在没有输入的情况下退出,它有基本的,驱动的类属性初始化问题
- 如何在程序崩溃时关闭程序,没有任何警告屏幕等.C++窗口
- 睡眠:(睡眠或usleep)并没有将我的线程中的所有内容悬挂在Linux中,而是在Windows中悬挂吗?为什么
- C++ std::unique并没有显示我对它的期望
- OpenGL并没有渲染我的立方体
- 尝试制作矩形时C++程序中没有输出
- 我的程序并没有使我成为我想做的事情