#!/bin/csh -f
# +-======-+ 
#  Copyright (c) 2003-2018 United States Government as represented by 
#  the Admistrator of the National Aeronautics and Space Administration.  
#  All Rights Reserved.
#  
#  THIS OPEN  SOURCE  AGREEMENT  ("AGREEMENT") DEFINES  THE  RIGHTS  OF USE,
#  REPRODUCTION,  DISTRIBUTION,  MODIFICATION AND REDISTRIBUTION OF CERTAIN 
#  COMPUTER SOFTWARE ORIGINALLY RELEASED BY THE UNITED STATES GOVERNMENT AS 
#  REPRESENTED BY THE GOVERNMENT AGENCY LISTED BELOW ("GOVERNMENT AGENCY").  
#  THE UNITED STATES GOVERNMENT, AS REPRESENTED BY GOVERNMENT AGENCY, IS AN 
#  INTENDED  THIRD-PARTY  BENEFICIARY  OF  ALL  SUBSEQUENT DISTRIBUTIONS OR 
#  REDISTRIBUTIONS  OF THE  SUBJECT  SOFTWARE.  ANYONE WHO USES, REPRODUCES, 
#  DISTRIBUTES, MODIFIES  OR REDISTRIBUTES THE SUBJECT SOFTWARE, AS DEFINED 
#  HEREIN, OR ANY PART THEREOF,  IS,  BY THAT ACTION, ACCEPTING IN FULL THE 
#  RESPONSIBILITIES AND OBLIGATIONS CONTAINED IN THIS AGREEMENT.
#  
#  Government Agency: National Aeronautics and Space Administration
#  Government Agency Original Software Designation: GSC-15354-1
#  Government Agency Original Software Title:  GEOS-5 GCM Modeling Software
#  User Registration Requested.  Please Visit http://opensource.gsfc.nasa.gov
#  Government Agency Point of Contact for Original Software:  
#  			Dale Hithon, SRA Assistant, (301) 286-2691
#  
# +-======-+ 

setenv MYNAME RmShmKeys_sshmpi

                                    setenv FAILED 0
if( (! $?FVROOT ) & (! $?GEOSBIN) ) setenv FAILED 1

if ( $FAILED ) then
   env
   echo " ${MYNAME}: not all required env vars defined"
   exit 1
endif

if( $?FVROOT ) then
   set pathname = $FVROOT/bin
endif
if( $?GEOSBIN ) then
   set pathname = $GEOSBIN
endif

setenv SITE `$pathname/g5_modules site`

if( $?PBS_NODEFILE ) then
   sleep 10

   set nodes = `cat $PBS_NODEFILE | uniq`

   if ( $SITE == NCCS ) then

      echo "Found site ${SITE}: using sshmpi"
      foreach node ($nodes)
         echo sshmpi $node $pathname/rmshmkeyhere.sh
              sshmpi $node $pathname/rmshmkeyhere.sh &
      end

   else if ( $SITE == NAS ) then

      echo "Found site ${SITE}: using pdsh"
      pdsh -f 128 -aF $PBS_NODEFILE $pathname/rmshmkeyhere.sh

   else

      echo "SITE: $SITE not supported for SHMEM! Contact GEOS Support"
      exit 2

   endif

   wait
endif
