1

I have a for loop in c++ parallelized using OpenMP. In the loop, I am accessing an sql server database. I have been told that if I share the same ODBC driver between threads, the data access would not be parallel. If I define different drivers for each iteration, it would be time consuming.(?) Is there a way to have different threads access the same data in a safe parallel manner?

PS: I am not writing to the database, just reading from it.

isometry
  • 11
  • 2
  • I am not so sure but you can refer the below link might be you can get some idea on accessing the same data by two or more threads parallely :- http://stackoverflow.com/questions/5365941/is-boostinterprocessshared-ptr-threadsafe-and-interprocess-safe – Abhineet May 17 '12 at 09:36

1 Answers1

0

I have been told that if I share the same ODBC driver between threads, the data access would not be parallel.

Are you sure that you have told exactly this?

There are lot of issues about multithread, but for most ODBC drivers you can use connection-per-thread model to do reading in parallel. So connect each time you start thread (and close when thread is shut-downed). Better pattern will be usage of connection pool.

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • Yes. To give more context to the problem, I have a 10k cross 100k matrix of numbers on the database and each thread takes a linear combination of these columns and then sort it. Since different threads are unrelated, they could be be parallel. I think sorting in sql would be faster than in c++.(?) – isometry May 17 '12 at 19:46
  • It depends on ODBC driver, but most of the nowadays ones support parallel handling. MSSQL, Postgress, Oracle ... grants that readonly operations will be executed in parallel very good. Use 'thread-per-connection' model for this. – Dewfy May 18 '12 at 07:47