diff --git a/Makefile b/Makefile index 763a737a40bc..7e0d4f4c0c74 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,10 @@ sim: make -C src/qasm-simulator-cpp/src clean make -C src/qasm-simulator-cpp/src +# Build dependencies for the simulator target +depend: + make -C src/qasm-simulator-cpp depend + coverage_erase: coverage erase diff --git a/src/qasm-simulator-cpp/Makefile b/src/qasm-simulator-cpp/Makefile index 5adcb207bbd6..53c9ba61c31c 100644 --- a/src/qasm-simulator-cpp/Makefile +++ b/src/qasm-simulator-cpp/Makefile @@ -5,5 +5,8 @@ all: sim sim: make -C src +depend: + ./build_dependencies.sh + clean: - make -C src clean \ No newline at end of file + make -C src clean diff --git a/src/qasm-simulator-cpp/build_dependencies.sh b/src/qasm-simulator-cpp/build_dependencies.sh new file mode 100755 index 000000000000..e7a29b0b11d8 --- /dev/null +++ b/src/qasm-simulator-cpp/build_dependencies.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# ------------------------------------------------------------------------------ +# build_dependencies.sh +# +# Dependency installer for qiskit-sdk-py/src/qasm-simulator-cpp +# Running the script: +# 1. Run the script directly +# ./build_dependencies.sh +# 2. Alternatively, build the make depend target (See the Makefile) +# make depend +# +# .. note:: Tested on Ubuntu 16.04 only. +# ------------------------------------------------------------------------------ +set -ex +os_type=`uname -s` + +# Check who is the current user. +USER=$(whoami) + +if [ ${USER} == "root" ] +then + SUDOCMD="" +else + SUDOCMD="sudo" +fi + +# Check the OS Type +echo "OS is $os_type" + +if [[ "$os_type" == "Darwin" ]]; then + ${SUDOCMD} xcode-select --install +elif [[ "$os_type" == "Linux" ]]; then + echo "Installing dependencies on Linux" + linux_distro=`cat /etc/*release | grep "ID_LIKE=" | cut -c9- | tr -d '"'` + if [[ "$linux_distro" == "debian" ]]; then + ${SUDOCMD} apt-get update + ${SUDOCMD} apt-get -y install build-essential libblas-dev liblapack-dev + elif [[ "$linux_distro" == "fedora" ]]; then + ${SUDOCMD} yum update + ${SUDOCMD} yum -y install devtoolset-6 blas blas-devel lapack lapack-devel + ${SUDOCMD} scl enable devtoolset-6 bash + else + echo "Unsupported linux distro: $linux_distro" + fi +fi diff --git a/src/qasm-simulator-cpp/src/Makefile b/src/qasm-simulator-cpp/src/Makefile index 8938f28a7af1..9bb7751dc6ca 100644 --- a/src/qasm-simulator-cpp/src/Makefile +++ b/src/qasm-simulator-cpp/src/Makefile @@ -6,13 +6,18 @@ OUTPUT_DIR = ../../../out/src/qasm-simulator-cpp CC = g++ # Use Homebrew GNU g++ for enabling OpenMP on macOS - OS:=$(shell uname) GCC7:=$(shell g++-7 --version | grep ^'command not found') ifeq ($(OS)$(GCC7),Darwin) CC = g++-7 endif +# -march not supported on ppc64le (Power). Use -mcpu instead +ARCH:=$(shell uname -m) +ifeq ($(ARCH),ppc64le) + OPT = -O3 -mcpu=native -ffast-math +endif + # Check if compiler is Apple LLVM and doesn't support OpenMP APPLELLVM = $(shell ${CC} --version | grep ^Apple) ifeq ($(APPLELLVM),) @@ -50,6 +55,9 @@ sim: main.o sim_debug: main.o $(CC) -g $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qasm_simulator_cpp_debug ${OUTPUT_DIR}/main.o $(LIBS) +depend: + ../build_dependencies.sh + clean: rm -rf ${OUTPUT_DIR}