小编akh*_*288的帖子

pthread_join是一个瓶颈

我有一个应用程序,pthread_join它是瓶颈.我需要帮助来解决这个问题.

void *calc_corr(void *t) {
         begin = clock();
         // do work
         end = clock();
         duration = (double) (1000*((double)end - (double)begin)/CLOCKS_PER_SEC);
         cout << "Time is "<<duration<<"\t"<<h<<endl;
         pthread_exit(NULL);
}

int main() {
         start_t = clock();

         for (ii=0; ii<16; ii++) 
            pthread_create(&threads.p[ii], NULL, &calc_corr, (void *)ii);

         for (i=0; i<16; i++) 
            pthread_join(threads.p[15-i], NULL);

         stop_t = clock();

         duration2 = (double) (1000*((double)stop_t - (double)start_t)/CLOCKS_PER_SEC);
         cout << "\n Time is "<<duration2<<"\t"<<endl;

         return 0;
}
Run Code Online (Sandbox Code Playgroud)

螺纹功能中打印的时间范围为40ms - 60ms,主要功能中打印的时间为650ms - 670ms.具有讽刺意味的是,我的串行代码运行时间为650毫秒 - 670毫秒 …

c++ performance multithreading pthreads

2
推荐指数
1
解决办法
894
查看次数

如何在vim中跳过两行并删除两行直到文件末尾?

我想跳过两行并删除两行直到文件末尾

如果我的文件包含

111
222
333
444
555
666
777
888
999
1010
1111
Run Code Online (Sandbox Code Playgroud)

我想修改它看起来像

111
222
555
666
999
1010
Run Code Online (Sandbox Code Playgroud)

linux vi vim awk sed

1
推荐指数
1
解决办法
115
查看次数

将浮点数读入动态分配的数据,同时在读取文件时增加数组的大小

我试图从文件中读取浮点数到动态分配的2D数组.我正在使用c ++.

在我的.txt文件中,行的元素由制表符空间分隔,每行以新行开头.

我的问题是 -

我可以根据编号增加数组的大小吗?文件中存在的元素(行和列)?如果是这样,请建议一种方法.

我想写了不.在文本文件的第一行上的行和列,并在开头读取它们以设置将为我的数组分配空间的循环限制.有没有更好的方法,可能基于文本文件的格式?这样,我认为它将更接近流数据类型的场景.

提前致谢.

AKHIL

c++ arrays file-io

0
推荐指数
1
解决办法
1420
查看次数

标签 统计

c++ ×2

arrays ×1

awk ×1

file-io ×1

linux ×1

multithreading ×1

performance ×1

pthreads ×1

sed ×1

vi ×1

vim ×1