Write statement in main.F

Question on input files/tags, interpreting output, etc.

Please check whether the answer to your question is given in the VASP online manual or has been discussed in this forum previously!

Moderators: Global Moderator, Moderator

Post Reply
Message
Author
mike_foster
Newbie
Newbie
Posts: 12
Joined: Fri Jan 27, 2023 5:26 pm

Write statement in main.F

#1 Post by mike_foster » Fri Feb 03, 2023 2:48 pm

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.

fabien_tran1
Global Moderator
Global Moderator
Posts: 316
Joined: Mon Sep 13, 2021 11:02 am

Re: Write statement in main.F

#2 Post by fabien_tran1 » Fri Feb 03, 2023 3:41 pm

Is IO%IU6 properly defined? Would it work with 8:
WRITE(8,*) "test"

mike_foster
Newbie
Newbie
Posts: 12
Joined: Fri Jan 27, 2023 5:26 pm

Re: Write statement in main.F

#3 Post by mike_foster » Fri Feb 03, 2023 4:36 pm

I passed IO in but I guess something is not defined correctly. WRITE(8,*) works so I will just use that, thanks.

User avatar
juergen.furthmueller
Newbie
Newbie
Posts: 10
Joined: Fri Nov 08, 2019 9:46 am

Re: Write statement in main.F

#4 Post by juergen.furthmueller » Sat Feb 18, 2023 5:54 pm

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).

Post Reply