Write statement in main.F
Moderators: Global Moderator, Moderator
-
- Newbie
- Posts: 12
- Joined: Fri Jan 27, 2023 5:26 pm
Write statement in main.F
I wrote a small subroutine that I added to the end of "SUBROUTINE ELECTRONIC_OPTIMIZATION" in main.F. Everything seems to be working as planned; however, when I write to OUTCAR, e.g. WRITE(IO%IU6,*) "test", the output also appears in the stdout. No big deal, however, the output appears N times (N = number of processors) in the stdout. Note, it only appears once in OUTCAR. How do I stop it from writing to stdout or at least N times? Thanks for any help.
-
- Global Moderator
- Posts: 418
- Joined: Mon Sep 13, 2021 11:02 am
Re: Write statement in main.F
Is IO%IU6 properly defined? Would it work with 8:
WRITE(8,*) "test"
WRITE(8,*) "test"
-
- Newbie
- Posts: 12
- Joined: Fri Jan 27, 2023 5:26 pm
Re: Write statement in main.F
I passed IO in but I guess something is not defined correctly. WRITE(8,*) works so I will just use that, thanks.
- juergen.furthmueller
- Newbie
- Posts: 10
- Joined: Fri Nov 08, 2019 9:46 am
Re: Write statement in main.F
Usually the proper way is to use IO%IU6 (stdout = OUTCAR) and/or IO%IU0 (stderr = screen).
However, in an MPI environment IO%IU6=-1 will be set for all nodes except the master node
in order to prevent multiple output by all nodes. Therefore, any write statement needs to
be preceeded by some "IF (IO%IU6>=0) ...". This is by the way also all true for IO%IU0.
If you have "WDES" (or some "COMM") available there is also an alternative way by defining
two local integer variables NODE_ME and IONODE set up the following way:
NODE_ME=0
IONODE=0
#ifdef MPI
NODE_ME= WDES%COMM%NODE_ME
IONODE = WDES%COMM%IONODE
#endif
There is a pre-defined macro "do_io" (in symbol.inc) set equal to "IF (NODE_ME==IONODE)"
which allows then to simply use "do_io WRITE(IO%IU6,format) whatever" ... . If you have
several WRITE statements they can be embedded into an "io_begin" .... "io_end" block (these
are other macros defined as "IF (NODE_ME==IONODE) THEN" and "ENDIF" ...). Anyway, you may
only write on the IO node (the only node where IO%IU6 and IO%IU0 are different from "-1" ...).
But this mechanism is only worth the effort if you have many WRITE statements, otherwise the
quick solution with "IF (IO%IU6>=0) ..." is more simple and more convenient (but it's a must).
So, if structure "IO" was properly passed and declared both should work (also for IO%IU0).
However, in an MPI environment IO%IU6=-1 will be set for all nodes except the master node
in order to prevent multiple output by all nodes. Therefore, any write statement needs to
be preceeded by some "IF (IO%IU6>=0) ...". This is by the way also all true for IO%IU0.
If you have "WDES" (or some "COMM") available there is also an alternative way by defining
two local integer variables NODE_ME and IONODE set up the following way:
NODE_ME=0
IONODE=0
#ifdef MPI
NODE_ME= WDES%COMM%NODE_ME
IONODE = WDES%COMM%IONODE
#endif
There is a pre-defined macro "do_io" (in symbol.inc) set equal to "IF (NODE_ME==IONODE)"
which allows then to simply use "do_io WRITE(IO%IU6,format) whatever" ... . If you have
several WRITE statements they can be embedded into an "io_begin" .... "io_end" block (these
are other macros defined as "IF (NODE_ME==IONODE) THEN" and "ENDIF" ...). Anyway, you may
only write on the IO node (the only node where IO%IU6 and IO%IU0 are different from "-1" ...).
But this mechanism is only worth the effort if you have many WRITE statements, otherwise the
quick solution with "IF (IO%IU6>=0) ..." is more simple and more convenient (but it's a must).
So, if structure "IO" was properly passed and declared both should work (also for IO%IU0).