problem with sharing data

General OpenMP discussion

problem with sharing data

Postby amir1981 » Thu Dec 05, 2013 5:45 pm

Hi,
I am developing a C++ program that use another C++ class named Database to access the data. I have a loop inside one of my member functions that I like to make parallel (80% of time program spends in this loop). Over all there are two C++ classes that share data through Database.
The main class is named HDPHMM and has a member named db_d (defined as Database *db_d); The other class name is DPM and similarly has its own db_d. All these db_ds are pointing to the same database and therefore when we tell db_d in class HDPHMM to show data point number 2 , db_d in class DPM will show the same data point. Here is the piece of code that I want to make parallel:
emissions_d is a vector of DPMs objects. So basically we loop over all data points and using db->get(data_records) we call the current data point (which both this class and DPM class has access to)
I know that I could not make db_d private and since it is shared by all threats it cause error like this:
*** glibc detected *** ./hdphmm_test.exe: double free or corruption (out): 0x00\
007ffdd40008c0 ***
(when I compile and run with openMP directives before the main loop) I can move openMP directives inside the main loop (for example for the first loop over kz shown below and it works but it is not the most desirable way for me (since I rather to distribute the data among threads instead of distribute running emission objects ) I wonder if there is anyway to tackle this problem. I also should mention that I am new to openMP

// loop over all data points
//
for (int32 data_records = 0; data_records < db_d->get_records_no(); data_records++){

// read the data
//
db_d->get(data_records);

// seqeuece length
//
int32 T = db_d->curr_data_d.getNumColumns();

// compute the log likelihood
// at each call "log_likelihood" variable will be updated by the likelihood
// the current point (points accessed successively)
//

// compute the likelihood for each emission distribution
// without normaliztion
//
for (int32 kz = 0 ;kz< Kz_d; kz++)
emissions_d(kz).compute_loglikelihood(false);


....

}
amir1981
 
Posts: 2
Joined: Thu Dec 05, 2013 5:08 pm

Re: problem with sharing data

Postby MarkB » Fri Dec 06, 2013 5:06 am

It is likely that the methods of db_d are not thread-safe. You could try enclosing all such calls in OpenMP critical constructs and see if that works.
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 8 guests