C++ 当我调用C++;在openmp循环中初始化方法
大家早上好 我制作了一个在单线程模式下运行的代码,并尝试在多线程模式下对其进行调整。 我在单线程模式下运行的方法非常类似于MARCH::RUN_PAR,结果很好,但是当我尝试在多线程模式下执行(使用Openmp)时,结果太奇怪了 有人能帮我解决这个问题吗 下面是我的代码:C++ 当我调用C++;在openmp循环中初始化方法,c++,openmp,C++,Openmp,大家早上好 我制作了一个在单线程模式下运行的代码,并尝试在多线程模式下对其进行调整。 我在单线程模式下运行的方法非常类似于MARCH::RUN_PAR,结果很好,但是当我尝试在多线程模式下执行(使用Openmp)时,结果太奇怪了 有人能帮我解决这个问题吗 下面是我的代码: void MI_MARCH::RUN_PARALELO(double zt,double ***Vpar,int mt,int red_yred,int prof,int tam) { int RANK, n
void MI_MARCH::RUN_PARALELO(double zt,double ***Vpar,int mt,int red_yred,int prof,int tam) {
int RANK, numero_proc_parall;
int shift,cont,m,rredy;
//start the number of (possible) threads
numero_proc_parall = tam;
//shift the loop of threads
shift = 0;
//the necessary total number of threads
cont = prof;
//set the number of threads
omp_set_num_threads(numero_proc_parall);
//argument initialization
rredy = red_yred;
MARCH VETOR_MARCH[numero_proc_parall]; //vector of class
//open the parallel section
#pragma omp parallel shared(cont,shift,numero_proc_parall) private(red_yred,RANK,m)
{
while(cont > 0)
{
#pragma omp critical
std::cout<<"[MI_MARCH RUN_PAR] loop cont "<<cont<<" shift "<<shift<<" numero_proc_parall "<<numero_proc_parall<<"\n";
#pragma omp for
for(m=0;m<numero_proc_parall;m++) //loop de profundidade
{
//atualize the rank
RANK = omp_get_thread_num();
//set the reference
red_yred = rredy + m + shift
//run the method of the MARCH class
VETOR_MARCH[m].RUN_PAR(zt,Vpar[m],mt,red_yred,RANK + shift);
}
//execute only in the master thread
#pragma omp master
{
//increment the shift variable
shift = shift + numero_proc_parall;
//decrement the loop control
cont = cont - numero_proc_parall;
//verify if the process is greater than controller
if(cont<numero_proc_parall)
{
//set a new number of parallel process
numero_proc_parall = cont;
}
}
#pragma omp barrier //waiting other process
}
}
}
void MI_MARCH::并行运行(双zt、双***Vpar、内mt、内红色、内专业、内tam){
整数秩,进程并行数;
int移位,cont,m,rredy;
//开始(可能的)线程数
数字过程参数=tam;
//移动线程的循环
移位=0;
//所需的线程总数
cont=教授;
//设置线程数
omp_集合_num_线程(numo_proc_parall);
//参数初始化
rredy=红色;
MARCH VETOR_MARCH[numero_proc_parall];//类的向量
//打开平行部分
#pragma omp并行共享(cont、shift、numero\u proc\u parall)私有(red\u yred、RANK、m)
{
而(续>0)
{
#pragma-omp-critical
std::coutWelcome to Stack Overflow!寻求调试帮助的问题(“为什么这段代码不工作?”)必须包含期望的行为、特定的问题或错误,以及在问题本身中需要复制的最短代码。没有明确问题陈述的问题对其他读者是没有用的。请参见:<代码> RunsPar < /C> >的原型。请考虑进程和线程之间的差异。OpenMP使用线程,而不是进程。这使您的问题很难理解。您能包括Vcopia
的定义吗?您确定void MARCH::RUN_PAR(双zt,双**Vxy,int mt,int red_yred,int RANK)之后和{
之前的分号没有引起问题吗?
void MARCH::RUN_PAR(double zt,double **Vxy,int mt,int red_yred,int RANK);
{
int xf,yf;
xf = 100;
yf = 100;
//execute this piece of code in critical mode
#pragma omp critical
{
for(int i=0;i<xf;i++)
{
for(int j=0;j<yf;j++)
{
Vcopia[i][j] = Vxy[i][j]; //Vcopia is a member of MARCH class
}
}
}
V_H(Vcopia,xf,yf,red_yred); //this method is a member of MARCH class
CALC(mt,zt,RANK); //this method is a member of MARCH class
}
...
class MARCH{
public:
...
void RUN_PAR(double zt,double **Vxy,int mt,int red_yred,int RANK);
private:
...
double **Vcopia;
...
void V_H(double **Vcopia,int xf,int yf,int red_yred);
void CALC(int mt,double zt,int RANK);
};