#!/bin/bash

source ./functions

##
## entry point for script
##

NONCONTIG=${CLUSTER_DIR}/noncontig

(cd ${EXTRA_TESTS}/noncontig-test/noncontig && \
${CLUSTER_DIR}/mpich2/bin/mpicc noncontig.c parse_cmdline.c -o ${NONCONTIG} )

if [ $? -ne 0 ] ; then
	exit 1
fi


# like the other mpiio tests we can only do multi processor tests if there's a
# pav config file we can use
# If we have to we can fall back to single processor, and still do something
# reasonable. 

if [ -f $PAV_CONFIG ] ; then 
	# write out a pbs script
	pbs_script=${CLUSTER_DIR}/noncontig.sh
	make_pbs_script ${NONCONTIG} -fname pvfs2:\${MOUNTPOINT}/ncfile1 \
		-v -veclen $((1024*2)) -elmtcount 1  \
		-veccount 1 -timing -all -loops 1 > $pbs_script

	# submit it
	job_id=$(qsub -N noncontig $pbs_script | cut -d . -f1)

	if [ $? -ne 0 ] ; then
		exit 1
	fi	

	if [ -z "$job_id" ] ; then
		exit 1
	fi	

	# wait patently for it to complete
	block_until_done $job_id

	# need to get results into per-test log files
	cat noncontig.o$job_id

	egrep -q '(Assertion*failed|error:|Error|killed by signal)' noncontig.o$job_id
	if [ $? -eq 0 ] ; then 
		exit 1
	fi

	exit 0
fi
