#!/bin/bash
noderank=$1
compile_path=$2
is_share_memory=$3

executable_o=${compile_path}/GPU_MemoryBw.o
executable=${compile_path}/GPU_MemoryBw
compile() {
    nvcc -c -o $executable_o bandwidth.cu -I/usr/local/cuda/include -I/usr/local/nccl/include -I/usr/local/mpi/include
    mpic++ -o $executable $executable_o -L/usr/local/cuda/lib64 -L/usr/local/nccl/lib -L/usr/local/mpi/lib -lcudart -lnccl -lcuda -lmpi 
}
if [ "$is_share_memory" = 1 ] && [ "$noderank" -eq 0 ]; then
  compile
elif [ "$is_share_memory" = 0 ]; then
  compile
fi
sleep 10
mpirun --allow-run-as-root -np 8 -x NCCL_DEBUG=WARN $executable