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).
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hello Gengbing,
yes, that should work.
Very good.
But CCTK_stdout may also need to be thread private variable to avoid race condition by multiple SMP threads.
Hmm, not sure I fully follow. Is it that for a run using AMPI, there would be N pthreads (for an N core machine) but each one of those pthreads would contain M user threads and so there would be N*M AMPI ranks. Is this what you are thinking about?
This actually makes it harder since we have to worry about __thread and (for non-AMPI runs) the pthreads that OpenMP creates and which need to have their output FILE pointer initialized to that of the owning process.
So this will be similar to what I proposed to have a cctk_printf function.
Basically the cctk_printf functions are cctk_VWarn and cctk_VInfo.
Yours, Roland
- -- My email is as private as my paper mail. I therefore support encrypting and signing email messages. Get my PGP key from http://keys.gnupg.net.
users@lists.einsteintoolkit.org