#!/bin/csh

# @ PMI_RANK = 7
# @ PMI_SIZE = 8

if ( $PMI_SIZE < 2 ) then
  echo "at least 2 ranks required"
  exit -1
endif

# set NAMDBIN = /Projects/namd2/Programmers/jim/swift/namd2/Linux-x86_64-g++.multicore/namd2
set NAMDBIN = "namd2 -version nightly"

@ totalprocs = `grep -c ^processor /proc/cpuinfo`

@ cores = ($totalprocs - 1) / ($PMI_SIZE - 1)

if ( $cores < 1 || $PMI_RANK == $PMI_SIZE - 1 ) @ cores = 1

if ( $PMI_RANK == $PMI_SIZE - 1 ) then
  $NAMDBIN +p$cores $* < /dev/null
else
  $NAMDBIN +p$cores $* >! /var/tmp/stdout.$PMI_RANK.log < /dev/null
endif

