Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

A simple pipeline parallel problem

chbq
Beginner
739 Views
Hi,I have a simple program that calculate the average of the array elements
A=(A[i+1]+A[i-1]+A[j+1]+A[j-1])/2. (0
they have data dependancy so I use pipeline parallel?
I use a array lock as a lock,at first ,initialize all of the data to 0,and initialize the A[0]=1 (,j=0 to N-1); if A[i-1] is calculated ,,the A can calculate at the same time.
however ,I found that theP_Calculation in the following program only work wheniN/2, they do not work.
#include "stdafx.h"
#include "iostream"
#include "vector"
#include "string"
#include "fstream"
#include "iomanip"
#include
#include "omp.h"
using namespace std;
const int N=10;
const string Before="D:\DEMO\Before.txt";
const string SAfter="D:\DEMO\SAfter.txt";
const string PAfter="D:\DEMO\PAfter.txt";
void Init(int nsize,vector &Vec)
{
int i,j,k;
for(i=0;ifor (j=0;j{
Vec[i*nsize+j]=i*N+j;
}
// random_shuffle(Vec.begin(),Vec.end());
}
void OutPut(const string str,int nsize,vector &Vec)
{
ofstream ofs(str.c_str());
ofs<int i,j,k;
for(i=0;ifor (j=0;j{
ofs.precision(4);
if((i*nsize+j)%8==0)
ofs<ofs<
}
}
void Calculation(int nsize,vector &Vec)
{
int i,j,first,ix,xi,jy,yj;
for(i=1;ifor (j=1;j{
first=i*nsize+j;//A
ix=(i-1)*nsize+j;//A[i-1]
xi=(i+1)*nsize+j;//A[i+1]
jy=first-1; //A[j-1]
yj=first+1; //A[j+1]
Vec[first]=(Vec[ix]+Vec[xi]+Vec[jy]+Vec[yj])/2.0f;
}
}
void P_Calculation(int nsize,vector &Vec,vector &lock)
{
int i,j,first,ix,xi,jy,yj;
for(i=0;ifor(j=0;jlock[i*nsize+j]=0;
for(i=0;ilock=1;
#pragma omp parallel for private(i,j,first,ix,xi,jy,yj) default(shared) num_threads(2)
for(i=1;ifor (j=1;j{
first=i*nsize+j;//A
ix=(i-1)*nsize+j;//A[i-1]
xi=(i+1)*nsize+j;//A[i+1]
jy=first-1; //A[j-1]
yj=first+1; //A[j+1]
if(lock[ix]==1) //if the A[i-1] is calculated
{
Vec[first]=(Vec[ix]+Vec[xi]+Vec[jy]+Vec[yj])/2.0f;
lock[first]=1;
}
}
}
int main(int argc, char* argv[])
{
vector fVec(N*N,0);
vector fVect(N*N,0);
vector mylock(N*N,0);
cout<<"Test is running... "<
Init(N,fVec);
Calculation(N,fVec);
OutPut(SAfter,N,fVec);
Init(N,fVect);
OutPut(Before,N,fVect);
P_Calculation(N,fVect,mylock);
OutPut(PAfter,N,fVect);
cout<<"Test is ended..."<return 0;
}
if remove the openmp clause,the P_Calculation and the Ca lculation function get the same result. but I do not know why the P_Calculation not work when i>N/2; can you give me some suggestion? thank you !
0 Kudos
2 Replies
pbkenned1
Employee
739 Views

The example you posted has numerous syntax errors:

C:>icl -Qopenmp simple.cpp
Intel C++ Compiler for 32-bit applications, Version 8.1 Build 20060606Z Package ID: w_cc_pc_8.1.038
Copyright (C) 1985-2006 Intel Corporation. All rights reserved.

simple.cpp
simple.cpp(19): error: argument list for class template "std::vector" is missing

void Init(int nsize,vector &Vec)
^

simple.cpp(22): error: expected a ";"
for(i=0;i for (j=0;j {
^

simple.cpp(54): error: this pragma must immediately precede a statement
#pragma omp parallel for private(i,j,first,ix,xi,jy,yj) default(shared) num_th
reads(2)
^

simple.cpp(71): warning #12: parsing restarts here after previous syntax error
vector fVect(N*N,0);
^

simple.cpp(72): error: argument list for class template "std::vector" is missing

vector mylock(N*N,0);
^

simple.cpp(72): error: expected a ")"
vector mylock(N*N,0);
^

simple.cpp(84): warning #12: parsing restarts here after previous syntax error
}
^

simple.cpp(84): error: expected a statement
}
^

compilation aborted for simple.cpp (code 2)

If you will please file an IntelPremier Support issue, and attach (not copy/paste) a test case that we can compile and run, we will be happy to investigate your issue. Please ask that the issue be directed to Patrick.

Thank you,

Intel Compiler Support

0 Kudos
chbq
Beginner
739 Views
Thanks for your replying, I have solved this problem ,I synchronize the threadsby the lockfunctions of OpenMP,or define aarray for synchronization.Ican not getthe code of that simple testbecause of my Visual SourceSafe has some problem. I don't know how to attach a file to the forum,so paste the code may result in some problem.
0 Kudos
Reply