Page 1 of 1

Write statement in main.F

Posted: Fri Feb 03, 2023 2:48 pm
by mike_foster
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.

Re: Write statement in main.F

Posted: Fri Feb 03, 2023 3:41 pm
by fabien_tran1
Is IO%IU6 properly defined? Would it work with 8:
WRITE(8,*) "test"

Re: Write statement in main.F

Posted: Fri Feb 03, 2023 4:36 pm
by mike_foster
I passed IO in but I guess something is not defined correctly. WRITE(8,*) works so I will just use that, thanks.

Re: Write statement in main.F

Posted: Sat Feb 18, 2023 5:54 pm
by juergen.furthmueller
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).