#!/usr/bin/env sh

#    Frees any any shared memory allocated by PETSc with PetscShmgetAllocateArray()
#
if [ "X$1" == "X-h" ] || [ "X$1" == "X--help" ]; then
  echo "Usage: petscfreesharedmeory"
  exit
fi

if [ `uname` == "Linux" ]; then
  ipcrm --all
else
  for i in $(ipcs -m  | grep -E -v "(KEY|Shared|IPC|0x00000000)" | tr -s ' ' | cut -d" " -f3); do ipcrm -M $i; done
fi

