Page 1 of 1

Problem in vector looping and i/o

PostPosted: Wed May 08, 2013 2:46 am
by Rajesh1978
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

Re: Problem in vector looping and i/o

PostPosted: Wed May 08, 2013 4:48 am
by MarkB
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.

Re: Problem in vector looping and i/o

PostPosted: Wed May 08, 2013 5:14 am
by Rajesh1978
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

Re: Problem in vector looping and i/o

PostPosted: Wed May 08, 2013 7:08 am
by Rajesh1978
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

Re: Problem in vector looping and i/o

PostPosted: Wed May 08, 2013 8:25 am
by MarkB
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....

Re: Problem in vector looping and i/o

PostPosted: Wed May 08, 2013 12:18 pm
by ftinetti
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.

Re: Problem in vector looping and i/o

PostPosted: Thu May 09, 2013 3:54 am
by MarkB
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.