#!/bin/sh
##******************************************************************************
##  Copyright(C) 2001-2014 Intel Corporation. All Rights Reserved.
##
##  The source code, information  and  material ("Material") contained herein is
##  owned  by Intel Corporation or its suppliers or licensors, and title to such
##  Material remains  with Intel Corporation  or its suppliers or licensors. The
##  Material  contains proprietary information  of  Intel or  its  suppliers and
##  licensors. The  Material is protected by worldwide copyright laws and treaty
##  provisions. No  part  of  the  Material  may  be  used,  copied, reproduced,
##  modified, published, uploaded, posted, transmitted, distributed or disclosed
##  in any way  without Intel's  prior  express written  permission. No  license
##  under  any patent, copyright  or  other intellectual property rights  in the
##  Material  is  granted  to  or  conferred  upon  you,  either  expressly,  by
##  implication, inducement,  estoppel or  otherwise.  Any  license  under  such
##  intellectual  property  rights must  be express  and  approved  by  Intel in
##  writing.
##
##  *Third Party trademarks are the property of their respective owners.
##
##  Unless otherwise  agreed  by Intel  in writing, you may not remove  or alter
##  this  notice or  any other notice embedded  in Materials by Intel or Intel's
##  suppliers or licensors in any way.
##
##******************************************************************************

echo "This is a SAMPLE run script for SMP LINPACK. Change it to reflect"
echo "the correct number of CPUs/threads, problem input files, etc.."

export MKL_MIC_ENABLE=1

export MIC_LD_LIBRARY_PATH=../../lib/mic:../../../compiler/lib/mic:/opt/intel/mic/coi/device-linux-release/lib:$MIC_LD_LIBRARY_PATH
export LD_LIBRARY_PATH=../../../compiler/lib/intel64:/opt/intel/mic/coi/host-linux-release/lib:$LD_LIBRARY_PATH

# Check for presence of libraries required for AO
error=""
for f in libcoi_host.so.0 libiomp5.so libmkl_ao_worker.so; do
        found=""
        for d in $(echo $MIC_LD_LIBRARY_PATH $LD_LIBRARY_PATH| sed 's/:/ /g'); do
                test -f "$d/$f" && found=1
        done
        if test -z "$found"; then
                error=1
                echo " ** Error: required library $f not found in MIC_LD_LIBRARY_PATH or LD_LIBRARY_PATH"
        fi
done
test -n "$error" && echo "AO required libs not present. Forcing exit..." && exit -1

#    Setting up affinity for better threading performance
export KMP_AFFINITY=nowarnings,compact,1,0,granularity=fine
export MIC_KMP_AFFINITY=compact,granularity=fine

# Limit the number of CPU threads so that Intel(R) MIC coprocessor will get most of work
#export OMP_NUM_THREADS=16

# Force LINPACK to stop if MIC can't be used
#export MKL_MIC_DISABLE_HOST_FALLBACK=1

# Number of cards for calculation
export OFFLOAD_DEVICES=0,1

# Amount of pre-allocated memory (as much as possible by default)
export MKL_MIC_MAX_MEMORY=16G

date
date > lin_xeon64_ao.txt
./xlinpack_xeon64 lininput_xeon64_ao | tee -a lin_xeon64_ao.txt
date >> lin_xeon64_ao.txt
echo -n "Done: "
