TABLE OF CONTENTS


54-remote

DESCRIPTION

This example shows how to run script snippets on remote hosts using ::pwtk::remote.

BEWARE

::pwtk::remote requires that a user is able to ssh to remote host without a password.

As an emulation of the remote host, localhost is used by this example. To run this example, a user should be able to "ssh localhost" without a password.

FURTHER DESCRIPTION

This example is analogous to the 51-bg example (file: bg.pwtk), with the difference that that ::pwtk::remote is used instead of ::pwtk::bg.

EXAMPLE SOURCE FILE

remote.pwtk

SOURCE

# jobs submitted with ::pwtk::remote are child processes born in an empty state;
# ::pwtk::propagate is used to inform PWTK what to propagate to the child processes

propagate {
    # we will run 4 concurrent remote jobs; the number of processors
    # used for each job depends on the number of available cores;
    # edit according to your preference
    prefix mpirun -np 2

    # load the pw.x input data with ::pwtk::pwi::load_fromPWI    

    # (N.B.: if the remote host uses a different file system as the
    #        localhost, the relax.OAl111-1x1-2L.in should exist on the
    #        remote host hence scp or rsync it there)
    
    load_fromPWI relax.OAl111-1x1-2L.in

    # Make some simple structure modification:
    # 1. fix the O adatom and the top Al layer laterally with ::pwtk::pwi::fixAtoms1st    
    # 2. fix the bottom layer of Al-slab with ::pwtk::pwi::fixAtomsLast
    
    fixAtoms1st  2 "0 0 1"
    fixAtomsLast 2
}

# set user@remotehost: let's use localhost which works for (almost) everybody;
#    consider replacing localhost with a remote host you can log
#    without a password and has PWTK and QE installed)

set user_at_remotehost localhost

# scan the O adatom over the lateral x,y positions

set seq [seq 0.0 0.2 1.0]; # this sequence will be used multiple times

foreach dx $seq {
    foreach dy $seq {
        # a counter to count # of concurrent remote jobs
        incr iremote

        # ::pwtk::remote runs a script snippet on the remote host
        # (consider replacing localhost with a remote host you can log
        #  to without a password and has PWTK and QE installed)
        
        remote $user_at_remotehost {            
            # each job should have its own prefix or else jobs will
            # write to the same temporary files
            
            CONTROL " prefix = 'O-$dx,$dy.Al111' "

            # shift the O adatom to a new position with ::pwtk::pwi::displaceAtoms
            displaceAtoms "$dx $dy 0.0" 1

            # run pw.x calculation with ::pwtk::runPW
            runPW relax-z.O-$dx,$dy.Al111-1x1-2L
        }

        # allow only 4 parallel remote jobs
        if { $iremote == 4 } {            
            # waits for remote jobs to finish with ::pwtk::remote_wait 
            remote_wait         
            # reset the concurrent job counter
            set iremote 0
        }     
    }
}

remote_wait; # not really needed because 36 is divisible by 4, hence
             # all remote jobs should be finished at this point


# download the output files from the remote host and extract all total energies

print "rsyncing output files ..."

foreach dx $seq {
    foreach dy $seq {
        print "   relax-z.O-$dx,$dy.Al111-1x1-2L.out ..."
        # fetch with ::pwtk::rsync the output file from the remotehost 
        rsync $user_at_remotehost:[pwd]/relax-z.O-$dx,$dy.Al111-1x1-2L.out .
        
        # get the total energy with pwo_totene, a shortcut to ::pwtk::pwo::totene
        set E($dx,$dy) [pwo_totene relax-z.O-$dx,$dy.Al111-1x1-2L.out]

        # get the minimum total energy        
        ifset Emin $E($dx,$dy); # ::pwtk::ifset assigns the variable only if it is not yet assigned
        if { $E($dx,$dy) < $Emin } {
            set Emin $E($dx,$dy)
        }
    }
}

# calculate ΔE(x,y) = E(x,y) - Emin, and write a datafile

foreach dx $seq {
    foreach dy $seq {
        # calculate ΔE(x,y) in eV units
        set dE [expr $ry2ev*($E($dx,$dy) - $Emin)]

        # lateral Cartesian position of the O atom in alat units
        set x [expr $dx - 0.5*$dy]
        set y [expr sqrt(3)/2*$dy]

        # write data to a file with ::pwtk::write
        write ene.OAl.dat "$x $y $dE"
    }
    write ene.OAl.dat ""
}


# plot the heatmap with ::pwtk::heatmap
heatmap -pal dark -i 10,10 -contour -cc black \
    -xr -0.5:1 -yr 0:sqrt(3)/2 \
    -xl "Δx (alat)" -yl "Δy (alat)" \
    -xf %.1f -yf %.1f -cbf %.1f ene.OAl.dat


# plot the surface plot with ::pwtk::splot
splot -pal dark -i 10,10 -contour -cc black \
    -xr -0.5:1 -yr 0:sqrt(3)/2 \
    -xl "Δx (alat)" -yl "Δy (alat)" -zl "ΔE (eV)" \
    -xf %.1f -yf %.1f -zf %.1f -cbf %.1f \
    -x {set zlabel rotate by 90} ene.OAl.dat