Tag: 开销

Struct对类型大小的贡献

我想知道为什么以下两种类型 struct { double re[2]; }; 和 double re[2]; 在C中具有相同的大小? struct不会增加一点大小开销吗?

OpenMP特定线程数急剧减速

我运行了一个OpenMP程序来执行Jacobi方法,它运行得非常好,2个线程执行略超过2x 1线程,4个线程比1个线程快2倍。 我觉得一切都很完美……直到我准确地达到了20,22和24个线程。 我一直把它分解,直到我有这个简单的程序 #include #include int main(int argc, char *argv[]) { int i, n, maxiter, threads, nsquared, execs = 0; double begin, end; if (argc != 4) { printf(“4 args\n”); return 1; } n = atoi(argv[1]); threads = atoi(argv[2]); maxiter = atoi(argv[3]); omp_set_num_threads(threads); nsquared = n * n; begin = omp_get_wtime(); while (execs < […]

使用背靠背rdtsc进行负时钟周期测量?

我正在编写一个C代码,用于测量获取信号量所需的时钟周期数。 我正在使用rdtsc,在对信号量进行测量之前,我连续两次调用rdtsc来测量开销。 我在for循环中重复了这么多次,然后我使用平均值作为rdtsc开销。 这是正确的,首先要使用平均值吗? 尽管如此,这里的一个大问题是,有时我会得到开销的负值(不一定是平均值,但至少是for循环中的部分值)。 这也会影响sem_wait()操作所需的cpu周期数的连续计算,有时也会产生负数。 如果我写的不清楚,这里有一部分我正在编写的代码。 为什么我会得到这样的负值? (编者注:请参阅获取CPU周期计数?以获得完整的64位时间戳的正确和可移植方式。 “=A” asm约束仅在编译为x86-64时获得低或高32位,具体取决于寄存器分配是否恰好为uint64_t输出选择RAX或RDX。它不会选择edx:eax 。) (编辑的第二个注释:哎呀,这就是为什么我们得到负面结果的答案。仍然值得留下一个注释,作为警告不要复制这个rdtsc实现。) #include #include #include #include #include static inline uint64_t get_cycles() { uint64_t t; // editor’s note: “=A” is unsafe for this in x86-64 __asm volatile (“rdtsc” : “=A”(t)); return t; } int num_measures = 10; int main () { int i, value, res1, […]