Index: palm/trunk/SCRIPTS/mrun
===================================================================
--- palm/trunk/SCRIPTS/mrun	(revision 204)
+++ palm/trunk/SCRIPTS/mrun	(revision 206)
@@ -154,4 +154,5 @@
      # 08/08/08 - Marcus - typo removed in lcxt4 branch
      # 17/09/08 - Siggi  - restart mechanism adjusted for lcsgi
+     # 02/10/09 - BjornM - argument "-Y" modified, adjustments for coupled runs
  
     # VARIABLENVEREINBARUNGEN + DEFAULTWERTE
@@ -171,4 +172,6 @@
  cond2="" 
  config_file=.mrun.config
+ coupled_dist=""
+ coupled_mode="mpi1"
  cpp_opts=""
  cpp_options=""
@@ -219,4 +222,6 @@
  node_usage=default
  numprocs=""
+ numprocs_atmos=0
+ numprocs_ocean=0
  OOPT=""
  openmp=false
@@ -262,5 +267,5 @@
 
  typeset -i  iec=0 iic=0 iin=0 ioc=0 iout=0 memory=0 stagein_anz=0 stageout_anz=0
- typeset -i  cputime i ii iii icycle inode ival jobges jobsek maxcycle minuten nodes pes sekunden tp1
+ typeset -i  cputime i ii iia iii iio icycle inode ival jobges jobsek maxcycle minuten nodes pes sekunden tp1
 
  typeset  -R30 calltime
@@ -381,5 +386,5 @@
     # SHELLSCRIPT-OPTIONEN EINLESEN UND KOMMANDO NEU ZUSAMMENSETZEN, FALLS ES
     # FUER FOLGEJOBS BENOETIGT WIRD
- while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:Op:P:q:r:R:s:St:T:u:U:vxX:Y option
+ while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:Op:P:q:r:R:s:St:T:u:U:vxX:Y: option
  do
    case  $option  in
@@ -420,5 +425,5 @@
        (x)   do_trace=true;set -x; mc="$mc -x";;
        (X)   numprocs=$OPTARG; mc="$mc -X$OPTARG";;
-       (Y)   run_coupled_model=true; mc="$mc -Y";;
+       (Y)   run_coupled_model=true; coupled_dist=$OPTARG; mc="$mc -Y'$OPTARG'";;
        (\?)  printf "\n  +++ unknown option $OPTARG \n"
              printf "\n  --> type \"$0 ?\" for available options \n"
