我想创建一个线程池.我有一个名为ServerThread.cpp的类,其构造函数应该执行以下操作:
ServerThread::ServerThread()
{
for( int i=0 ; i<init_thr_num ; i++ )
{
//create a pool of threads
//suspend them, they will wake up when requests arrive for them to process
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道在构造函数中创建pthreads是否会导致任何应该避免进入的未定义行为.
谢谢
我写了一个包含内联汇编代码的简单程序.我的代码只是添加了变量a和b,并在b中返回结果.
令我困惑的是为什么下面的代码生成了这个指令movl 28(%esp),%ecx.
我没有完全承担修饰符+和=在输入和输出列表中扮演的角色.如果你能对此有所了解,我们将不胜感激.
#include <cstdio>
int main( int argc , char ** argv )
{
int a = 2, b = 7;
__asm__
(
"addl %1,%0;"
:"+r"(b)
:"r"(a), "r"(b)
);
printf("b = %d\n",b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)movl $2, 24(%esp) movl $7, 28(%esp) movl 24(%esp), %edx movl 28(%esp), %ecx movl 28(%esp), %eax addl %edx,%eax movl %eax, 28(%esp)
我接下来要展示的是错误的.但这是为了让我更好地了解海湾合作委员会的情况.
好的,现在我从+ r变为= r.这是GCC生成的汇编代码.
#include <cstdio>
int main( int argc , char ** argv )
{
int a = 2, b = 7; …Run Code Online (Sandbox Code Playgroud) 我的应用程序与 LAM/MPI 一起工作,但它与 OpenMPI 一起崩溃。
下面是我的代码的外观。
void Comm::nonblocking_send( int s_idx , int e_idx )
{
MPI_Wait(&mpireq,&mpistat);
buffer.clear();
list<class vertex*>::iterator vit;
for( vit=our_dag->cur_block_intmeds.begin() ; vit!=our_dag->cur_block_intmeds.end() ; vit++ )
{
vertex * v = (*vit);
list<class edge*> in_edges = v->in_edges;
list<class edge*>::iterator eit;
for( eit=in_edges.begin() ; eit!=in_edges.end() ; eit++ )
{
int x_idx = (*eit)->src->idx;
int y_idx = (*eit)->tgt->idx;
double dydx = (*eit)->partial;
struct partial * p = new partial();
//ownership info
p->rank = our_dag->rank;
//structural info
p->x_idx = x_idx;
p->y_idx = …Run Code Online (Sandbox Code Playgroud) 我正在考虑为MPI实现一个模仿OpenMP并行化循环方式的包装器.
begin_parallel_region( chunk_size=100 , num_proc=10 );
for( int i=0 ; i<1000 ; i++ )
{
//some computation
}
end_parallel_region();
Run Code Online (Sandbox Code Playgroud)
上面的代码将for循环中的计算分配给10个从MPI处理器.在进入并行区域时,提供块大小和从处理器的数量.在离开并行区域时,MPI处理器被同步并被置于空闲状态.
编辑以回应高性能标志.
我无意模拟OpenMP的共享内存模型.我提出这个是因为我需要它.我正在开发一个从数学函数构建图形所需的库.在这些数学函数中,经常存在如下所示的循环.
for( int i=0 ; i<n ; i++ )
{
s = s + sin(x[i]);
}
Run Code Online (Sandbox Code Playgroud)
所以我想首先能够将sin(x [i])分发给从属处理器,最后减少到单个变量,就像在OpenMP中一样.
我想知道是否有这样的包装,所以我不必重新发明轮子.
谢谢.
在下面的代码中,如果我调用v.resize(n),程序将打印出0 0 0 0 0 0 0 0 0 0,这不是我想看到的.但是,如果我对包含v.resize(n)的行进行注释,它将打印出0 1 2 3 4 5 6 7 8 9,这是我想要看到的.为什么会这样?我的逻辑在这里有什么问题?
#include <iostream>
#include <vector>
using namespace std;
int main( int argc , char ** argv )
{
int n = 10;
vector<int> v;
v.resize(n);
for( int i=0 ; i<n ; i++ )
{
v.push_back(i);
}
for( int i=0 ; i<n ; i++ )
{
cout << v[i] << " ";
}
cout << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在我的代码中,我有一个服务器进程反复探测传入的消息,它有两种类型.每个进程将发送一次这两种类型,以向服务器进程提供有关其终止的提示.
我想知道使用MPI_Broadcast广播这些终止消息并使用MPI_Probe来探测其到达是否有效.
我尝试使用这种组合,但失败了.这种失败可能是由其他一些事情引起的.所以我想任何知道此事的人都要确认一下.
c++ ×3
mpi ×3
c ×2
assembly ×1
constructor ×1
containers ×1
gcc ×1
nonblocking ×1
openmp ×1
openmpi ×1
pthreads ×1
stl ×1
threadpool ×1
vector ×1