| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | #calcmem |
| 3 | |
| 4 | #function usage(){ |
| 5 | # echo "CalcMem v1.01" |
| 6 | # echo "Written by Brian Bushnell, Doug Jacobsen, Alex Copeland" |
| 7 | # echo "Calculates available memory in megabytes" |
| 8 | # echo "Last modified April 25, 2014" |
| 9 | #} |
| 10 | |
| 11 | function parseXmxscip-shell shell bbmap 39.20+dfsg-3 parseXmx(). () { |
| 12 | local setxmx=0 |
| 13 | local setxms=0 |
| 14 | |
| 15 | for arg in "$@" |
| 16 | do |
| 17 | if [[ "$arg" == -Xmx* ]]; then |
| 18 | z="$arg" |
| 19 | setxmx=1 |
| 20 | elif [[ "$arg" == Xmx* ]]; then |
| 21 | z="-$arg" |
| 22 | setxmx=1 |
| 23 | elif [[ "$arg" == -Xms* ]]; then |
| 24 | z2="$arg" |
| 25 | setxms=1 |
| 26 | elif [[ "$arg" == Xms* ]]; then |
| 27 | z2="-$arg" |
| 28 | setxms=1 |
| 29 | elif [[ "$arg" == -da ]] || [[ "$arg" == -ea ]]; then |
| 30 | EA="$arg" |
| 31 | fi |
| 32 | done |
| 33 | |
| 34 | if [[ $setxmx == 1 ]] && [[ $setxms == 0 ]]; then |
| 35 | local substring=`echoscip-shell system . . echo. $z| cutscip-shell system . . cut. -d'x' -f 2` |
| 36 | z2="-Xms$substring" |
| 37 | setxms=1 |
| 38 | elif [[ $setxmx == 0 ]] && [[ $setxms == 1 ]]; then |
| 39 | local substring=`echoscip-shell system . . echo. $z2| cutscip-shell system . . cut. -d's' -f 2` |
| 40 | z="-Xmx$substring" |
| 41 | setxmx=1 |
| 42 | fi |
| 43 | |
| 44 | set=$setxmx |
| 45 | } |
| 46 | |
| 47 | |
| 48 | RAM=0; |
| 49 | |
| 50 | function freeRamscip-shell shell bbmap 39.20+dfsg-3 freeRam().(){ |
| 51 | #Memory is in kilobytes. |
| 52 | local defaultMem=3200000 |
| 53 | if [scip-shell system . . `[`. $# -gt 0 ]; then |
| 54 | defaultMem=$1; |
| 55 | case $defaultMem in |
| 56 | *g) |
| 57 | defaultMem=`echoscip-shell system . . echo. $defaultMem| cutscip-shell system . . cut. -d'g' -f 1` |
| 58 | defaultMem=$(( $defaultMem * $(( 1024 * 1024 )) )) |
| 59 | ;; |
| 60 | *m) |
| 61 | defaultMem=`echoscip-shell system . . echo. $defaultMem| cutscip-shell system . . cut. -d'm' -f 1` |
| 62 | defaultMem=$(( $defaultMem * 1024 )) |
| 63 | ;; |
| 64 | *k) |
| 65 | defaultMem=`echoscip-shell system . . echo. $defaultMem| cutscip-shell system . . cut. -d'k' -f 1` |
| 66 | ;; |
| 67 | esac |
| 68 | fi |
| 69 | |
| 70 | local mult=84 |
| 71 | if [scip-shell system . . `[`. $# -gt 1 ]; then |
| 72 | mult=$2; |
| 73 | fi |
| 74 | |
| 75 | #echo "mult = $mult" |
| 76 | #echo "default = $defaultMem" |
| 77 | |
| 78 | local ulimit=$(ulimit -v) |
| 79 | local x=$ulimit |
| 80 | |
| 81 | if [scip-shell system . . `[`. -e /proc/meminfoscip-shell filesystem . . `/proc/meminfo`. ]; then |
| 82 | local vfree=$(catscip-shell system . . cat. /proc/meminfoscip-shell filesystem . . `/proc/meminfo`. | awkscip-shell system . . awk. -F: 'BEGIN{total=-1;used=-1} /^CommitLimit:/ { total=$2 }; /^Committed_AS:/ { used=$2 } END{ print (total-used) }') |
| 83 | local pfree=$(catscip-shell system . . cat. /proc/meminfoscip-shell filesystem . . `/proc/meminfo`. | awkscip-shell system . . awk. -F: 'BEGIN{free=-1;cached=-1;buffers=-1} /^MemFree:/ { free=$2 }; /^Cached:/ { cached=$2}; /^Buffers:/ { buffers=$2} END{ print (free+cached+buffers) }') |
| 84 | |
| 85 | echoscip-shell system . . echo. "vfree = $vfree" |
| 86 | echoscip-shell system . . echo. "pfree = $pfree" |
| 87 | echoscip-shell system . . echo. "ulimit = $ulimit" |
| 88 | |
| 89 | local x2=0; |
| 90 | |
| 91 | if [scip-shell system . . `[`. $vfree -gt 0 ] && [scip-shell system . . `[`. $pfree -gt 0 ]; then |
| 92 | if [scip-shell system . . `[`. $vfree -gt $pfree ]; then x2=$pfree; |
| 93 | else x2=$vfree; fi |
| 94 | elif [scip-shell system . . `[`. $vfree -gt 0 ]; then x2=$vfree; |
| 95 | elif [scip-shell system . . `[`. $pfree -gt 0 ]; then x2=$pfree; |
| 96 | fi |
| 97 | |
| 98 | echoscip-shell system . . echo. $x |
| 99 | echoscip-shell system . . echo. $x2 |
| 100 | echoscip-shell system . . echo. $vfree |
| 101 | echoscip-shell system . . echo. $pfree |
| 102 | |
| 103 | if [scip-shell system . . `[`. "$x" = "unlimited" ] || (($x > $x2)); then x=$x2; fi |
| 104 | |
| 105 | fi |
| 106 | |
| 107 | #echo "x=$x" |
| 108 | local HOSTNAME=`hostnamescip-shell system . . hostname.` |
| 109 | if [scip-shell system . . `[`. $x -lt 1 ] || [[ $HOSTNAME == genepool* ]]; then |
| 110 | #echo "hello 2" |
| 111 | #echo $x |
| 112 | #echo "ram is unlimited" |
| 113 | RAM=$((defaultMem/1024)) |
| 114 | echoscip-shell system . . echo. "Max memory cannot be determined. Attempting to use $RAM MB." 1>&2 |
| 115 | echoscip-shell system . . echo. "If this fails, please set ulimit or run this program qsubbed or from a qlogin session on Genepool." 1>&2 |
| 116 | else |
| 117 | #echo "hello 1" |
| 118 | #echo $x |
| 119 | |
| 120 | #if [ $x -ge 1000000000 ]; then |
| 121 | # echo "ram is 1000g+" |
| 122 | #elif [ $x -ge 500000000 ]; then |
| 123 | # echo "ram is 500g+" |
| 124 | #elif [ $x -ge 250000000 ]; then |
| 125 | # echo "ram is 250g+" |
| 126 | #elif [ $x -ge 144000000 ]; then |
| 127 | # echo "ram is 144g+" |
| 128 | #elif [ $x -ge 120000000 ]; then |
| 129 | # echo "ram is 120g+" |
| 130 | #elif [ $x -ge 40000000 ]; then |
| 131 | # echo "ram is 40g+" |
| 132 | #else |
| 133 | # echo "ram is under 40g" |
| 134 | #fi |
| 135 | #echo $x |
| 136 | RAM=$(( ((x-500000)*mult/100)/1024 )) |
| 137 | #echo $RAM |
| 138 | fi |
| 139 | |
| 140 | echoscip-shell system . . echo. $set |
| 141 | echoscip-shell system . . echo. $z |
| 142 | echoscip-shell system . . echo. $z2 |
| 143 | |
| 144 | #local z="-Xmx${RAM}m" |
| 145 | return 0 |
| 146 | } |
| 147 | |
| 148 | parseXmxscip-shell shell bbmap 39.20+dfsg-3 parseXmx(). "$@" |
| 149 | freeRamscip-shell shell bbmap 39.20+dfsg-3 freeRam(). "$@" |