title: OpenMP and OOP (Molecular Dynamics Simulation)
body: <p>I’m conducting a molecular dynamics simulation, and I’ve been struggling for quite a while to implement it in parallel, and although I succeeded in fully loading my 4-thread processor, the computation time in parallel is greater than the computation time in serial mode. </p>
  
  <p>Studying at which point of time each thread starts and finishes its loop iteration, I’ve noticed a pattern: it’s as if different threads are waiting for each other. 
  It was then that I turned my attention to the structure of my program. I have a class, an instance of which represents my system of particles, containing all the information about particles and some functions that use this information. I also have a class instance of which represents my interatomic potential, containing parameters of potential function along with some functions (one of those functions calculates force between two given particles). </p>
  
  <p>And so in my program there exist instances of two different classes, and they interact with each other: some functions of one class take references to instances of another class. 
  And the block I’m trying to implement in parallel looks like this:</p>
  
  <pre><code>      void Run_simulation(Class_system &amp;system, Class_potential &amp;potential, some other arguments){
            #pragma omp parallel for
                for(…) 
        }
  </code></pre>
  
  <p>for(...) is the actual computation, using data from the <code>system</code> instance of the <code>Class_system</code> class and some functions from the<code>potential</code> instance of the <code>Class_potential</code> class. </p>
  
  <p>Am I right that it’s this structure that’s the source of my troubles?</p>
  
  <p>Could you suggest me what has to be done in this case? Must I rewrite my program in completely different manner? Should I use some different tool to implement my program in parallel?</p>