Problem in vector looping and i/o

General OpenMP discussion

Problem in vector looping and i/o

Postby Rajesh1978 » Wed May 08, 2013 2:46 am

Hi,
I am new to Open MP
I used Open MP to do some DB Operation.

I have a vector with size 99999
i have the code like this
Code: Select all
int numThreads=50;
int count=0;
double start=omp_get_wtime();
#pragma omp parallel for default(shared) private (count) num_threads(numThreads)
    for(count=0;count< MsgQInfo.size();++count) //MsgQInfo is a structure
    {
      //code to insert into the table Table_To_insert with seqNo as count
      //delete from the table Table_To_delete where seqNo as count
    }


I always see there is some mismatch i.e.
It should insert record with sequence num 1 to 99999 Table_to_insert
and it should delete sequence num from 1 to 99999 from Table_to_delete

but i see some 3400 +
recoreds are left out in the Table_to_delete

I am using Linux gcc 4.1 (presently i do not have higher version)
Please help me
Am i missing anything
or any better way to do this
I see that There is
Rajesh1978
 
Posts: 5
Joined: Sun Apr 21, 2013 11:21 pm

Re: Problem in vector looping and i/o

Postby MarkB » Wed May 08, 2013 4:48 am

Hi there,

Are you sure that there are no other variables inside the loop which ought to be declared private?
It is possible that the database functions you are calling are not actually thread-safe: is there any documentation to suggest that they are?

Hope that helps,
Mark.
MarkB
 
Posts: 447
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Problem in vector looping and i/o

Postby Rajesh1978 » Wed May 08, 2013 5:14 am

i pick one element from the vector.
The vector contains a structure as element

I insert one element (value taken from the structure) into the Table_To_insert
and i delete the same element from the Table_To_delete.

e.g. v[0]= structExample [ int val 0]
...
v[99999] = structExample [ int val 99999 ]

so i insert 0 then delete 0, insert 1 then delete 1 ... upto 99999

The db operation is thread safe.

Only I doubt the structure or the way I am doing
Rajesh1978
 
Posts: 5
Joined: Sun Apr 21, 2013 11:21 pm

Re: Problem in vector looping and i/o

Postby Rajesh1978 » Wed May 08, 2013 7:08 am

Now i have separated the insertion and deletion into two loops

the insertion has no imapact if you do with omp or not with omp.

But the loop where i do the deletion is below
Code: Select all
int count1;
#pragma omp parallel for default(shared) num_threads(numThreads)
    for(count1=0;count1<expiredMsgsClientMsgQInfo.size();++count1)
    {
#pragma omp critical(delpor) // IF I DO NOT GIVE THIS PRAGMA THEN THE SOME ENTRIES ARE NOT GETTING DELTED
            {
        NtfnMgrCommonUtilities::deleteMsgQEntry(expiredMsgsClientMsgQInfo[count1].mClientMdn,
                expiredMsgsClientMsgQInfo[count1].mSequenceNumber);
            }

    }



AND IF I GIVE THE PRAGMA FOR CRITICAL SECTION THEN THE PERFORMANCE IS NOT INCREASING
PLEASE SUGGEST
Rajesh1978
 
Posts: 5
Joined: Sun Apr 21, 2013 11:21 pm

Re: Problem in vector looping and i/o

Postby MarkB » Wed May 08, 2013 8:25 am

I can only see 3 possibilities here:

1) deleteMsgQEntry() isn't actually thread safe.
2) expiredMsgsClientMsgQInfo.size() is not loop invariant or side-effect free.
3) a compiler bug.

The fact that you get the right answer with the critical region makes me think 1) is the most likely....
MarkB
 
Posts: 447
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Problem in vector looping and i/o

Postby ftinetti » Wed May 08, 2013 12:18 pm

Hi,

Besides I agree on
The fact that you get the right answer with the critical region makes me think 1) is the most likely....

if most (or all) of the work is i/o, I think there will not be much gain in trying to do it in parallel, since parallel i/o is usually not implemented/feasible.

HTH,

Fernando.
ftinetti
 
Posts: 581
Joined: Wed Feb 10, 2010 2:44 pm

Re: Problem in vector looping and i/o

Postby MarkB » Thu May 09, 2013 3:54 am

Rajesh1978 wrote:I am using Linux gcc 4.1 (presently i do not have higher version)


That's a very old OpenMP implementation: it would be worth trying an up-to-date version of gcc.
MarkB
 
Posts: 447
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 9 guests