[Users] [Einstein Toolkit] #1548: stdout redirection in multithreading scenario

Gengbin Zheng gzheng at illinois.edu
Thu May 22 15:28:31 CDT 2014


yes, that should work.
But CCTK_stdout may also need to be thread private variable to avoid 
race condition by multiple SMP threads.
So this will be similar to what I proposed to have a cctk_printf function.

Gengbin

On 5/22/2014 1:53 PM, Einstein Toolkit wrote:
> #1548: stdout redirection in multithreading scenario
> ----------------------------------+-----------------------------------------
>    Reporter:  gzheng@…             |       Owner:
>        Type:  defect               |      Status:  reopened
>    Priority:  major                |   Milestone:
>   Component:  Cactus               |     Version:  development version
> Resolution:                       |    Keywords:  stdout redirection
> ----------------------------------+-----------------------------------------
>
> Comment (by rhaas):
>
>   After Gengbing's talk today and studying #1618, would it be possible to do
>   something as simple as this:
>   {{{
>   static AMPI_TLS FILE *CCTK_stdout = NULL;
>   ...
>   CCTKi_CommandLineFinished(...)
>   {
>   ...
>   if(CCTK_MyProc(cctkGH) != 0) {
>     CCTK_stdout = fopen("CCTK_ProcX.out");
>   } else {
>     // or just = stdout since we never close the file handle anyway
>     CCTK_stdout = freopen(stdout);
>   }
>   ...
>   }
>   }}}
>   ?
>
>   We would then use CCTK_stdout in CCTK_VWarn etc. We'd still keep the
>   {{{dup()}}} code around for the benefit of Fortran code that does
>   {{{write(*,*)}}} etc. and requires redirecting the OS level file
>   descriptors (which may need some code to protect against multiple AMPI
>   ranks trying to redirect the same file descriptor). Such Fortran code
>   would not be compatible with AMPI (not much we can do about this I think
>   unless we want to change the file descriptors each time the thread
>   changes).
>
>   This would make this ticket a sub-ticket of #1618 (supporting AMPI).
>



More information about the Users mailing list