views:

116

answers:

1

I have a section of a Fortran90 program that should be parallelized with OpenMP.

!$omp parallel num_threads(8) &
!$omp private(j, s, prop_states) &
!$omp firstprivate(targets, pulses)
  ! ... modify something in pulses. targets(s)%ham contains pointers to
  ! elements of pulses ...
  do s = 1, n_systems
    prop_states(s) = targets(s)%psi_i
    call prop(prop_states(s), targets(s)%grid, targets(s)%ham, &
    &         targets(s)%work, para)
  end do
!$omp end parallel

What I'm unsure about is whether complex data structures can be private to each thread (and how this should be done -- is firstprivate correct?). In the example code above, targets is of a somewhat complicated user-defined type, with equally complex sub-fields. For example, targets(s)%ham%op(1)%pulse is a pointer to some element of an array pulses. Also, targets(s)%work contains allocated space to be used as work arrays in Fast-Fourier-Transforms.

Obviously, every thread needs to maintain an independent copy both of targets and of pulses, and maintain the pointers between the two independently. It seems to me that this might be asking a little bit too much from the automatic memory management of OpenMP. Is this correct, or should this work out of the box?

The alternative of course is to create copies of the original data within each thread (stored in an array), and use this private copied data in the call to prop.

A: 

Hi Michael

From my reading of the OpenMP 2.5 standard you can't use the targets of Fortran pointers in private (or firstprivate or threadprivate) clauses, which seems to rule out your code. Having said that, it's not something I've ever tried in OpenMP so if you bash ahead and get anywhere, do let us know.

And firstprivate is correct if your private variables are to be initialised, on entry into the parallel region, with the value of the variables of the same name at the entry to the parallel region.

I guess you will probably have to implement your plan B.

Regards

Mark

High Performance Mark

related questions