@@ -437,5 +442,5 @@
  then
    (printf "\n  *** mrun can be called as follows:\n"
-    printf "\n      $mrun_script_name  -b -c.. -d.. -D.. -f.. -F -h.. -i.. -I -K.. -m.. -o.. -p.. -r.. -R -s.. -t.. -T.. -v -x -X..  <modus>\n"
+    printf "\n      $mrun_script_name  -b -c.. -d.. -D.. -f.. -F -h.. -i.. -I -K.. -m.. -o.. -p.. -r.. -R -s.. -t.. -T.. -v -x -X.. -Y.. <modus>\n"
     printf "\n      Description of available options:\n"
     printf "\n      Option  Description                              Default-Value"
@@ -475,5 +480,6 @@
     printf "\n        -x    tracing of mrun for debug purposes       ---"
     printf "\n        -X    # of processors (on parallel machines)   1"
-    printf "\n        -Y    run coupled model                        ---"
+    printf "\n        -Y    run coupled model, \"#1 #2\" with" 
+    printf "\n              #1 atmosphere and #2 ocean processors    \"#/2 #/2\" depending on -X"
     printf "\n "
     printf "\n      Possible values of positional parameter <modus>:"
@@ -509,5 +515,5 @@
  while read line
  do
-    if [[ "$line" != ""  ||  $(echo $line | cut -c1) != "#" ]]
+    if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
     then
        HOSTNAME=`echo $line | cut -d" " -s -f2`
@@ -530,5 +536,4 @@
     locat=localhost; exit
  fi
-
 
 
@@ -586,5 +591,5 @@
     do_remote=true
     case  $host  in
-        (ibm|ibmb|ibmh|ibms|ibmy|nech|neck|lcsgib|lcsgih|lctit|unics)  true;;
+        (ibm|ibmb|ibmh|ibms|ibmy|nech|neck|lcsgib|lcsgih|lctit|unics|lcxt4)  true;;
         (*)  printf "\n"
              printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
@@ -609,4 +614,60 @@
        locat=options; exit
     fi
+ fi
+
+
+      # KOPPLUNGSEIGENSCHAFTEN (-Y) AUSWERTEN UND coupled_mode BESTIMMEN
+ if [[ $run_coupled_model = true ]] 
+ then
+
+    if  [[ -n $coupled_dist ]]
+    then
+
+       numprocs_atmos=`echo $coupled_dist | cut -d" " -s -f1`
+       numprocs_ocean=`echo $coupled_dist | cut -d" " -s -f2`
+
+       if (( $numprocs_ocean + $numprocs_atmos != $numprocs ))
+       then
+
+          printf "\n  +++ number of processors does not fit to specification by \"-Y\"."
+          printf "\n      PEs (total)     : $numprocs"
+          printf "\n      PEs (atmosphere): $numprocs_atmos"
+          printf "\n      PEs (ocean)     : $numprocs_ocean"
+          locat=coupling; exit
+
+          # REARRANGING BECAUSE CURRENTLY ONLY 1:1 TOPOLOGIES ARE SUPPORTED
+          # THIS SHOULD BE REMOVED IN FUTURE
+       elif (( $numprocs_ocean != $numprocs_atmos ))
+       then
+
+          printf "\n  +++ currently only 1:1 topologies are supported"
+          printf "\n      PEs (total)     : $numprocs"
+          printf "\n      PEs (atmosphere): $numprocs_atmos"
+          printf "\n      PEs (ocean)     : $numprocs_ocean"
+          (( numprocs_atmos = $numprocs / 2 ))
+          (( numprocs_ocean = $numprocs / 2 ))
+          printf "\n  +++ rearranged topology to $numprocs_atmos:$numprocs_ocean"
+
+       fi
+
+    else
+
+       (( numprocs_ocean = $numprocs / 2 ))
+       (( numprocs_atmos = $numprocs / 2 ))
+
+    fi
+    coupled_dist=`echo "$numprocs_atmos $numprocs_ocean"`
+
+       # GET coupled_mode FROM THE CONFIG FILE
+    line=""
+    grep  "%cpp_options.*-D__mpi2.*$host" $config_file  >  tmp_mrun
+    while read line
+    do
+       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" &&  ( $(echo $line | cut -d" " -s -f4) = $cond1 || $(echo $line | cut -d" " -s -f4)  = $cond2 ) ]]
+       then
+          coupled_mode="mpi2"
+       fi
+    done < tmp_mrun
+
  fi
 
@@ -705,5 +766,5 @@
                    do_remote=true
                    case  $host  in
-                       (ibm|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics)  true;;
+                       (ibm|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics|lcxt4)  true;;
                        (*)  printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
                             printf "\n      is not available"
@@ -960,5 +1021,5 @@
     do_remote=true
     case  $host  in
-        (ibm|ibmb|ibmh|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics)  true;;
+        (ibm|ibmb|ibmh|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics|lcxt4)  true;;
         (*)  printf "\n"
              printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
@@ -2867,42 +2928,53 @@
                 fi
              else
-                ((  iii = ii / 2 ))
-                echo "atmosphere_to_ocean"  >  runfile_atmos
-                echo "ocean_to_atmosphere"  >  runfile_ocean
-
-                printf "\n      coupled run ($iii atmosphere, $iii ocean)"
+
+                    # currently there is no full MPI-2 support on ICE and XT4
+                (( iia = $numprocs_atmos / $threads_per_task ))
+                (( iio = $numprocs_ocean / $threads_per_task ))
+                printf "\n      coupled run ($iia atmosphere, $iio ocean)"
+                printf "\n      using $coupled_mode coupling"
                 printf "\n\n"
 
-                if [[ $host = lcsgih  ||  $host = lcsgib ]]
+                if [[ $coupled_mode = "mpi2" ]]
                 then
-
-                   mpiexec  -n $iii  a.out  $ROPTS  <  runfile_atmos &
-                   mpiexec  -n $iii  a.out  $ROPTS  <  runfile_ocean &
-#                   head  -n $iii  $PBS_NODEFILE  >  nodefile_atmos
-#                   echo "--- nodefile_atmos:"
-#                   cat nodefile_atmos
-#                   tail  -n $iii  $PBS_NODEFILE  >  nodefile_ocean
-#                   echo "--- nodefile_ocean:"
-#                   cat nodefile_ocean
-#                   export  PBS_NODEFILE=${PWD}/nodefile_atmos
-#                   mpiexec_mpt -np $iii   ./a.out  $ROPTS  <  runfile_atmos &
-#                   export  PBS_NODEFILE=${PWD}/nodefile_ocean
-#                   mpiexec_mpt -np $iii   ./a.out  $ROPTS  <  runfile_ocean &
-
-
-                elif [[ $host = lcxt4 ]]
-                then
-                   aprun  -n $iii  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS  &
-                   aprun  -n $iii  -N $tasks_per_node  a.out < runfile_ocean  $ROPTS  &
+                   echo "atmosphere_to_ocean $iia $iio"  >  runfile_atmos
+                   echo "ocean_to_atmosphere $iia $iio"  >  runfile_ocean
+                   if [[ $host = lcsgih  ||  $host = lcsgib ]]
+                   then
+
+                      mpiexec_mpt -np $iia  ./palm  $ROPTS < runfile_atmos &
+                      mpiexec_mpt -np $iio  ./palm  $ROPTS < runfile_ocean &
+
+                   elif [[ $host = lcxt4 ]]
+                   then
+
+                      aprun  -n $iia  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS  &
+                      aprun  -n $iio  -N $tasks_per_node  a.out < runfile_ocean  $ROPTS  &
+
+                   else
+                          # WORKAROUND BECAUSE mpiexec WITH -env option IS NOT AVAILABLE ON SOME SYSTEMS
+                       mpiexec  -machinefile hostfile  -n $iia  a.out  $ROPTS  <  runfile_atmos &
+                       mpiexec  -machinefile hostfile  -n $iio  a.out  $ROPTS  <  runfile_ocean &
+#                       mpiexec  -machinefile hostfile  -n $iia  -env coupling_mode atmosphere_to_ocean  a.out  $ROPTS  &
+#                       mpiexec  -machinefile hostfile  -n $iio  -env coupling_mode ocean_to_atmosphere  a.out  $ROPTS  &
+                   fi
+                   wait
+
                 else
 
-                      # WORKAROUND BECAUSE mpiexec WITH -env option IS NOT AVAILABLE ON SOME SYSTEMS
-                   mpiexec  -machinefile hostfile  -n $iii  a.out  $ROPTS  <  runfile_atmos &
-                   mpiexec  -machinefile hostfile  -n $iii  a.out  $ROPTS  <  runfile_ocean &
-#                   mpiexec  -machinefile hostfile  -n $iii  -env coupling_mode atmosphere_to_ocean  a.out  $ROPTS  &
-#                   mpiexec  -machinefile hostfile  -n $iii  -env coupling_mode ocean_to_atmosphere  a.out  $ROPTS  &
+                   echo "coupled_run $iia $iio"  >  runfile_atmos
+                   if [[ $host = lcsgih  ||  $host = lcsgib ]]
+                   then
+
+                      mpiexec_mpt  -np $ii  a.out  $ROPTS  <  runfile_atmos
+
+                   elif [[ $host = lcxt4 ]]
+                   then
+
+                      aprun  -n $ii  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS
+
+                   fi
+                   wait
                 fi
-                wait
-             fi
 
 #             if [[ $scirocco = true ]]
@@ -2912,5 +2984,5 @@
 #                mpirun  -machinefile hostfile  -np $ii  a.out  $ROPTS
 #             fi
-
+             fi
           elif [[ $host = decalpha ]]
           then
@@ -3778,5 +3850,5 @@
     [[ $delete_temporary_catalog = false ]]  &&  mrun_com=${mrun_com}" -B"
     [[ $node_usage != default  &&  "$(echo $node_usage | cut -c1-3)" != "sla"  &&  $node_usage != novice ]]  &&  mrun_com=${mrun_com}" -n $node_usage"
-    [[ $run_coupled_model = true ]]  &&  mrun_com=${mrun_com}" -Y"
+    [[ $run_coupled_model = true ]]  &&  mrun_com=${mrun_com}" -Y \"$coupled_dist\""
     if [[ $do_remote = true ]]
     then
