Tasks executed by thread 0 only

General OpenMP discussion
Post Reply
FabriceRoy
Posts: 2
Joined: Mon Aug 10, 2020 6:39 am

Tasks executed by thread 0 only

Post by FabriceRoy »

Hello,
I am trying to use tasks in a hybrid MPI / OpenMP Fortran code.
I would like to write data on disk with thread 0 only, and I would like to use tasks for this.
Ideally threads others than 0 will process data and then create a "write" task that thread 0 only can execute.
Is this possible? If it is, how can I do this?
Thanks for your help,
Fabrice

MarkB
Posts: 803
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Tasks executed by thread 0 only

Post by MarkB »

There is no way to specify which thread executes a task. Most likely you do not need to restrict file I/O to thread 0, as long as you don't have multiple tasks/threads trying to write the same file concurrently. But a pattern like this might work for you:

Code: Select all

#pragma omp parallel 
{
#pragma omp master
  {
< create compute tasks > 
#pragma omp taskwait 
<write to file> 
....
  }
}

FabriceRoy
Posts: 2
Joined: Mon Aug 10, 2020 6:39 am

Re: Tasks executed by thread 0 only

Post by FabriceRoy »

Ok, thanks for your reply.

Post Reply