Commit 3038054c by Balaji V. Iyer Committed by Balaji V. Iyer

Added Cilk runtime library (libcilkrts) into GCC.

From-SVN: r204173
parent 939b37da
2013-10-29 Balaji V. Iyer <balaji.v.iyer@intel.com>
* Makefile.def: Add libcilkrts to target_modules. Make libcilkrts
depend on libstdc++ and libgcc.
* configure: Regenerate.
* configure.ac: Added libcilkrts to target binaries. Also, restrict
libcilkrts for POSIX and i*86, and x86_64 architectures.
* Makefile.in: Added libcilkrts related fields to support building it.
2013-10-26 Jeff Law <law@redhat.com> 2013-10-26 Jeff Law <law@redhat.com>
* Makefile.def (target_modules): Remove libmudflap * Makefile.def (target_modules): Remove libmudflap
......
...@@ -125,6 +125,8 @@ target_modules = { module= libvtv; ...@@ -125,6 +125,8 @@ target_modules = { module= libvtv;
bootstrap=true; bootstrap=true;
lib_path=.libs; lib_path=.libs;
raw_cxx=true; }; raw_cxx=true; };
target_modules = { module= libcilkrts;
lib_path=.libs; };
target_modules = { module= libssp; lib_path=.libs; }; target_modules = { module= libssp; lib_path=.libs; };
target_modules = { module= newlib; }; target_modules = { module= newlib; };
target_modules = { module= libgcc; bootstrap=true; no_check=true; }; target_modules = { module= libgcc; bootstrap=true; no_check=true; };
...@@ -491,6 +493,7 @@ dependencies = { module=all-m4; on=all-build-texinfo; }; ...@@ -491,6 +493,7 @@ dependencies = { module=all-m4; on=all-build-texinfo; };
// on libgcc and newlib/libgloss. // on libgcc and newlib/libgloss.
lang_env_dependencies = { module=libjava; cxx=true; }; lang_env_dependencies = { module=libjava; cxx=true; };
lang_env_dependencies = { module=libitm; cxx=true; }; lang_env_dependencies = { module=libitm; cxx=true; };
lang_env_dependencies = { module=libcilkrts; cxx=true; };
lang_env_dependencies = { module=newlib; no_c=true; }; lang_env_dependencies = { module=newlib; no_c=true; };
lang_env_dependencies = { module=libgloss; no_c=true; }; lang_env_dependencies = { module=libgloss; no_c=true; };
lang_env_dependencies = { module=libgcc; no_gcc=true; no_c=true; }; lang_env_dependencies = { module=libgcc; no_gcc=true; no_c=true; };
...@@ -531,6 +534,8 @@ dependencies = { module=install-target-libsanitizer; on=install-target-libstdc++ ...@@ -531,6 +534,8 @@ dependencies = { module=install-target-libsanitizer; on=install-target-libstdc++
dependencies = { module=install-target-libsanitizer; on=install-target-libgcc; }; dependencies = { module=install-target-libsanitizer; on=install-target-libgcc; };
dependencies = { module=install-target-libvtv; on=install-target-libstdc++-v3; }; dependencies = { module=install-target-libvtv; on=install-target-libstdc++-v3; };
dependencies = { module=install-target-libvtv; on=install-target-libgcc; }; dependencies = { module=install-target-libvtv; on=install-target-libgcc; };
dependencies = { module=install-target-libcilkrts; on=install-target-libstdc++-v3; };
dependencies = { module=install-target-libcilkrts; on=install-target-libgcc; };
dependencies = { module=install-target-libjava; on=install-target-libgcc; }; dependencies = { module=install-target-libjava; on=install-target-libgcc; };
dependencies = { module=install-target-libitm; on=install-target-libgcc; }; dependencies = { module=install-target-libitm; on=install-target-libgcc; };
dependencies = { module=install-target-libobjc; on=install-target-libgcc; }; dependencies = { module=install-target-libobjc; on=install-target-libgcc; };
......
...@@ -2772,6 +2772,7 @@ target_libraries="target-libgcc \ ...@@ -2772,6 +2772,7 @@ target_libraries="target-libgcc \
target-libgloss \ target-libgloss \
target-newlib \ target-newlib \
target-libgomp \ target-libgomp \
target-libcilkrts \
target-libatomic \ target-libatomic \
target-libitm \ target-libitm \
target-libstdc++-v3 \ target-libstdc++-v3 \
...@@ -3164,6 +3165,25 @@ $as_echo "yes" >&6; } ...@@ -3164,6 +3165,25 @@ $as_echo "yes" >&6; }
fi fi
fi fi
# Disable libcilkrts on unsupported systems.
if test -d ${srcdir}/libcilkrts; then
if test x$enable_libcilkrts = x; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libcilkrts support" >&5
$as_echo_n "checking for libcilkrts support... " >&6; }
if (srcdir=${srcdir}/libcilkrts; \
. ${srcdir}/configure.tgt; \
test -n "$UNSUPPORTED")
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
noconfigdirs="$noconfigdirs target-libcilkrts"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
fi
fi
fi
# Disable libitm on unsupported systems. # Disable libitm on unsupported systems.
if test -d ${srcdir}/libitm; then if test -d ${srcdir}/libitm; then
if test x$enable_libitm = x; then if test x$enable_libitm = x; then
......
...@@ -156,6 +156,7 @@ target_libraries="target-libgcc \ ...@@ -156,6 +156,7 @@ target_libraries="target-libgcc \
target-libgloss \ target-libgloss \
target-newlib \ target-newlib \
target-libgomp \ target-libgomp \
target-libcilkrts \
target-libatomic \ target-libatomic \
target-libitm \ target-libitm \
target-libstdc++-v3 \ target-libstdc++-v3 \
...@@ -506,6 +507,22 @@ if test -d ${srcdir}/libatomic; then ...@@ -506,6 +507,22 @@ if test -d ${srcdir}/libatomic; then
fi fi
fi fi
# Disable libcilkrts on unsupported systems.
if test -d ${srcdir}/libcilkrts; then
if test x$enable_libcilkrts = x; then
AC_MSG_CHECKING([for libcilkrts support])
if (srcdir=${srcdir}/libcilkrts; \
. ${srcdir}/configure.tgt; \
test -n "$UNSUPPORTED")
then
AC_MSG_RESULT([no])
noconfigdirs="$noconfigdirs target-libcilkrts"
else
AC_MSG_RESULT([yes])
fi
fi
fi
# Disable libitm on unsupported systems. # Disable libitm on unsupported systems.
if test -d ${srcdir}/libitm; then if test -d ${srcdir}/libitm; then
if test x$enable_libitm = x; then if test x$enable_libitm = x; then
......
2013-10-23 Balaji V. Iyer <balaji.v.iyer@intel.com>
* libcilkrts/Makefile.am: New file. Libcilkrts version 3902.
* libcilkrts/Makefile.in: Likewise
* libcilkrts/README: Likewise
* libcilkrts/aclocal.m4: Likewise
* libcilkrts/configure: Likewise
* libcilkrts/configure.ac: Likewise
* libcilkrts/include/cilk/cilk.h: Likewise
* libcilkrts/include/cilk/cilk_api.h: Likewise
* libcilkrts/include/cilk/cilk_api_linux.h: Likewise
* libcilkrts/include/cilk/cilk_stub.h: Likewise
* libcilkrts/include/cilk/cilk_undocumented.h: Likewise
* libcilkrts/include/cilk/common.h: Likewise
* libcilkrts/include/cilk/holder.h: Likewise
* libcilkrts/include/cilk/hyperobject_base.h: Likewise
* libcilkrts/include/cilk/metaprogramming.h: Likewise
* libcilkrts/include/cilk/reducer.h: Likewise
* libcilkrts/include/cilk/reducer_file.h: Likewise
* libcilkrts/include/cilk/reducer_list.h: Likewise
* libcilkrts/include/cilk/reducer_max.h: Likewise
* libcilkrts/include/cilk/reducer_min.h: Likewise
* libcilkrts/include/cilk/reducer_min_max.h: Likewise
* libcilkrts/include/cilk/reducer_opadd.h: Likewise
* libcilkrts/include/cilk/reducer_opand.h: Likewise
* libcilkrts/include/cilk/reducer_opmul.h: Likewise
* libcilkrts/include/cilk/reducer_opor.h: Likewise
* libcilkrts/include/cilk/reducer_opxor.h: Likewise
* libcilkrts/include/cilk/reducer_ostream.h: Likewise
* libcilkrts/include/cilk/reducer_string.h: Likewise
* libcilkrts/include/cilktools/cilkscreen.h: Likewise
* libcilkrts/include/cilktools/cilkview.h: Likewise
* libcilkrts/include/cilktools/fake_mutex.h: Likewise
* libcilkrts/include/cilktools/lock_guard.h: Likewise
* libcilkrts/include/internal/abi.h: Likewise
* libcilkrts/include/internal/cilk_fake.h: Likewise
* libcilkrts/include/internal/cilk_version.h: Likewise
* libcilkrts/include/internal/inspector-abi.h: Likewise
* libcilkrts/include/internal/metacall.h: Likewise
* libcilkrts/include/internal/rev.mk: Likewise
* libcilkrts/mk/cilk-version.mk: Likewise
* libcilkrts/mk/unix-common.mk: Likewise
* libcilkrts/runtime/acknowledgements.dox: Likewise
* libcilkrts/runtime/bug.cpp: Likewise
* libcilkrts/runtime/bug.h: Likewise
* libcilkrts/runtime/c_reducers.c: Likewise
* libcilkrts/runtime/cilk-abi-cilk-for.cpp: Likewise
* libcilkrts/runtime/cilk-abi-vla-internal.c: Likewise
* libcilkrts/runtime/cilk-abi-vla-internal.h: Likewise
* libcilkrts/runtime/cilk-abi-vla.c: Likewise
* libcilkrts/runtime/cilk-abi.c: Likewise
* libcilkrts/runtime/cilk-ittnotify.h: Likewise
* libcilkrts/runtime/cilk-tbb-interop.h: Likewise
* libcilkrts/runtime/cilk_api.c: Likewise
* libcilkrts/runtime/cilk_fiber-unix.cpp: Likewise
* libcilkrts/runtime/cilk_fiber-unix.h: Likewise
* libcilkrts/runtime/cilk_fiber.cpp: Likewise
* libcilkrts/runtime/cilk_fiber.h: Likewise
* libcilkrts/runtime/cilk_malloc.c: Likewise
* libcilkrts/runtime/cilk_malloc.h: Likewise
* libcilkrts/runtime/component.h: Likewise
* libcilkrts/runtime/doxygen-layout.xml: Likewise
* libcilkrts/runtime/doxygen.cfg: Likewise
* libcilkrts/runtime/except-gcc.cpp: Likewise
* libcilkrts/runtime/except-gcc.h: Likewise
* libcilkrts/runtime/except.h: Likewise
* libcilkrts/runtime/frame_malloc.c: Likewise
* libcilkrts/runtime/frame_malloc.h: Likewise
* libcilkrts/runtime/full_frame.c: Likewise
* libcilkrts/runtime/full_frame.h: Likewise
* libcilkrts/runtime/global_state.cpp: Likewise
* libcilkrts/runtime/global_state.h: Likewise
* libcilkrts/runtime/jmpbuf.c: Likewise
* libcilkrts/runtime/jmpbuf.h: Likewise
* libcilkrts/runtime/local_state.c: Likewise
* libcilkrts/runtime/local_state.h: Likewise
* libcilkrts/runtime/metacall_impl.c: Likewise
* libcilkrts/runtime/metacall_impl.h: Likewise
* libcilkrts/runtime/os-unix.c: Likewise
* libcilkrts/runtime/os.h: Likewise
* libcilkrts/runtime/os_mutex-unix.c: Likewise
* libcilkrts/runtime/os_mutex.h: Likewise
* libcilkrts/runtime/pedigrees.c: Likewise
* libcilkrts/runtime/pedigrees.h: Likewise
* libcilkrts/runtime/record-replay.cpp: Likewise
* libcilkrts/runtime/record-replay.h: Likewise
* libcilkrts/runtime/reducer_impl.cpp: Likewise
* libcilkrts/runtime/reducer_impl.h: Likewise
* libcilkrts/runtime/rts-common.h: Likewise
* libcilkrts/runtime/scheduler.c: Likewise
* libcilkrts/runtime/scheduler.h: Likewise
* libcilkrts/runtime/signal_node.c: Likewise
* libcilkrts/runtime/signal_node.h: Likewise
* libcilkrts/runtime/spin_mutex.c: Likewise
* libcilkrts/runtime/spin_mutex.h: Likewise
* libcilkrts/runtime/stacks.h: Likewise
* libcilkrts/runtime/stats.c: Likewise
* libcilkrts/runtime/stats.h: Likewise
* libcilkrts/runtime/symbol_test.c: Likewise
* libcilkrts/runtime/sysdep-unix.c: Likewise
* libcilkrts/runtime/sysdep.h: Likewise
* libcilkrts/runtime/unix_symbols.t: Likewise
* libcilkrts/runtime/worker_mutex.c: Likewise
* libcilkrts/runtime/worker_mutex.h: Likewise
# @copyright
# Copyright (C) 2011, 2013, Intel Corporation
# All rights reserved.
#
# @copyright
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# @copyright
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
AUTOMAKE_OPTIONS = foreign
# Use when building GCC
ACLOCAL_AMFLAGS = -I .. -I ../config
# Compiler and linker flags.
GENERAL_FLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/runtime -I$(top_srcdir)/runtime/config/$(config_dir) -DIN_CILK_RUNTIME=1
GENERAL_FLAGS += -D_Cilk_spawn="" -D_Cilk_sync="" -D_Cilk_for=for
# Enable Intel Cilk Plus extension
GENERAL_FLAGS += -fcilkplus
AM_CFLAGS = $(GENERAL_FLAGS) -std=c99
AM_CPPFLAGS = $(GENERAL_FLAGS)
AM_LDFLAGS = -lpthread -ldl
# Target list.
toolexeclib_LTLIBRARIES = libcilkrts.la
libcilkrts_la_SOURCES = \
runtime/config/$(config_dir)/cilk-abi-vla.c \
runtime/config/$(config_dir)/os-unix-sysdep.c \
runtime/bug.cpp \
runtime/cilk-abi.c \
runtime/cilk-abi-cilk-for.cpp \
runtime/cilk-abi-vla-internal.c \
runtime/cilk_api.c \
runtime/cilk_fiber.cpp \
runtime/cilk_fiber-unix.cpp \
runtime/cilk_malloc.c \
runtime/c_reducers.c \
runtime/except-gcc.cpp \
runtime/frame_malloc.c \
runtime/full_frame.c \
runtime/global_state.cpp \
runtime/jmpbuf.c \
runtime/local_state.c \
runtime/metacall_impl.c \
runtime/os_mutex-unix.c \
runtime/os-unix.c \
runtime/pedigrees.c \
runtime/record-replay.cpp \
runtime/reducer_impl.cpp \
runtime/scheduler.c \
runtime/signal_node.c \
runtime/spin_mutex.c \
runtime/stats.c \
runtime/symbol_test.c \
runtime/sysdep-unix.c \
runtime/worker_mutex.c
# Load the $(REVISION) value.
include include/internal/rev.mk
#libcilkrts_la_LDFLAGS = -rpath '$(libdir)'
libcilkrts_la_LDFLAGS = -version-info 5:0:0
libcilkrts_la_LDFLAGS += -lpthread -ldl
# If we're building on Linux, use the Linux version script
if LINUX_LINKER_SCRIPT
libcilkrts_la_LDFLAGS += -Wl,--version-script,$(srcdir)/runtime/linux-symbols.ver
endif
# If we're building on MacOS, use the Mac versioning
if MAC_LINKER_SCRIPT
libcilkrts_la_LDFLAGS += -Wl,-exported_symbols_list,$(srcdir)/runtime/mac-symbols.txt
endif
# Hack for Cygwin
libcilkrts_la_LDFLAGS += -no-undefined
# C/C++ header files for Cilk.
cilkincludedir = $(includedir)/cilk
cilkinclude_HEADERS = \
include/cilk/cilk_api.h \
include/cilk/cilk_api_linux.h \
include/cilk/cilk.h \
include/cilk/cilk_stub.h \
include/cilk/cilk_undocumented.h \
include/cilk/common.h \
include/cilk/holder.h \
include/cilk/hyperobject_base.h \
include/cilk/metaprogramming.h \
include/cilk/reducer_file.h \
include/cilk/reducer.h \
include/cilk/reducer_list.h \
include/cilk/reducer_max.h \
include/cilk/reducer_min.h \
include/cilk/reducer_min_max.h \
include/cilk/reducer_opadd.h \
include/cilk/reducer_opand.h \
include/cilk/reducer_opmul.h \
include/cilk/reducer_opor.h \
include/cilk/reducer_opxor.h \
include/cilk/reducer_ostream.h \
include/cilk/reducer_string.h
# Work around what appears to be a GNU make bug handling MAKEFLAGS
# values defined in terms of make variables, as is the case for CC and
# friends when we are called from the top level Makefile.
AM_MAKEFLAGS = \
"AR_FLAGS=$(AR_FLAGS)" \
"CC_FOR_BUILD=$(CC_FOR_BUILD)" \
"CFLAGS=$(CFLAGS)" \
"CXXFLAGS=$(CXXFLAGS)" \
"CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
"INSTALL=$(INSTALL)" \
"INSTALL_DATA=$(INSTALL_DATA)" \
"INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
"INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
"JC1FLAGS=$(JC1FLAGS)" \
"LDFLAGS=$(LDFLAGS)" \
"LIBCFLAGS=$(LIBCFLAGS)" \
"LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
"MAKE=$(MAKE)" \
"MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
"PICFLAG=$(PICFLAG)" \
"PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
"SHELL=$(SHELL)" \
"RUNTESTFLAGS=$(RUNTESTFLAGS)" \
"exec_prefix=$(exec_prefix)" \
"infodir=$(infodir)" \
"libdir=$(libdir)" \
"prefix=$(prefix)" \
"includedir=$(includedir)" \
"AR=$(AR)" \
"AS=$(AS)" \
"LD=$(LD)" \
"LIBCFLAGS=$(LIBCFLAGS)" \
"NM=$(NM)" \
"PICFLAG=$(PICFLAG)" \
"RANLIB=$(RANLIB)" \
"DESTDIR=$(DESTDIR)"
MAKEOVERRIDES=
Intel(R) Cilk(TM) Plus runtime library
Index:
1. BUILDING
2. USING
3. DOXYGEN DOCUMENTATION
4. QUESTIONS OR BUGS
5. CONTRIBUTIONS
#
# 1. BUILDING:
#
To distribute applications that use the Intel Cilk Plus language
extensions to non-development systems, you need to build the Intel
Cilk Plus runtime library and distribute it with your application.
To build the libcilkrts.so runtime library component, you need the
autoconf and automake packages, which are available through your
favorite package manager. You also need a C/C++ compiler that
supports the Intel Cilk Plus language extensions, since the runtime
uses Intel Cilk Plus features internally. Use either the Intel(R)
C++ Compiler (icc command) v12.1 or later, or in GCC 4.9 or later
(gcc command).
Once you have the necessary prerequisites installed, you can use the
following commands to create the library:
% libtoolize
% aclocal
% automake --add-missing
% autoconf
% ./configure
% make
% make install
This will produce the libcilkrts.so shared object. To install the
library in a custom location, set the prefix while running the
configure script:
% ./configure --prefix=/your/path/to/lib
#
# 2. USING:
#
The Intel(R) C++ Compiler will automatically try to bring in the
Intel Cilk Plus runtime in any program that uses the relevant
features. GCC requires explicit linking of both the library and
its dependencies (libpthread, libdl). For example:
% gcc foo.c -lcilkrts -lpthread -ldl
#
# 3. DOXYGEN DOCUMENTATION:
#
The library source has Doxygen markup. Generate HTML documentation
based on the markup by changing directory into runtime and running:
% doxygen doxygen.cfg
#
# 4. QUESTIONS OR BUGS:
#
Issues with the Intel Cilk Plus runtime can be addressed in the Intel
Cilk Plus forums:
http://software.intel.com/en-us/forums/intel-cilk-plus/
#
# 5. CONTRIBUTIONS:
#
The Intel Cilk Plus runtime library is dual licensed. The upstream copy
of the library is maintained via the BSD-licensed version available at:
http://cilkplus.org/
Changes to the Intel Cilk Plus runtime are welcome and should be
contributed to the upstream version via http://cilkplus.org/.
------------------------
Intel and Cilk are trademarks of Intel Corporation in the U.S. and/or
other countries.
This source diff could not be displayed because it is too large. You can view the blob instead.
# @copyright
# Copyright (C) 2011-2013, Intel Corporation
# All rights reserved.
#
# @copyright
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# @copyright
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
AC_INIT([Cilk Runtime Library], [2.0], [cilk@intel.com])
AC_PREREQ([2.64])
# Needed to define ${target}. Needs to be very early to avoid annoying
# warning about calling AC_ARG_PROGRAM before AC_CANONICAL_SYSTEM
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(foreign no-dist)
# Build a DLL on Windows
# AC_LIBTOOL_WIN32_DLL
AC_PROG_CXX
AC_PROG_CC
# AC_PROG_LIBTOOL
# AC_CONFIG_MACRO_DIR([..])
AC_CONFIG_FILES([Makefile])
AM_ENABLE_MULTILIB(, ..)
# Get target configury.
. ${srcdir}/configure.tgt
if test -n "$UNSUPPORTED"; then
AC_MSG_ERROR([Configuration ${target} is unsupported.])
fi
if test "${multilib}" = "yes"; then
multilib_arg="--enable-multilib"
else
multilib_arg=
fi
AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
AC_ARG_ENABLE([version-specific-runtime-libs],
AC_HELP_STRING([--enable-version-specific-runtime-libs],
[Specify that runtime libraries should be installed in a compi
ler-specific directory]),
[case "$enableval" in
yes) enable_version_specific_runtime_libs=yes ;;
no) enable_version_specific_runtime_libs=no ;;
*) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs
]);;
esac],
[enable_version_specific_runtime_libs=no])
AC_MSG_RESULT($enable_version_specific_runtime_libs)
# Calculate toolexeclibdir
# Also toolexecdir, though it's only used in toolexeclibdir
case ${enable_version_specific_runtime_libs} in
yes)
# Need the gcc compiler version to know where to install libraries
# and header files if --enable-version-specific-runtime-libs option
# is selected.
toolexecdir='$(libdir)/gcc/$(target_alias)'
toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
;;
no)
if test -n "$with_cross_host" &&
test x"$with_cross_host" != x"no"; then
# Install a library built with a cross compiler in tooldir, not libdir.
toolexecdir='$(exec_prefix)/$(target_alias)'
toolexeclibdir='$(toolexecdir)/lib'
else
toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
toolexeclibdir='$(libdir)'
fi
multi_os_directory=`$CC -print-multi-os-directory`
case $multi_os_directory in
.) ;; # Avoid trailing /.
*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
esac
;;
esac
# Set config_dir based on the target. config_dir specifies where to get
# target-specific files. The generic implementation is incomplete, but
# contains information on what's needed
case "${target}" in
x86_64-*-*)
config_dir="x86"
;;
i[456]86-*-*)
config_dir="x86"
;;
*)
config_dir="generic"
;;
esac
AC_SUBST(config_dir)
# We have linker scripts for appropriate operating systems
linux_linker_script=no
case "${host}" in
*-*-linux*)
linux_linker_script=yes
;;
esac
AM_CONDITIONAL(LINUX_LINKER_SCRIPT, test "$linux_linker_script" = "yes")
mac_linker_script=no
case "${host}" in
*-*-apple*)
mac_linker_script=yes
;;
esac
AM_CONDITIONAL(MAC_LINKER_SCRIPT, test "$mac_linker_script" = "yes")
AM_PROG_LIBTOOL
AC_SUBST(toolexecdir)
AC_SUBST(toolexeclibdir)
# Must be last
AC_OUTPUT
# @copyright
# Copyright (C) 2011-2013, Intel Corporation
# All rights reserved.
#
# @copyright
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# @copyright
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Disable Cilk Runtime library for non x86 architecture...for now.
case "${target}" in
x86_64-*-*)
;;
i?86-*-*)
;;
*-*-*)
UNSUPPORTED=1
;;
esac
# Disable libcilkrts on non POSIX hosted systems.
if test x$enable_libcilkrts = x ; then
# Enable libcilkrts by default on hosted POSIX systems.
case "${target}" in
*-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu | *-*-kopensolaris*-gnu)
;;
*-*-netbsd* | *-*-freebsd* | *-*-openbsd* | *-*-dragonfly*)
;;
*-*-solaris2* | *-*-hpux11*)
;;
*-*-darwin* | *-*-aix*)
;;
*)
UNSUPPORTED=1
;;
esac
fi
/* cilk.h -*-C++-*-
*
* @copyright
* Copyright (C) 2010-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** @file cilk.h
*
* @brief Provides convenient aliases for the Cilk language keywords.
*
* @details
* Since Cilk is a nonstandard extension to both C and C++, the Cilk
* language keywords all begin with “`_Cilk_`”, which guarantees that they
* will not conflict with user-defined identifiers in properly written
* programs, so that “standard” C and C++ programs can safely be
* compiled a Cilk-enabled C or C++ compiler.
*
* However, this means that the keywords _look_ like something grafted on to
* the base language. Therefore, you can include this header:
*
* #include "cilk/cilk.h"
*
* and then write the Cilk keywords with a “`cilk_`” prefix instead of
* “`_Cilk_`”.
*
* @ingroup language
*/
/** @defgroup language Language Keywords
* Definitions having to do with the Cilk language.
* @{
*/
#ifndef cilk_spawn
# define cilk_spawn _Cilk_spawn ///< Spawn a task that can execute in parallel.
# define cilk_sync _Cilk_sync ///< Wait for spawned tasks to complete.
# define cilk_for _Cilk_for ///< Execute iterations of a for loop in parallel.
#endif
/// @}
/*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
/* THIS FILE IS DEPRECATED. USE cilk_api.h INSTEAD. */
#include <cilk/cilk_api.h>
/* cilk_stub.h -*-C++-*-
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef INCLUDED_CILK_STUB_DOT_H
#define INCLUDED_CILK_STUB_DOT_H
/* Definitions for creating a serialization from a Cilk program.
* These definitions are suitable for use by a compiler that is not
* Cilk-enabled.
*/
/* Pretend we are a non-Cilk compiler */
#undef __cilk
#define CILK_STUB
/* Replace Cilk keywords with serial equivalents */
#define _Cilk_spawn
#define _Cilk_sync
#define _Cilk_for for
#endif /* ! defined(INCLUDED_CILK_STUB_DOT_H) */
/*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*
* cilk_undocumented.h
*
* This file defines exported functions that are not included in the standard
* documentation.
*/
#ifndef INCLUDED_CILK_UNDOCUMENTED_H
#define INCLUDED_CILK_UNDOCUMENTED_H
#include <cilk/common.h>
#ifndef CILK_STUB
__CILKRTS_BEGIN_EXTERN_C
/*
* __cilkrts_synched
*
* Allows an application to determine if there are any outstanding children at
* this instant. This function will examine the current full frame to
* determine this. This function will return a valid result only when called
* within a spawn continuation, within the stack frame of the continuation
* itself.
*/
CILK_EXPORT __CILKRTS_NOTHROW
int __cilkrts_synched(void);
/*
* __cilkrts_cilkscreen_puts
*
* Allows an application to write a string to the Cilkscreen log.
* The standard error stream will be flushed after the write.
*/
CILK_EXPORT __CILKRTS_NOTHROW
void __cilkrts_cilkscreen_puts(const char *);
/*
* __cilkrts_get_sf
*
* A debugging aid that allows an application to get the __cilkrts_stack_frame
* for the current function. Only compiled into the DLL in debug builds.
*/
CILK_EXPORT __CILKRTS_NOTHROW
void *__cilkrts_get_sf(void);
/**
* Returns the size of stacks created by Cilk.
*/
CILK_EXPORT __CILKRTS_NOTHROW
size_t __cilkrts_get_stack_size(void);
/**
* Dumps runtime statistics to stderr.
* Undocumented API for debugging.
*/
CILK_EXPORT __CILKRTS_NOTHROW
void __cilkrts_dump_stats(void);
CILK_EXPORT __CILKRTS_NOTHROW
int __cilkrts_irml_version(void);
struct __cilk_tbb_unwatch_thunk;
struct __cilk_tbb_stack_op_thunk;
CILK_EXPORT __CILKRTS_NOTHROW
int __cilkrts_watch_stack(struct __cilk_tbb_unwatch_thunk *u,
struct __cilk_tbb_stack_op_thunk o);
#ifndef IN_CILK_RUNTIME
#ifdef _WIN32
/* Do not use CILK_API because __cilkrts_worker_stub must be __stdcall */
CILK_EXPORT unsigned __CILKRTS_NOTHROW __stdcall
__cilkrts_worker_stub(void *arg);
#else
/* Do not use CILK_API because __cilkrts_worker_stub have default visibility */
CILK_EXPORT void* __CILKRTS_NOTHROW
__cilkrts_worker_stub(void *arg);
#endif /* _WIN32 */
#endif /* IN_CILK_RUNTIME */
__CILKRTS_END_EXTERN_C
#else /* CILK_STUB */
/* Stubs for the api functions */
#define __cilkrts_get_stack_size() (0)
#define __cilkrts_synched() (1)
#endif /* CILK_STUB */
#endif /* INCLUDED_CILK_UNDOCUMENTED_H */
/*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef INCLUDED_CILK_HYPEROBJECT_BASE
#define INCLUDED_CILK_HYPEROBJECT_BASE
#ifdef __cplusplus
# include <cstdlib>
# include <cstddef>
#else
# include <stdlib.h>
# include <stddef.h>
#endif
#include <cilk/common.h>
#if defined _WIN32 || defined _WIN64
# if !defined CILK_STUB && !defined IN_CILK_RUNTIME
/* bring in the Cilk library, which has definitions for some of these
* functions. */
# pragma comment(lib, "cilkrts")
# endif
#endif
/* The __CILKRTS_STRAND_PURE attribute tells the compiler that the value
* returned by 'func' for a given argument to 'func' will remain valid until
* the next strand boundary (spawn or sync) or until the next call to a
* function with the __CILKRTS_STRAND_STALE attribute using the same function
* argument.
*/
#if 0 && defined __cilk && (defined __GNUC__ && !defined _WIN32) && defined __cilkartsrev
# define __CILKRTS_STRAND_PURE(func) \
func __attribute__((__cilk_hyper__("lookup")))
# define __CILKRTS_STRAND_STALE(func) \
func __attribute__((__cilk_hyper__("flush")))
#else
# define __CILKRTS_STRAND_PURE(func) func
# define __CILKRTS_STRAND_STALE(func) func
#endif
/*****************************************************************************
* C runtime interface to the hyperobject subsystem
*****************************************************************************/
__CILKRTS_BEGIN_EXTERN_C
/* Callback function signatures. The 'r' argument always points to the
* reducer itself and is commonly ignored. */
typedef void (*cilk_c_reducer_reduce_fn_t)(void* r, void* lhs, void* rhs);
typedef void (*cilk_c_reducer_identity_fn_t)(void* r, void* view);
typedef void (*cilk_c_reducer_destroy_fn_t)(void* r, void* view);
typedef void* (*cilk_c_reducer_allocate_fn_t)(void* r, __STDNS size_t bytes);
typedef void (*cilk_c_reducer_deallocate_fn_t)(void* r, void* view);
/** Representation of the monoid */
typedef struct cilk_c_monoid {
cilk_c_reducer_reduce_fn_t reduce_fn;
cilk_c_reducer_identity_fn_t identity_fn;
cilk_c_reducer_destroy_fn_t destroy_fn;
cilk_c_reducer_allocate_fn_t allocate_fn;
cilk_c_reducer_deallocate_fn_t deallocate_fn;
} cilk_c_monoid;
/** Base of the hyperobject */
typedef struct __cilkrts_hyperobject_base
{
cilk_c_monoid __c_monoid;
unsigned long long __flags;
__STDNS ptrdiff_t __view_offset; /* offset (in bytes) to leftmost view */
__STDNS size_t __view_size; /* Size of each view */
} __cilkrts_hyperobject_base;
#ifndef CILK_STUB
/* Library functions. */
CILK_EXPORT
void __cilkrts_hyper_create(__cilkrts_hyperobject_base *key);
CILK_EXPORT void __CILKRTS_STRAND_STALE(
__cilkrts_hyper_destroy(__cilkrts_hyperobject_base *key));
CILK_EXPORT void* __CILKRTS_STRAND_PURE(
__cilkrts_hyper_lookup(__cilkrts_hyperobject_base *key));
CILK_EXPORT
void* __cilkrts_hyperobject_alloc(void* ignore, __STDNS size_t bytes);
CILK_EXPORT
void __cilkrts_hyperobject_dealloc(void* ignore, void* view);
/* No-op destroy function */
CILK_EXPORT
void __cilkrts_hyperobject_noop_destroy(void* ignore, void* ignore2);
#else // CILK_STUB
// Programs compiled with CILK_STUB are not linked with the Cilk runtime
// library, so they should not have external references to cilkrts functions.
// Furthermore, they don't need the hyperobject functionality, so the
// functions can be stubbed.
#define __cilkrts_hyperobject_create __cilkrts_hyperobject_create__stub
__CILKRTS_INLINE
void __cilkrts_hyper_create(__cilkrts_hyperobject_base *key)
{}
#define __cilkrts_hyperobject_destroy __cilkrts_hyperobject_destroy__stub
__CILKRTS_INLINE
void __cilkrts_hyper_destroy(__cilkrts_hyperobject_base *key)
{}
#define __cilkrts_hyperobject_lookup __cilkrts_hyperobject_lookup__stub
__CILKRTS_INLINE
void* __cilkrts_hyper_lookup(__cilkrts_hyperobject_base *key)
{ return (char*)(key) + key->__view_offset; }
// Pointers to these functions are stored into monoids, so real functions
// are needed.
#define __cilkrts_hyperobject_alloc __cilkrts_hyperobject_alloc__stub
__CILKRTS_INLINE
void* __cilkrts_hyperobject_alloc(void* ignore, __STDNS size_t bytes)
{ assert(0); return __STDNS malloc(bytes); }
#define __cilkrts_hyperobject_dealloc __cilkrts_hyperobject_dealloc__stub
__CILKRTS_INLINE
void __cilkrts_hyperobject_dealloc(void* ignore, void* view)
{ assert(0); __STDNS free(view); }
#define __cilkrts_hyperobject_noop_destroy \
__cilkrts_hyperobject_noop_destroy__stub
__CILKRTS_INLINE
void __cilkrts_hyperobject_noop_destroy(void* ignore, void* ignore2)
{}
#endif
__CILKRTS_END_EXTERN_C
#endif /* INCLUDED_CILK_HYPEROBJECT_BASE */
/*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
/* reducer_max.h -*- C++ -*-
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** @file reducer_max.h
*
* @brief Defines classes for doing parallel maximum reductions.
*
* @ingroup ReducersMinMax
*
* @see ReducersMinMax
*/
#include "reducer_min_max.h"
/* reducer_min.h -*- C++ -*-
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** @file reducer_min.h
*
* @brief Defines classes for doing parallel minimum reductions.
*
* @ingroup ReducersMinMax
*
* @see ReducersMinMax
*/
#include "reducer_min_max.h"
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* reducer_ostream.h
*
* Purpose: Hyper-object to write to 'std::ostream's
*
* Classes: reducer_ostream
*
* Description:
* ============
* Output streams ('std::ostream's) are a convenient means of writing text to
* files, the user console, or sockets. In a serial program, text is written
* to an ostream in a specific, logical order. For example, computing while
* traversing a data structure and printing them to an 'ostream' will result
* in the values being printed in the order of traversal. In a parallel
* version of the same program, however, different parts of the data structure
* may be traversed in a different order, resulting in a non-deterministic
* ordering of the stream. Worse, multiple strands may write to the same
* stream simultaneously, resulting in a data race. Replacing the
* 'std::ostream' with a 'cilk::reducer_ostream' will solve both problems: Data
* will appeaer in the stream in the same order as it would for the serial
* program, and there will be no races (no locks) on the common stream.
*
* Usage Example:
* ==============
* Assume we wish to traverse an array of objects, performing an operation on
* each object and writing the result to a file. Without a reducer_ostream,
* we have a race on the 'output' file stream:
*..
* void compute(std::ostream& os, double x)
* {
* // Perform some significant computation and print the result:
* os << std::asin(x);
* }
*
* int test()
* {
* const std::size_t ARRAY_SIZE = 1000000;
* extern double myArray[ARRAY_SIZE];
*
* std::ofstream output("output.txt");
* cilk_for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
* {
* compute(output, myArray[i]);
* }
*
* return 0;
* }
*..
* The race is solved by using a reducer_ostream to proxy the 'output' file:
*..
* void compute(cilk::reducer_ostream& os, double x)
* {
* // Perform some significant computation and print the result:
* *os << std::asin(x);
* }
*
* int test()
* {
* const std::size_t ARRAY_SIZE = 1000000;
* extern double myArray[ARRAY_SIZE];
*
* std::ofstream output("output.txt");
* cilk::reducer_ostream hyper_output(output);
* cilk_for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
* {
* compute(hyper_output, myArray[i]);
* }
*
* return 0;
* }
*..
*
* Limitations:
* ============
* There are two possible values for the formatting flags immediately after a
* 'cilk_spawn' statement: they may either have the value that was set by the
* spawn function, or they may have default values. Because of
* non-determinism in the processor scheduling, there is no way to determine
* which it will be. Similarly, the formatting flags after a 'cilk_sync' may
* or may not have the same value as before the sync. Therefore, one must use
* a disciplined coding style to avoid formatting errors. There are two
* approaches to mitigating the problem: The first is to eliminate the
* difference between the two possible outcomes by ensuring that the spawned
* function always returns the flags to their initial state:
*..
* void compute(cilk::reducer_ostream& os, double x)
* {
* // Perform some significant computation and print the result:
* int saveprec = os.precision(5);
* os << std::asin(x);
* os.precision(saveprec);
* }
*..
* The second approach is to write your streaming operations such that they
* don't depend on the previous state of the formatting flags by setting any
* important flags before every block of output:
*..
* cilk_spawn compute(hyper_output, value);
*
* hyper_output->precision(2); // Don't depend on previous precision
* *hyper_output << f();
* *hyper_output << g();
*..
* Another concern is memory usage. A reducer_ostream will buffer as much text
* as necessary to ensure that the order of output matches that of the serial
* version of the program. If all spawn branches perform an equal amount of
* output, then one can expect that half of the output before a sync will be
* buffered in memory. This hyperobject is therefore not well suited for
* serializing very large quantities of text output.
*/
#ifndef REDUCER_OSTREAM_H_INCLUDED
#define REDUCER_OSTREAM_H_INCLUDED
#include <cilk/reducer.h>
#include <iostream>
#include <sstream>
namespace cilk {
/**
* @brief Class 'reducer_ostream' is the representation of a hyperobject for
* output text streaming.
*/
class reducer_ostream
{
public:
/// Internal representation of the per-strand view of the data for reducer_ostream
class View: public std::ostream
{
public:
/// Type of the std::stream reducer_ostream is based on
typedef std::ostream Base;
friend class reducer_ostream;
View():
std::ostream(0)
{
Base::rdbuf(&strbuf_);
};
private:
void use_ostream (const std::ostream &os)
{
Base::rdbuf(os.rdbuf());
Base::flags(os.flags()); // Copy formatting flags
Base::setstate(os.rdstate()); // Copy error state
}
private:
std::stringbuf strbuf_;
};
public:
/// Definition of data view, operation, and identity for reducer_ostream
struct Monoid: monoid_base< View >
{
static void reduce (View *left, View *right);
};
private:
// Hyperobject to serve up views
reducer<Monoid> imp_;
// Methods that provide the API for the reducer
public:
// Construct an initial 'reducer_ostream' from an 'std::ostream'. The
// specified 'os' stream is used as the eventual destination for all
// text streamed to this hyperobject.
explicit reducer_ostream(const std::ostream &os);
// Return a modifiable reference to the underlying 'ostream' object.
std::ostream& get_reference();
/**
* Append data from some type to the reducer_ostream
*
* @param v Value to be appended to the reducer_ostream
*/
template<typename T>
std::ostream &
operator<< (const T &v)
{
return imp_.view() << v;
}
/**
* Append data from a std::ostream to the reducer_ostream
*
* @param _Pfn std::ostream to copy from
*/
std::ostream &
operator<< (std::ostream &(*_Pfn)(std::ostream &))
{
View &v = imp_.view();
return ((*_Pfn)(v));
}
reducer_ostream& operator*() { return *this; }
reducer_ostream const& operator*() const { return *this; }
reducer_ostream* operator->() { return this; }
reducer_ostream const* operator->() const { return this; }
};
// -------------------------------------------
// class reducer_ostream::Monoid
// -------------------------------------------
/**
* Appends string from "right" reducer_basic_string onto the end of
* the "left". When done, the "right" reducer_basic_string is empty.
*/
void
reducer_ostream::Monoid::reduce(View *left, View *right)
{
left->operator<< (&right->strbuf_);
}
// --------------------------
// class reducer_ostream
// --------------------------
/**
* Construct a reducer_ostream which will write to the specified std::ostream
*
* @param os std::ostream to write to
*/
inline
reducer_ostream::reducer_ostream(const std::ostream &os) :
imp_()
{
View &v = imp_.view();
v.use_ostream(os);
}
/**
* Get a reference to the std::ostream
*/
inline
std::ostream &
reducer_ostream::get_reference()
{
View &v = imp_.view();
return v;
}
} // namespace cilk
#endif // REDUCER_OSTREAM_H_INCLUDED
/* cilkscreen.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2010-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************/
#ifndef INCLUDED_CILKSCREEN_H
#define INCLUDED_CILKSCREEN_H
#include <cilk/cilk_api.h>
/*
* Cilkscreen "functions". These macros generate metadata in your application
* to notify Cilkscreen of program state changes
*/
#if ! defined(CILK_STUB) && defined(__INTEL_COMPILER)
# define __cilkscreen_metacall(annotation,expr) \
__notify_zc_intrinsic((char *)annotation, expr)
#else
# define __cilkscreen_metacall(annotation,expr) ((void)annotation, (void)(expr))
#endif
/* Call once when a user thread enters a spawning function */
#define __cilkscreen_enable_instrumentation() \
__cilkscreen_metacall("cilkscreen_enable_instrumentation", 0)
/* Call once when a user thread exits a spawning function */
#define __cilkscreen_disable_instrumentation() \
__cilkscreen_metacall("cilkscreen_disable_instrumentation", 0)
/* Call to temporarily disable cilkscreen instrumentation */
#define __cilkscreen_enable_checking() \
__cilkscreen_metacall("cilkscreen_enable_checking", 0)
/* Call to re-enable temporarily-disabled cilkscreen instrumentation */
#define __cilkscreen_disable_checking() \
__cilkscreen_metacall("cilkscreen_disable_checking", 0)
/* Inform cilkscreen that memory from begin to end can be reused without
* causing races (e.g., for memory that comes from a memory allocator) */
#define __cilkscreen_clean(begin, end) \
do { \
void *__data[2] = { (begin), (end) }; \
__cilkscreen_metacall("cilkscreen_clean", &__data); \
} while(0)
/* Inform cilkscreen that a lock is being acquired.
* If the lock type is not a handle, then the caller should take its address
* and pass the pointer to the lock. Otherwise, the caller should pass the
* lock handle directly.
*/
#define __cilkscreen_acquire_lock(lock) \
__cilkscreen_metacall("cilkscreen_acquire_lock", (lock))
#define __cilkscreen_release_lock(lock) \
__cilkscreen_metacall("cilkscreen_release_lock", (lock))
/*
* Metacall data
*
* A metacall is a way to pass data to a function implemented by a tool.
* Metacalls are always instrumented when the tool is loaded.
*/
// Tool code for Cilkscreen
#define METACALL_TOOL_CILKSCREEN 1
// Metacall codes implemented by Cilkscreen
#define CS_METACALL_PUTS 0 // Write string to the Cilkscreen log
#define __cilkscreen_puts(text) \
__cilkrts_metacall(METACALL_TOOL_CILKSCREEN, CS_METACALL_PUTS, (void *)(const char *)text)
#endif /* defined(INCLUDED_CILKSCREEN_H) */
/* cilkview.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2010-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************/
#ifndef INCLUDED_CILKVIEW_H
#define INCLUDED_CILKVIEW_H
#include <cilk/cilk_api.h>
#ifdef _WIN32
# ifndef _WINBASE_
__CILKRTS_BEGIN_EXTERN_C
unsigned long __stdcall GetTickCount();
__CILKRTS_END_EXTERN_C
# endif
#endif // _WIN32
#if defined __unix__ || defined __APPLE__ || defined __VXWORKS__
# include <sys/time.h>
#endif // defined __unix__ || defined __APPLE__
/// @brief Return the system clock with millisecond resolution
///
/// This function returns a long integer representing the number of
/// milliseconds since an arbitrary starting point, e.g., since the system was
/// started or since the Unix Epoch. The result is meaningless by itself, but
/// the difference between two sequential calls to __cilkview_getticks()
/// represents the time interval that elapsed between them (in ms).
static inline unsigned long long __cilkview_getticks()
{
#if __INTEL_COMPILER > 1200
// When inlined, prevent code motion around this call
__notify_zc_intrinsic((void*) "test_getticks_start", 0);
#endif
#ifdef _WIN32
// Return milliseconds elapsed since the system started
return GetTickCount();
#elif defined(__unix__) || defined(__APPLE__) || defined __VXWORKS__
// Return milliseconds elapsed since the Unix Epoch
// (1-Jan-1970 00:00:00.000 UTC)
struct timeval t;
gettimeofday(&t, 0);
return t.tv_sec * 1000ULL + t.tv_usec / 1000;
#else
# error test_getticks() not implemented for this OS
#endif
#if __INTEL_COMPILER > 1200
// When inlined, prevent code motion around this call
__notify_zc_intrinsic((void*) "test_getticks_end", 0);
#endif
}
typedef struct
{
unsigned int size; // Size of structure in bytes
unsigned int status; // 1 = success, 0 = failure
unsigned long long time; // Time in milliseconds
unsigned long long work;
unsigned long long span;
unsigned long long burdened_span;
unsigned long long spawns;
unsigned long long syncs;
unsigned long long strands;
unsigned long long atomic_ins;
unsigned long long frames;
} cilkview_data_t;
typedef struct
{
cilkview_data_t *start; // Values at start of interval
cilkview_data_t *end; // Values at end of interval
const char *label; // Name for this interval
unsigned int flags; // What to do - see flags below
} cilkview_report_t;
// What __cilkview_report should do. The flags can be ORed together
enum
{
CV_REPORT_WRITE_TO_LOG = 1, // Write parallelism report to the log (xml or text)
CV_REPORT_WRITE_TO_RESULTS = 2 // Write parallelism data to results file
};
#ifndef CILKVIEW_NO_REPORT
static void __cilkview_do_report(cilkview_data_t *start,
cilkview_data_t *end,
const char *label,
unsigned int flags);
#endif /* CILKVIEW_NO_REPORT */
/*
* Metacall data
*
* A metacall is a way to pass data to a function implemented by a tool.
* Metacalls are always instrumented when the tool is loaded.
*/
// Tool code for Cilkview
#define METACALL_TOOL_CILKVIEW 2
// Metacall codes implemented by Cilkview
enum
{
CV_METACALL_PUTS,
CV_METACALL_QUERY,
CV_METACALL_START,
CV_METACALL_STOP,
CV_METACALL_RESET,
CV_METACALL_USE_DEFAULT_GRAIN,
CV_METACALL_CONNECTED,
CV_METACALL_SUSPEND,
CV_METACALL_RESUME,
CV_METACALL_REPORT
};
#if ! defined(CILK_STUB) && defined(__INTEL_COMPILER)
# define __cilkview_metacall(code,data) \
__cilkrts_metacall(METACALL_TOOL_CILKVIEW, code, data)
#else
# define __cilkview_metacall(annotation,expr) (annotation, (void) (expr))
#endif
// Write arbitrary string to the log
#define __cilkview_puts(arg) \
__cilkview_metacall(CV_METACALL_PUTS, arg)
// Retrieve the Cilkview performance counters. The parameter must be a
// cilkview_data_t
#define __cilkview_query(d) \
do { \
d.size = sizeof(d); \
d.status = 0; \
__cilkview_metacall(CV_METACALL_QUERY, &d); \
if (0 == d.status) \
d.time = __cilkview_getticks(); \
} while (0)
// Write report to log or results file. If end is NULL, Cilkview will
// use the current values.
#define __cilkview_report(start, end, label, flags) \
__cilkview_do_report(start, end, label, flags)
// Control the workspan performance counters for the final report
#define __cilkview_workspan_start() \
__cilkview_metacall(CV_METACALL_START, 0)
#define __cilkview_workspan_stop() \
__cilkview_metacall(CV_METACALL_STOP, 0)
#define __cilkview_workspan_reset() \
__cilkview_metacall(CV_METACALL_RESET, 0)
#define __cilkview_workspan_suspend() \
__cilkview_metacall(CV_METACALL_SUSPEND, 0)
#define __cilkview_workspan_resume() \
__cilkview_metacall(CV_METACALL_RESUME, 0)
#define __cilkview_use_default_grain_size() \
__cilkview_metacall(CV_METACALL_USE_DEFAULT, 0)
// Sets the int is_connected to 1 if Cilkview is active
#define __cilkview_connected(is_connected) \
__cilkview_metacall(CV_METACALL_CONNECTED, &is_connected)
#ifndef CILKVIEW_NO_REPORT
// Stop Microsoft include files from complaining about getenv and fopen
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable: 1786) // Suppress warnings that getenv, fopen are deprecated
#endif
static void __cilkview_do_report(cilkview_data_t *start,
cilkview_data_t *end,
const char *label,
unsigned int flags)
{
int under_cilkview = 0;
unsigned long long elapsed_ms;
int worker_count = 0;
char *nworkers;
char *outfile;
FILE *f;
// Check whether we're running under Cilkview
__cilkview_connected(under_cilkview);
// If we're running under Cilkview, let it do those things that need
// to be done
if (under_cilkview)
{
cilkview_report_t d = {start, end, label, flags};
__cilkview_metacall(CV_METACALL_REPORT, &d);
return;
}
// We're not running under Cilkview.
//
// If we weren't asked to write to the results file, we're done.
if (0 == (flags & CV_REPORT_WRITE_TO_RESULTS))
return;
// Calculate the elapse milliseconds
if (NULL == end)
elapsed_ms = __cilkview_getticks() - start->time;
else
elapsed_ms = end->time - start->time;
// Determine how many workers we're using for this trial run
nworkers = getenv("CILK_NWORKERS");
if (NULL != nworkers)
worker_count = atoi(nworkers);
if (0 == worker_count)
worker_count = 16;
// Open the output file and write the trial data to it
outfile = getenv("CILKVIEW_OUTFILE");
if (NULL == outfile)
outfile = (char *)"cilkview.out";
f = fopen(outfile, "a");
if (NULL == f)
fprintf(stderr, "__cilkview_do_report: unable to append to file %s\n", outfile);
else
{
fprintf(f, "%s trial %d %f\n", label,
worker_count,
((float)elapsed_ms) / 1000.0f);
fclose(f);
}
}
#ifdef _WIN32
#pragma warning(pop)
#endif
#endif // CILKVIEW_NO_REPORT
#endif /* ! defined(INCLUDED_CILKVIEW_H) */
/* fake_mutex.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* Cilkscreen fake mutexes are provided to indicate to the Cilkscreen race
* detector that a race should be ignored.
*
* NOTE: This class does not provide mutual exclusion. You should use the
* mutual exclusion constructs provided by TBB or your operating system to
* protect against real data races.
*/
#ifndef FAKE_MUTEX_H_INCLUDED
#define FAKE_MUTEX_H_INCLUDED
#include <cilktools/cilkscreen.h>
namespace cilkscreen
{
class fake_mutex
{
public:
fake_mutex() : locked(false)
{
}
~fake_mutex()
{
__CILKRTS_ASSERT(! locked);
}
// Wait until mutex is available, then enter
void lock()
{
__cilkscreen_acquire_lock(&locked);
__CILKRTS_ASSERT(! locked);
locked = true;
}
// A fake mutex is always available
bool try_lock() { lock(); return true; }
// Releases the mutex
void unlock()
{
__CILKRTS_ASSERT(locked);
locked = false;
__cilkscreen_release_lock(&locked);
}
private:
bool locked;
};
} // namespace cilk
#endif // FAKE_MUTEX_H_INCLUDED
/* lock_guard.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2011-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* Lock guard patterned after the std::lock_guard class template proposed in
* the C++ 0x draft standard.
*
* An object of type lock_guard controls the ownership of a mutex object
* within a scope. A lock_guard object maintains ownership of a mutex object
* throughout the lock_guard object's lifetime. The behavior of a program is
* undefined if the mutex referenced by pm does not exist for the entire
* lifetime of the lock_guard object.
*/
#ifndef LOCK_GUARD_H_INCLUDED
#define LOCK_GUARD_H_INCLUDED
#include <cilk/cilk.h>
namespace cilkscreen
{
template <class Mutex>
class lock_guard
{
public:
typedef Mutex mutex_type;
explicit lock_guard(mutex_type &m) : pm(m)
{
pm.lock();
locked = true;
}
~lock_guard()
{
locked = false;
pm.unlock();
}
private:
lock_guard(lock_guard const&);
lock_guard& operator=(lock_guard const&);
private:
// exposition only:
mutex_type &pm;
bool locked;
};
}
#endif // LOCK_GUARD_H_INCLUDED
// cilk_version.h
//
// @copyright
// Copyright (C) 2009-2013, Intel Corporation
// All rights reserved.
//
// @copyright
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Intel Corporation nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// @copyright
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// DO NOT EDIT THIS FILE!
//
// It was automatically generated by cilkrts/include/internal/Makefile
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_BUILD 3902
#define VERSION_REV 0
#define VERSION_STRING "2,0,3902,0"
#define VERSION_HASH "b4e38f4f7e3e"
#define VERSION_BRANCH "v14.0"
#define TBB_REV_NUMBER ""
#define VERSION_YEAR "2013"
// -*- C++ -*-
/*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*
* metacall.h
*
* This is an internal header file defining part of the metacall
* interface used by Cilkscreen. It is not a stable API and is
* subject to change without notice.
*/
// Provides the enum of metacall kinds. This is used by Cilkscreen and the
// runtime, and will probably be used by any future ptools.
#pragma once
///////////////////////////////////////////////////////////////////////////////
enum
{
// Notify Cilkscreen to stop/start instrumenting code
HYPER_DISABLE_INSTRUMENTATION = 0,
HYPER_ENABLE_INSTRUMENTATION = 1,
// Write 0 in *(char *)arg if the p-tool is sequential. The Cilk runtime
// system invokes this metacall to know whether to spawn worker threads.
HYPER_ZERO_IF_SEQUENTIAL_PTOOL = 2,
// Write 0 in *(char *)arg if the runtime must force reducers to
// call the reduce() method even if no actual stealing occurs.
HYPER_ZERO_IF_FORCE_REDUCE = 3,
// Inform cilkscreen about the current stack pointer.
HYPER_ESTABLISH_C_STACK = 4,
// Inform Cilkscreen about the current worker
HYPER_ESTABLISH_WORKER = 5,
// Tell tools to ignore a block of memory. Parameter is a 2 element
// array: void *block[2] = {_begin, _end}; _end is 1 beyond the end
// of the block to be ignored. Essentially, if p is a pointer to an
// array, _begin = &p[0], _end = &p[max]
HYPER_IGNORE_MEMORY_BLOCK = 6
// If you add metacalls here, remember to update BOTH workspan.cpp AND
// cilkscreen-common.cpp!
};
typedef struct
{
unsigned int tool; // Specifies tool metacall is for
// (eg. system=0, cilkscreen=1, cilkview=2).
// All tools should understand system codes.
// Tools should ignore all other codes, except
// their own.
unsigned int code; // Tool-specific code specifies what to do and how to
// interpret data
void *data;
} metacall_data_t;
#define METACALL_TOOL_SYSTEM 0
///////////////////////////////////////////////////////////////////////////////
#########################################################################
#
# @copyright
# Copyright (C) 2011-2013, Intel Corporation
# All rights reserved.
#
# @copyright
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# @copyright
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###########################################################################
# DO NOT EDIT THIS FILE!
#
# It was automatically generated by cilkrts/include/internal/Makefile
CILK_REVISION = 3902
#########################################################################
#
# @copyright
# Copyright (C) 2009-2013, Intel Corporation
# All rights reserved.
#
# @copyright
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# @copyright
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###########################################################################
# cilk-version.mk
#
# The one place we look up information from the code management system
#
# Note that the build number is *only* valid on the build machines
ifeq ($(wildcard $(TOP)/../.hg),)
# If this is the open source release, there is no Mercurial repository,
# so set some reasonable defaults.
CILK_VERSION_MAJOR := 2
CILK_VERSION_MINOR := 0
CILK_VERSION_BUILD := 1
CILK_VERSION_REV := 0
CILK_VERSION_HASH := 000000000000
CILK_VERSION_BRANCH := oss
else
CILK_VERSION_MAJOR := 2
CILK_VERSION_MINOR := 0
CILK_VERSION_BUILD := $(firstword $(subst +, ,$(shell hg id --num)))
CILK_VERSION_REV := 0
CILK_VERSION_HASH := $(firstword $(subst +, ,$(shell hg id --id)))
CILK_VERSION_BRANCH := $(shell hg id --branch)
endif
/* acknowledgements.dox
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/*
* This file contains acknowledgements of community contributions to the
* Cilk Plus runtime.
*/
/**
* @mainpage
*
* @section Acknowledgements Acknowledgements
*
* Modifications to build the Cilk Plus runtime for VxWorks provided by
* Brian Kuhl of Wind River.
*/
/* bug.cpp -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
#include "bug.h"
#include <exception>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#ifdef _WIN32
# include "windows-clean.h"
# include "internal/abi.h"
# include "cilktools/cilkscreen.h"
# include <crtdbg.h>
#endif
__CILKRTS_BEGIN_EXTERN_C
COMMON_PORTABLE const char *const __cilkrts_assertion_failed =
"%s:%d: cilk assertion failed: %s\n";
COMMON_PORTABLE void __cilkrts_bug(const char *fmt,...) cilk_nothrow
{
#if defined (_WIN32) && defined(_DEBUG)
_CRTIMP void __cdecl _wassert(__in_z const wchar_t * _Message,
__in_z const wchar_t *_File,
__in unsigned _Line);
char message[256];
wchar_t wmessage[256];
va_list l;
va_start(l, fmt);
_vsnprintf_s(message, 256, _TRUNCATE, fmt, l);
va_end(l);
_snwprintf_s(wmessage, 256, _TRUNCATE, _CRT_WIDE("%S"),
message); /* widen */
// Force asserts to go to stderr and the debugger. This isn't polite, but
// we're about to kill the app anyway and it will prevent our tests from
// hanging
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE| _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
_wassert(wmessage, _CRT_WIDE(__FILE__), __LINE__);
// If there's a debugger attached, give it a chance to look at the failure
if (IsDebuggerPresent())
DebugBreak();
abort();
/* __asm int 3 */
#else
/* To reduce user confusion, write all user-generated output
before the system-generated error message. */
va_list l;
fflush(NULL);
va_start(l, fmt);
vfprintf(stderr, fmt, l);
va_end(l);
fflush(stderr);
#ifndef _WIN32
abort();
#endif
#endif
exit(1);
}
COMMON_PORTABLE void cilkbug_assert_no_uncaught_exception(void)
{
bool uncaught = std::uncaught_exception();
CILK_ASSERT(!uncaught);
}
COMMON_SYSDEP void abort_because_rts_is_corrupted(void)
{
__cilkrts_bug("The Cilk Plus runtime system detected a corruption "
"in its data structures. This is most likely caused "
"by an application bug. Aborting execution.\n");
}
#ifdef WIN32
COMMON_SYSDEP void __cilkrts_dbgprintf(const char *fmt,...)
{
char message[2048];
va_list l;
// Cilkscreen shouldn't watch this
__cilkscreen_disable_checking();
va_start(l, fmt);
_vsnprintf_s(message, 2048, _TRUNCATE, fmt, l);
va_end(l);
OutputDebugStringA (message);
// Re-enable Cilkscreen
__cilkscreen_enable_checking();
}
#endif
__CILKRTS_END_EXTERN_C
/* End bug.cpp */
/* bug.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/**
* @file bug.h
*
* @brief Support for reporting bugs and debugging.
*/
#ifndef INCLUDED_BUG_DOT_H
#define INCLUDED_BUG_DOT_H
#include "rts-common.h"
#include <cilk/common.h>
__CILKRTS_BEGIN_EXTERN_C
/**
* Flush all output, write error message to stderr and abort the execution.
* On Windows the error is also written to the debugger.
*
* @param fmt printf-style format string. Any remaining parameters will be
* be interpreted based on the format string text.
*/
COMMON_PORTABLE NORETURN __cilkrts_bug(const char *fmt,...) cilk_nothrow;
#ifndef CILK_ASSERT
/** Standard text for failed assertion */
COMMON_PORTABLE extern const char *const __cilkrts_assertion_failed;
/**
* Macro to assert an invariant that must be true. If the statement evalutes
* to false, __cilkrts_bug will be called to report the failure and terminate
* the application.
*/
#define CILK_ASSERT(ex) \
(__builtin_expect((ex) != 0, 1) ? (void)0 : \
__cilkrts_bug(__cilkrts_assertion_failed, __FILE__, __LINE__, #ex))
#define CILK_ASSERT_MSG(ex, msg) \
(__builtin_expect((ex) != 0, 1) ? (void)0 : \
__cilkrts_bug(__cilkrts_assertion_failed, __FILE__, __LINE__, \
#ex "\n " msg))
#endif // CILK_ASSERT
/**
* Assert that there is no uncaught exception.
*
* Not valid on Windows or Android.
*
* On Android, calling std::uncaught_exception with the stlport library causes
* a seg fault. Since we're not supporting exceptions there at this point,
* just don't do the check. It works with the GNU STL library, but that's
* GPL V3 licensed.
*/
COMMON_PORTABLE void cilkbug_assert_no_uncaught_exception(void);
#if defined(_WIN32) || defined(ANDROID)
# define CILKBUG_ASSERT_NO_UNCAUGHT_EXCEPTION()
#else
# define CILKBUG_ASSERT_NO_UNCAUGHT_EXCEPTION() \
cilkbug_assert_no_uncaught_exception()
#endif
/**
* Call __cilkrts_bug with a standard message that the runtime state is
* corrupted and the application is being terminated.
*/
COMMON_SYSDEP void abort_because_rts_is_corrupted(void);
// Debugging aids
#ifndef _DEBUG
# define DBGPRINTF(_fmt, ...)
#elif defined(_WIN32)
/**
* Write debugging output. On windows this is written to the debugger.
*
* @param fmt printf-style format string. Any remaining parameters will be
* be interpreted based on the format string text.
*/
COMMON_SYSDEP void __cilkrts_dbgprintf(const char *fmt,...) cilk_nothrow;
/**
* Macro to write debugging output which will be elided if this is not a
* debug build. The macro is currently always elided on non-Windows builds.
*
* @param _fmt printf-style format string. Any remaining parameters will be
* be interpreted based on the format string text.
*/
# define DBGPRINTF(_fmt, ...) __cilkrts_dbgprintf(_fmt, __VA_ARGS__)
#else /* if _DEBUG && !_WIN32 */
/* Non-Windows debug logging. Someday we should make GetCurrentFiber()
* and GetWorkerFiber() do something.
*/
# include <stdio.h>
__CILKRTS_INLINE void* GetCurrentFiber() { return 0; }
__CILKRTS_INLINE void* GetWorkerFiber(__cilkrts_worker* w) { return 0; }
# define DBGPRINTF(_fmt, ...) fprintf(stderr, _fmt, __VA_ARGS__)
#endif // _DEBUG
__CILKRTS_END_EXTERN_C
#endif // ! defined(INCLUDED_BUG_DOT_H)
/* c_reducers.c -*-C-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2010-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************/
/* Implementation of C reducers */
// Disable warning about integer conversions losing significant bits.
// The code is correct as is.
#ifdef __INTEL_COMPILER
#pragma warning(disable:2259)
#endif
#define CILK_C_DEFINE_REDUCERS
#include <cilk/reducer_opadd.h>
#include <cilk/reducer_opand.h>
#include <cilk/reducer_opmul.h>
#include <cilk/reducer_opor.h>
#include <cilk/reducer_opxor.h>
#include <cilk/reducer_min_max.h>
/* End reducer_opadd.c */
/* cilk-abi-vla-internal.c -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/*
* These functions are provided in their own compilation unit so I can debug
* them. cilk-abi-vla.c must always be compiled with optimization on so that
* inlining occurs.
*/
#include "internal/abi.h"
#include "cilk-abi-vla-internal.h"
#include "bug.h"
#include "full_frame.h"
#include "local_state.h"
#include <stdlib.h>
#include <stdint.h>
#include "bug.h"
void *vla_internal_heap_alloc(__cilkrts_stack_frame *sf,
size_t full_size,
uint32_t align)
{
return malloc(full_size);
}
void vla_internal_heap_free(void *t, size_t size)
{
free(t);
}
void vla_free_from_original_stack(__cilkrts_stack_frame *sf,
size_t full_size)
{
// The __cilkrts_stack_frame must be initialized
CILK_ASSERT(sf->worker);
#if 1
// Add full_size to ff->sync_sp so that when we return, the VLA will no
// longer be allocated on the stack
__cilkrts_adjust_stack(sf->worker->l->frame_ff, full_size);
#else
// Inline __cilkrts_adjust_stack for Kevin
full_frame *ff = sf->worker->l->frame_ff;
ff->sync_sp = ff->sync_sp + full_size;
#endif
}
/* cilk-abi-vla-internal.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/**
* @file cilk-abi-vla-internal.h
*
* @brief Allocation/deallocation function for use with Variable Length
* Arrays in spawning functions.
*
* These should be the only functions in the Cilk runtime allocating memory
* from the standard C runtime heap. This memory will be provided to user
* code for use in VLAs, when the memory cannot be allocated from the stack.
*
* While these functions are simply passthroughs to malloc and free at the
* moment, once we've got the basics of VLA allocations working we'll make
* them do fancier tricks.
*/
/**
* @brief Allocate memory from the heap for use by a Variable Length Array in
* a spawning function.
*
* @param sf The __cilkrts_stack_frame for the spawning function containing
* the VLA.
* @param full_size The number of bytes to be allocated, including any tags
* needed to identify this as allocated from the heap.
* @param align Any alignment necessary for the allocation.
*/
void *vla_internal_heap_alloc(__cilkrts_stack_frame *sf,
size_t full_size,
uint32_t align);
/**
* @brief Deallocate memory from the heap used by a Variable Length Array in
* a spawning function.
*
* @param t The address of the memory block to be freed.
* @param size The size of the memory block to be freed.
*/
void vla_internal_heap_free(void *t,
size_t size);
/**
* @brief Deallocate memory from the original stack. We'll do this by adding
* full_size to ff->sync_sp. So after the sync, the Variable Length Array
* will no longer be allocated on the stack.
*
* @param sf The __cilkrts_stack_frame for the spawning function that is
* deallocating a VLA.
* @param full_size The size of the VLA, including any alignment and tags.
*/
void vla_free_from_original_stack(__cilkrts_stack_frame *sf,
size_t full_size);
/* cilk-ittnotify.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
#ifndef INCLUDED_CILK_ITTNOTIFY_DOT_H
#define INCLUDED_CILK_ITTNOTIFY_DOT_H
#ifdef __INTEL_COMPILER
#endif
#include <stdio.h>
// ITTNOTIFY does not support ARM at this time
#ifdef __arm__
#undef USE_ITTNOTIFY
#endif
#ifdef USE_ITTNOTIFY
#include <ittnotify.h>
#ifdef _WIN32
# define ITT_SYNC_CREATE(_address, _description) \
__itt_sync_createA(_address, \
"Intel Cilk Plus " _description, \
"", \
__itt_attr_barrier)
#else
# define ITT_SYNC_CREATE(_address, _description) \
__itt_sync_create(_address, \
"Intel Cilk Plus " _description, \
"", \
__itt_attr_barrier)
#endif
#define ITT_SYNC_PREPARE(_address) __itt_sync_prepare(_address)
#define ITT_SYNC_ACQUIRED(_address) __itt_sync_acquired(_address)
#define ITT_SYNC_RELEASING(_address) __itt_sync_releasing(_address)
#define ITT_SYNC_DESTROY(_address) __itt_sync_destroy(_address)
// Note that we subtract 5 from the return address to find the CALL instruction
// to __cilkrts_sync
#if 1 // Disable renaming for now. Piersol isn't ready yet
#define ITT_SYNC_SET_NAME_AND_PREPARE(_address, _sync_ret_address) __itt_sync_prepare(_address)
#else
#define ITT_SYNC_SET_NAME_AND_PREPARE(_address, _sync_ret_address) \
if (NULL != __itt_sync_prepare_ptr) { \
if (0 == _sync_ret_address) \
__itt_sync_renameA(_address, ""); \
else \
{ \
char buf[128]; \
sprintf_s(buf, 128, "IP:0x%p", (DWORD_PTR)_sync_ret_address - 5); \
__itt_sync_renameA(_address, buf); \
_sync_ret_address = 0; \
} \
__itt_sync_prepare(_address); \
}
#endif
#else // USE_ITTNOTIFY not defined, compile out all calls
#define ITT_SYNC_CREATE(_address, _description)
#define ITT_SYNC_PREPARE(_address)
#define ITT_SYNC_ACQUIRED(_address)
#define ITT_SYNC_RELEASING(_addresss)
#define ITT_SYNC_DESTROY(_address)
#define ITT_SYNC_SET_NAME_AND_PREPARE(_sync_address, _wait_address)
#endif
#endif // ! defined(INCLUDED_CILK_ITTNOTIFY_DOT_H)
/* cilk-tbb-interop.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/**
* @file cilk-tbb-interop.h
*
* @brief Interface between TBB and Cilk to allow TBB to associate it's
* per-thread data with Cilk workers, and maintain the association as work
* moves between worker threads. This handles the case where TBB calls
* into a Cilk function which may later call back to a function making
* TBB calls.
*
* Each thunk structure has two pointers: \"routine\" and \"data\".
* The caller of the thunk invokes *routine, passing \"data\" as the void*
* parameter.
*/
#ifndef INCLUDED_CILK_TBB_INTEROP_DOT_H
#define INCLUDED_CILK_TBB_INTEROP_DOT_H
#include <cilk/common.h> // for CILK_EXPORT
__CILKRTS_BEGIN_EXTERN_C
/** A return code. 0 indicates success. */
typedef int __cilk_tbb_retcode;
/**
* Enumeration of reasons that Cilk will call the TBB stack operation
* function.
*
* When a non-empty stack is transfered between threads, the first thread must
* orphan it and the second thread must adopt it.
*
* An empty stack can be transfered similarly, or simply released by the first
* thread.
*
* Here is a summary of the actions as transitions on a state machine.
@verbatim
watch ORPHAN
-->--> -->--
/ \ / \
(freed empty stack) (TBB sees stack running on thread) (stack in limbo)
\ / \ /
--<-- --<--
RELEASE or ADOPT
unwatch
@endverbatim
*/
typedef enum __cilk_tbb_stack_op {
/**
* Disconnecting stack from a thread.
*
* The thunk must be invoked on the thread disconnecting itself from the
* stack. Must \"happen before\" the stack is adopted elsewhere.
*/
CILK_TBB_STACK_ORPHAN,
/**
* Reconnecting orphaned stack to a thread.
*
* The thunk must be invoked on the thread adopting the stack.
*/
CILK_TBB_STACK_ADOPT,
/**
* Releasing stack.
*
* The thunk must be invoked on the thread doing the releasing, Must
* \"happen before\" the stack is used elsewhere.
*/
CILK_TBB_STACK_RELEASE
} __cilk_tbb_stack_op;
/**
* Function that will be called by the Cilk runtime to inform TBB of a change
* in the stack associated with the current thread.
*
* It does not matter what stack the thunk runs on.
* The thread (not fiber) on which the thunk runs is important.
*
* @param op Enumerated value indicating what type of change is ocurring.
* @param data Context value provided by TBB in the __cilkrts_watch_stack
* call. This data is opaque to Cilk.
*
* @return 0 indicates success.
*/
typedef __cilk_tbb_retcode (*__cilk_tbb_pfn_stack_op)(enum __cilk_tbb_stack_op op,
void* data);
/**
* Function that will be called by TBB to inform the Cilk runtime that TBB
* is no longer interested in watching the stack bound to the current thread.
*
* @param data Context value provided to TBB by the __cilkrts_watch_stack
* call. This data is opaque to TBB.
*
* @return 0 indicates success.
*/
typedef __cilk_tbb_retcode (*__cilk_tbb_pfn_unwatch_stacks)(void *data);
/**
* Thunk invoked by Cilk to call back to TBB to tell it about a change in
* the stack bound to the current thread.
*/
typedef struct __cilk_tbb_stack_op_thunk {
/// Function in TBB the Cilk runtime should call when something
// "interesting" happens involving a stack
__cilk_tbb_pfn_stack_op routine;
/// TBB context data to pass with the call to the stack_op routine
void* data;
} __cilk_tbb_stack_op_thunk;
/**
* Thunk invoked by TBB when it is no longer interested in watching the stack
* bound to the current thread.
*/
typedef struct __cilk_tbb_unwatch_thunk {
/// Function in Cilk runtime to call when TBB no longer wants to watch
// stacks
__cilk_tbb_pfn_unwatch_stacks routine;
/// Cilk runtime context data to pass with the call to the unwatch_stacks
/// routine
void* data;
} __cilk_tbb_unwatch_thunk;
/**
* Requests that Cilk invoke __cilk_tbb_orphan_thunk when it orphans a stack.
* Cilk sets *u to a thunk that TBB should call when it is no longer
* interested in watching the stack.
*
* If the thread is not yet bound to the Cilk runtime, the Cilk runtime should
* save this data in thread-local storage until __cilkrts_bind_thread is called.
*
* Called by TBB, defined by Cilk. This function is exported from the Cilk
* runtime DLL/shared object. This declaration also appears in
* cilk/cilk_undocumented.h -- don't change one declaration without also
* changing the other.
*
* @param u __cilk_tbb_unwatch_thunk. This structure will be filled in by
* the Cilk runtime to allow TBB to register that it is no longer interested
* in watching the stack bound to the current thread.
* @param o __cilk_tbb_stack_op_thunk. This structure specifies the routine
* that the Cilk runtime should call when an "interesting" change in the stack
* associate with the current worker occurs.
*
* @return 0 indicates success.
*/
CILK_EXPORT
__cilk_tbb_retcode __cilkrts_watch_stack(__cilk_tbb_unwatch_thunk* u,
__cilk_tbb_stack_op_thunk o);
__CILKRTS_END_EXTERN_C
#endif // ! defined(INCLUDED_CILK_TBB_INTEROP_DOT_H)
/* cilk_api.c -*-C-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/*
* Implementation of functions declared in cilk_api.h
*/
/*
* Define the COMPILING_CILK_ABI_FUNCTIONS macro, so that
* compilation of this file generates non-inlined definitions for the
* functions marked as CILK_EXPORT_AND_INLINE in cilk_api.h.
*
* We must deal with these functions differently because we need to
* continue to ship nonlined versions of these functions.
*
* CILK_EXPORT_AND_INLINE int __cilkrts_get_worker_rank(uint64_t *rank);
* CILK_EXPORT_AND_INLINE int __cilkrts_bump_worker_rank();
* CILK_EXPORT_AND_INLINE int __cilkrts_bump_loop_rank();
*/
#define COMPILING_CILK_API_FUNCTIONS
#include <internal/abi.h>
#include <cilk/cilk_api.h>
#include "os.h"
#include "os_mutex.h"
#include "bug.h"
#include "global_state.h"
#include "local_state.h"
#include "scheduler.h"
#include "sysdep.h"
CILK_API_VOID __cilkrts_init(void)
{
// Initialize, but don't start, the cilk runtime.
__cilkrts_init_internal(0);
}
CILK_API_VOID __cilkrts_end_cilk(void)
{
// Take out the global OS mutex while we do this to protect against
// another thread attempting to bind while we do this
global_os_mutex_lock();
if (cilkg_is_published()) {
global_state_t *g = cilkg_get_global_state();
if (g->Q || __cilkrts_get_tls_worker())
__cilkrts_bug("Attempt to shut down Cilk while Cilk is still "
"running");
__cilkrts_stop_workers(g);
__cilkrts_deinit_internal(g);
}
global_os_mutex_unlock();
}
CILK_API_INT
__cilkrts_get_nworkers()
{
return cilkg_get_nworkers();
}
CILK_API_INT
__cilkrts_get_total_workers()
{
return cilkg_get_total_workers();
}
CILK_API_INT __cilkrts_get_force_reduce(void)
{
return cilkg_get_force_reduce();
}
CILK_API_INT __cilkrts_set_param(const char* param, const char* value)
{
return cilkg_set_param(param, value);
}
#ifdef _WIN32
CILK_API_INT __cilkrts_set_param_w(const wchar_t* param, const wchar_t* value)
{
return cilkg_set_param_w(param, value);
}
#endif // _WIN32
/* Return a small integer indicating which Cilk worker the function is
* currently running on. Each thread started by the Cilk runtime library
* (system worker) has a unique worker number in the range 1..P-1, where P is
* the valued returned by __cilkrts_get_nworkers(). All threads started by
* the user or by other libraries (user workers) share the worker number 0.
* Therefore, the worker number is not unique across multiple user threads.
*
* Implementor's note: The value returned from this function is different from
* the value, w->self, used in most debug messages.
*/
CILK_API_INT
__cilkrts_get_worker_number(void)
{
__cilkrts_worker *w = __cilkrts_get_tls_worker();
if (0 == w)
/* A non-worker always has a worker number of zero. */
return 0;
else if (WORKER_USER == w->l->type)
/* User worker was once a non-worker, so its number should still be
* zero. */
return 0;
else
/* w->self for a system worker is in range 0..(P-1); adjust to 1..P
* to avoid conflicting with the user thread's worker number. */
return w->self + 1;
}
/**
* Internal definition of the pedigree context. The size of the
* structure must match __cilkrts_pedigree_context_t defined in abi.i
*/
typedef struct pedigree_context_t
{
/** Size of the structure, in bytes */
size_t size;
/** Next __cilkrts_pedigree to return */
const __cilkrts_pedigree *pedigree;
/** Unused. Left over from previous implementation */
void *unused1;
/** Unused. Left over from previous implementation */
void *unused2;
// // Debugging aid for pedigree-test:
// __cilkrts_stack_frame *expected_sf;
} pedigree_context_t;
/*
* __cilkrts_get_pedigree_info
*
* Fetch the birthrank for a stack frame. To initialize the walk, both sf_in
* and frame_in should be NULL. parent_sf_ptr and parent_frame_ptr provide
* context for the stackwalk and should be returned as sf_in and frame_in on
* the next call.
*
* Returns:
* 0 - Success - birthrank, parent_sf_out and parent_frame_out are valid
* >1 - Pedigree walk completed
* <1 - Failure - -1: No worker bound to thread, -2: Sanity check failed
*/
#define PEDIGREE_WALK_COMPLETE (__cilkrts_pedigree *)-1
CILK_API_INT
__cilkrts_get_pedigree_info(__cilkrts_pedigree_context_t *external_context,
uint64_t *sf_birthrank)
{
pedigree_context_t *context = (pedigree_context_t *)external_context;
CILK_ASSERT(sizeof(__cilkrts_pedigree_context_t) ==
sizeof(pedigree_context_t));
if (context->size != sizeof(pedigree_context_t))
return -3; // Invalid size
// If the pointer to the last __cilkrts_pedigree is -1, we've
// finished the walk. We're still done.
if (PEDIGREE_WALK_COMPLETE == context->pedigree)
return 1;
// The passed in context value contains a pointer to the last
// __cilkrts_pedigree returned, or NULL if we're starting a
// new walk
if (NULL == context->pedigree)
{
__cilkrts_worker *w = __cilkrts_get_tls_worker();
__cilkrts_pedigree* pedigree_node;
if (NULL != w) {
pedigree_node = &w->pedigree;
}
else {
pedigree_node = __cilkrts_get_tls_pedigree_leaf(1);
}
context->pedigree = pedigree_node->parent;
}
else
context->pedigree = context->pedigree->parent;
// Note: If we want to omit the user root node,
// stop at context->pedigree->parent instead.
if (NULL == context->pedigree)
{
context->pedigree = PEDIGREE_WALK_COMPLETE;
return 1;
}
*sf_birthrank = context->pedigree->rank;
return 0;
}
CILK_API_PEDIGREE
__cilkrts_get_pedigree_internal(__cilkrts_worker *w)
{
if (NULL != w) {
return w->pedigree;
}
else {
const __cilkrts_pedigree *pedigree =
__cilkrts_get_tls_pedigree_leaf(1);
return *pedigree;
}
}
CILK_API_INT __cilkrts_bump_worker_rank_internal(__cilkrts_worker *w)
{
__cilkrts_pedigree *pedigree;
pedigree = (w ? &w->pedigree : __cilkrts_get_tls_pedigree_leaf(1));
pedigree->rank++;
return 0;
}
/* End cilk_api.c */
/* cilk_fiber-unix.cpp -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2012-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
#include "cilk_fiber-unix.h"
#include "cilk_malloc.h"
#include "bug.h"
#include "os.h"
#include <cstdio>
#include <cstdlib>
#include <alloca.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>
// MAP_ANON is deprecated on Linux, but seems to be required on Mac...
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
// Magic number for sanity checking fiber structure
const unsigned magic_number = 0x5afef00d;
int cilk_fiber_sysdep::s_page_size = getpagesize();
cilk_fiber_sysdep::cilk_fiber_sysdep(std::size_t stack_size)
: cilk_fiber(stack_size)
, m_magic(magic_number)
{
// Set m_stack and m_stack_base.
make_stack(stack_size);
// Get high-address of stack, with 32-bytes of spare space, and rounded
// down to the nearest 32-byte boundary.
const uintptr_t align_mask = 32 - 1;
m_stack_base -= ((std::size_t) m_stack_base) & align_mask;
}
cilk_fiber_sysdep::cilk_fiber_sysdep(from_thread_t)
: cilk_fiber()
, m_magic(magic_number)
{
this->set_allocated_from_thread(true);
// Dummy stack data for thread-main fiber
m_stack = NULL;
m_stack_base = NULL;
}
void cilk_fiber_sysdep::convert_fiber_back_to_thread()
{
// Does nothing on Linux.
}
cilk_fiber_sysdep::~cilk_fiber_sysdep()
{
CILK_ASSERT(magic_number == m_magic);
if (!this->is_allocated_from_thread())
free_stack();
}
#if SUPPORT_GET_CURRENT_FIBER
cilk_fiber_sysdep* cilk_fiber_sysdep::get_current_fiber_sysdep()
{
return cilkos_get_tls_cilk_fiber();
}
#endif
// Jump to resume other fiber. We may or may not come back.
inline void cilk_fiber_sysdep::resume_other_sysdep(cilk_fiber_sysdep* other)
{
if (other->is_resumable()) {
other->set_resumable(false);
// Resume by longjmp'ing to the place where we suspended.
CILK_LONGJMP(other->m_resume_jmpbuf);
}
else {
// Otherwise, we've never ran this fiber before. Start the
// proc method.
other->run();
}
}
void cilk_fiber_sysdep::suspend_self_and_resume_other_sysdep(cilk_fiber_sysdep* other)
{
#if SUPPORT_GET_CURRENT_FIBER
cilkos_set_tls_cilk_fiber(other);
#endif
CILK_ASSERT(this->is_resumable());
// Jump to the other fiber. We expect to come back.
if (! CILK_SETJMP(m_resume_jmpbuf)) {
resume_other_sysdep(other);
}
// Return here when another fiber resumes me.
// If the fiber that switched to me wants to be deallocated, do it now.
do_post_switch_actions();
}
NORETURN cilk_fiber_sysdep::jump_to_resume_other_sysdep(cilk_fiber_sysdep* other)
{
#if SUPPORT_GET_CURRENT_FIBER
cilkos_set_tls_cilk_fiber(other);
#endif
CILK_ASSERT(!this->is_resumable());
// Jump to the other fiber. But we are never coming back because
// this fiber is being reset.
resume_other_sysdep(other);
// We should never come back here...
__cilkrts_bug("Should not get here");
}
NORETURN cilk_fiber_sysdep::run()
{
// Only fibers created from a pool have a proc method to run and execute.
CILK_ASSERT(m_start_proc);
CILK_ASSERT(!this->is_allocated_from_thread());
CILK_ASSERT(!this->is_resumable());
// TBD: This setjmp/longjmp pair simply changes the stack pointer.
// We could probably replace this code with some assembly.
if (! CILK_SETJMP(m_resume_jmpbuf))
{
// Calculate the size of the current stack frame (i.e., this
// run() function.
size_t frame_size = (size_t)JMPBUF_FP(m_resume_jmpbuf) - (size_t)JMPBUF_SP(m_resume_jmpbuf);
// Macs require 16-byte alignment. Do it always because it just
// doesn't matter
if (frame_size & (16-1))
frame_size += 16 - (frame_size & (16-1));
// Assert that we are getting a reasonable frame size out of
// it. If this run() function is using more than 4096 bytes
// of space for its local variables / any state that spills to
// registers, something is probably *very* wrong here...
//
// 4096 bytes just happens to be a number that seems "large
// enough" --- for an example GCC 32-bit compilation, the
// frame size was 48 bytes.
CILK_ASSERT(frame_size < 4096);
// Change stack pointer to fiber stack. Offset the
// calculation by the frame size, so that we've allocated
// enough extra space from the top of the stack we are
// switching to for any temporaries required for this run()
// function.
JMPBUF_SP(m_resume_jmpbuf) = m_stack_base - frame_size;
CILK_LONGJMP(m_resume_jmpbuf);
}
// Note: our resetting of the stack pointer is valid only if the
// compiler has not saved any temporaries onto the stack for this
// function before the longjmp that we still care about at this
// point.
// Verify that 1) 'this' is still valid and 2) '*this' has not been
// corrupted.
CILK_ASSERT(magic_number == m_magic);
// If the fiber that switched to me wants to be deallocated, do it now.
do_post_switch_actions();
// Now call the user proc on the new stack
m_start_proc(this);
// alloca() to force generation of frame pointer. The argument to alloca
// is contrived to prevent the compiler from optimizing it away. This
// code should never actually be executed.
int* dummy = (int*) alloca((sizeof(int) + (std::size_t) m_start_proc) & 0x1);
*dummy = 0xface;
// User proc should never return.
__cilkrts_bug("Should not get here");
}
void cilk_fiber_sysdep::make_stack(size_t stack_size)
{
char* p;
// We've already validated that the stack size is page-aligned and
// is a reasonable value. No need to do any extra rounding here.
size_t rounded_stack_size = stack_size;
// Normally, we have already validated that the stack size is
// aligned to 4K. In the rare case that pages are huge though, we
// need to do some extra checks.
if (rounded_stack_size < 3 * (size_t)s_page_size) {
// If the specified stack size is too small, round up to 3
// pages. We need at least 2 extra for the guard pages.
rounded_stack_size = 3 * (size_t)s_page_size;
}
else {
// Otherwise, the stack size is large enough, but might not be
// a multiple of page size. Round up to nearest multiple of
// s_page_size, just to be safe.
size_t remainder = rounded_stack_size % s_page_size;
if (remainder) {
rounded_stack_size += s_page_size - remainder;
}
}
p = (char*)mmap(0, rounded_stack_size,
PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0);
if (MAP_FAILED == p) {
// For whatever reason (probably ran out of memory), mmap() failed.
// There is no stack to return, so the program loses parallelism.
m_stack = NULL;
m_stack_base = NULL;
return;
}
// mprotect guard pages.
mprotect(p + rounded_stack_size - s_page_size, s_page_size, PROT_NONE);
mprotect(p, s_page_size, PROT_NONE);
m_stack = p;
m_stack_base = p + rounded_stack_size - s_page_size;
}
void cilk_fiber_sysdep::free_stack()
{
if (m_stack) {
size_t rounded_stack_size = m_stack_base - m_stack + s_page_size;
if (munmap(m_stack, rounded_stack_size) < 0)
__cilkrts_bug("Cilk: stack munmap failed error %d\n", errno);
}
}
/* End cilk_fiber-unix.cpp */
/* cilk_fiber-unix.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2012-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
#ifndef INCLUDED_CILK_FIBER_UNIX_DOT_H
#define INCLUDED_CILK_FIBER_UNIX_DOT_H
#ifndef __cplusplus
# error cilk_fiber-unix.h is a C++-only header
#endif
#include "cilk_fiber.h"
#include "jmpbuf.h"
/**
* @file cilk_fiber-unix.h
*
* @brief Unix-specific implementation for cilk_fiber.
*/
/**
* @brief Unix-specific fiber class derived from portable fiber class
*/
struct cilk_fiber_sysdep : public cilk_fiber
{
public:
#if SUPPORT_GET_CURRENT_FIBER
/**
* @brief Gets the current fiber from TLS.
*/
static cilk_fiber_sysdep* get_current_fiber_sysdep();
#endif
/**
* @brief Construct the system-dependent portion of a fiber.
*
* @param stack_size The size of the stack for this fiber.
*/
cilk_fiber_sysdep(std::size_t stack_size);
/**
* @brief Construct the system-dependent of a fiber created from a
* thread.
*/
cilk_fiber_sysdep(from_thread_t);
/**
* @brief Destructor
*/
~cilk_fiber_sysdep();
/**
* @brief OS-specific calls to convert this fiber back to thread.
*
* Nothing to do for Linux.
*/
void convert_fiber_back_to_thread();
/**
* @brief System-dependent function to suspend self and resume execution of "other".
*
* This fiber is suspended.
*
* @pre @c is_resumable() should be true.
*
* @param other Fiber to resume.
*/
void suspend_self_and_resume_other_sysdep(cilk_fiber_sysdep* other);
/**
* @brief System-dependent function called to jump to @p other
* fiber.
*
* @pre @c is_resumable() should be false.
*
* @param other Fiber to resume.
*/
NORETURN jump_to_resume_other_sysdep(cilk_fiber_sysdep* other);
/**
* @brief Runs the start_proc.
* @pre is_resumable() should be false.
* @pre is_allocated_from_thread() should be false.
* @pre m_start_proc must be valid.
*/
NORETURN run();
/**
* @brief Returns the base of this fiber's stack.
*/
inline char* get_stack_base_sysdep() { return m_stack_base; }
private:
char* m_stack_base; ///< The base of this fiber's stack.
char* m_stack; // Stack memory (low address)
__CILK_JUMP_BUFFER m_resume_jmpbuf; // Place to resume fiber
unsigned m_magic; // Magic number for checking
static int s_page_size; // Page size for
// stacks.
// Allocate memory for a stack. This method
// initializes m_stack and m_stack_base.
void make_stack(size_t stack_size);
// Deallocates memory for the stack.
void free_stack();
// Common helper method for implementation of resume_other_sysdep
// variants.
inline void resume_other_sysdep(cilk_fiber_sysdep* other);
};
#endif // ! defined(INCLUDED_CILK_FIBER_UNIX_DOT_H)
/* cilk_malloc.c -*-C-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
#include "cilk_malloc.h"
#include <stdlib.h>
#if defined _WIN32 || defined _WIN64 || defined __linux__
#include <malloc.h>
#define HAS_MEMALIGN 1
#endif
#ifdef __VXWORKS__
#define HAS_MEMALIGN 1
#include <memLib.h>
#endif
#define PREFERRED_ALIGNMENT 64 /* try to keep runtime system data
structures within one cache line */
void *__cilkrts_malloc(size_t size)
{
/* TODO: check for out of memory */
#ifdef _WIN32
return _aligned_malloc(size, PREFERRED_ALIGNMENT);
#elif defined HAS_MEMALIGN
return memalign(PREFERRED_ALIGNMENT, size);
#else
return malloc(size);
#endif
}
void *__cilkrts_realloc(void *ptr, size_t size)
{
#ifdef _WIN32
return _aligned_realloc(ptr, size, PREFERRED_ALIGNMENT);
#else
return realloc(ptr, size);
#endif
}
void __cilkrts_free(void *ptr)
{
#ifdef _WIN32
_aligned_free(ptr);
#else
free(ptr);
#endif
}
/* End cilk_malloc.c */
/* cilk_malloc.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/**
* @file cilk_malloc.h
*
* @brief Provides replacement memory allocation functions to allocate
* (and free) memory on cache line boundaries, if supported by the OS.
*
* If aligned memory functions are not provided by the OS, the calls just
* pass through to the standard memory allocation functions.
*/
#ifndef INCLUDED_CILK_MALLOC_DOT_H
#define INCLUDED_CILK_MALLOC_DOT_H
#include <cilk/common.h>
#include <stddef.h>
#include "rts-common.h"
__CILKRTS_BEGIN_EXTERN_C
/**
* malloc replacement function to allocate memory aligned on a cache line
* boundary if aligned memory allocations are supported by the OS.
*
* @param size Number of bytes to allocate.
*
* @return pointer to memory block allocated, or NULL if unsuccessful.
*/
COMMON_PORTABLE void *__cilkrts_malloc(size_t size);
/**
* realloc replacement function to allocate memory aligned on a cache line
* boundary if aligned memory allocations are supported by the OS.
*
* @param ptr Block to be reallocated.
* @param size Number of bytes to allocate.
*
* @return pointer to memory block allocated, or NULL if unsuccessful.
*/
COMMON_PORTABLE void *__cilkrts_realloc(void *ptr, size_t size);
/**
* free replacement function to deallocate memory aligned on a cache line
* boundary if aligned memory allocations are supported by the OS.
*
* @param ptr Block to be freed.
*/
COMMON_PORTABLE void __cilkrts_free(void *ptr);
__CILKRTS_END_EXTERN_C
#endif // ! defined(INCLUDED_CILK_MALLOC_DOT_H)
/* component.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
#ifndef INCLUDED_COMPONENT_DOT_H
#define INCLUDED_COMPONENT_DOT_H
#define COMPONENT_NAME "Intel® Cilk™ Plus Runtime"
#define COMPONENT_INTERNAL_NAME COMPONENT_NAME
#define COMPONENT_FILENAME "CILKRTS20"
#define BuildVersionString(_major, _minor, _build, _rev) #_major "," #_minor "," #_build "," #_rev
#define COMPONENT_VERSION_STRING BuildVersionString (VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION)
#endif // ! defined(INCLUDED_COMPONENT_DOT_H)
/* cilk-abi-vla.cpp -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************/
/*
* Implementation of Variable Length Array (VLA) ABI.
*
* The compiler calls these functions to allocate Variable Length Arrays
* at runtime. The compiler must guarantee that __cilkrts_stack_free() is
* called to cleanup any memory allocated by __cilkrts_stack_alloc().
*
* This generic implementation always allocates the memory from the heap.
* Optimally, the implementation should expand the frame of the calling
* function if possible, since that will be faster. See the x86 version
* for one possible implementation.
*/
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include "internal/abi.h"
#include "cilk-abi-vla-internal.h"
#define c_cilk_ptr_from_heap 0xc2f2f00d
#define c_cilk_ptr_from_stack 0xc3f30d0f
// Allocate space for a variable length array
CILK_ABI(__cilkrts_void_ptr)
__cilkrts_stack_alloc(
__cilkrts_stack_frame *sf,
size_t size,
size_t distance_from_sp_to_alloca_area,
uint32_t align, // align is always >= minimum stack alignment and
// >= ptr_size as well, and must be a power of 2.
uint32_t needs_tag // non-zero if the pointer being returned needs to
// be tagged
)
{
// full_size will be a multiple of align, and contains
// enough extra space to allocate a marker.
size_t full_size = (size + align - 1) & ~(align - 1);
// Allocate memory from the heap. The compiler is responsible
// for guaranteeing us a chance to free it before the function
// exits
return (void *)vla_internal_heap_alloc(sf, full_size, align);
}
// Free the space allocated for a variable length array.
CILK_ABI(void)
__cilkrts_stack_free(
__cilkrts_stack_frame *sf,
void *p,
size_t size,
size_t distance_from_sp_to_alloca_area,
uint32_t align, // same requirements as for align in allocation,
// and must match alignment that was passed when
// doing the allocation
uint32_t known_from_stack // non-zero if this is known to be allocated
// on the stack, and therefore has no tag
)
{
// full_size will be a multiple of align, and contains
// enough extra space to allocate a marker if one was needed.
size_t full_size = (size + align - 1) & ~(align - 1);
// Just free the allocated memory to the heap since we don't know
// how to expand/contract the calling frame
vla_internal_heap_free(t, full_size);
}
/* os.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/*
* void __cilkrts_fence(void)
*
* Executes an MFENCE instruction to serialize all load and store instructions
* that were issued prior the MFENCE instruction. This serializing operation
* guarantees that every load and store instruction that precedes the MFENCE
* instruction is globally visible before any load or store instruction that
* follows the MFENCE instruction. The MFENCE instruction is ordered with
* respect to all load and store instructions, other MFENCE instructions, any
* SFENCE and LFENCE instructions, and any serializing instructions (such as
* the CPUID instruction).
*/
COMMON_SYSDEP void __cilkrts_fence(void); ///< MFENCE instruction
/* os-unix-sysdep.c -*-C-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*************************************************************************
*
* This file contains generic implementations of system-specific code for
* Unix-based systems
*/
#include "os.h"
#include "sysdep.h"
/*
* The cycle counter is used for debugging. This funciton is only called if
* CILK_PROFILE is defined when the runtime is built.
*/
COMMON_SYSDEP unsigned long long __cilkrts_getticks(void)
{
# warning "unimplemented cycle counter"
return 0;
}
/*
* A "short pause" - called from the Cilk runtime's spinloops.
*/
COMMON_SYSDEP void __cilkrts_short_pause(void)
{
# warning __cilkrts_short_pause empty
}
/*
* Interlocked exchange - used to implement the Cilk runtime's spinloops
*/
COMMON_SYSDEP int __cilkrts_xchg(volatile int *ptr, int x)
{
x = __sync_lock_test_and_set(ptr, x);
return x;
}
/*
* Restore the floating point state that is stored in a stack frame at each
* spawn. This should be called each time a frame is resumed.
*
* Only valid for IA32 and Intel64 processors.
*/
void restore_x86_fp_state (__cilkrts_stack_frame *sf)
{
}
/*
* Save the floating point state to the __cilkrts_stack_frame at each spawn.
*
* Architecture-specific - Should only be needed on IA32 and Intel64
* processors.
*/
void sysdep_save_fp_ctrl_state(__cilkrts_stack_frame *sf)
{
}
/* os.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/* gcc before 4.4 does not implement __sync_synchronize properly */
#if (__ICC >= 1110 && !(__MIC__ || __MIC2__)) \
|| (!defined __ICC && __GNUC__ * 10 + __GNUC_MINOR__ > 43)
# define HAVE_SYNC_INTRINSICS 1
#endif
/*
* void __cilkrts_fence(void)
*
* Executes an MFENCE instruction to serialize all load and store instructions
* that were issued prior the MFENCE instruction. This serializing operation
* guarantees that every load and store instruction that precedes the MFENCE
* instruction is globally visible before any load or store instruction that
* follows the MFENCE instruction. The MFENCE instruction is ordered with
* respect to all load and store instructions, other MFENCE instructions, any
* SFENCE and LFENCE instructions, and any serializing instructions (such as
* the CPUID instruction).
*/
#ifdef HAVE_SYNC_INTRINSICS
# define __cilkrts_fence() __sync_synchronize()
#elif defined __ICC || defined __GNUC__
/* mfence is a strict subset of lock add but takes longer on many
* processors. */
// # define __cilkrts_fence() __asm__ volatile ("mfence")
/* On MIC, fence seems to be completely unnecessary.
* Just for simplicity of 1st implementation, it defaults to x86 */
# define __cilkrts_fence() __asm__ volatile ("lock addl $0,(%rsp)")
// #elif defined _WIN32
// # pragma intrinsic(_ReadWriteBarrier)
// # define __cilkrts_fence() _ReadWriteBarrier()
#else
COMMON_SYSDEP void __cilkrts_fence(void); ///< MFENCE instruction
#endif
/* os-unix-sysdep.c -*-C-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*************************************************************************
*
* This file contains system-specific code for Unix systems
*/
#include "os.h"
#include "sysdep.h"
#include <internal/abi.h>
// On x86 processors (but not MIC processors), the compiler generated code to
// save the FP state (rounding mode and the like) before calling setjmp. We
// will need to restore that state when we resume.
#ifndef __MIC__
# if defined(__i386__) || defined(__x86_64)
# define RESTORE_X86_FP_STATE
# endif // defined(__i386__) || defined(__x86_64)
#endif // __MIC__
/* timer support */
COMMON_SYSDEP unsigned long long __cilkrts_getticks(void)
{
#if defined __i386__ || defined __x86_64
unsigned a, d;
__asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
return ((unsigned long long)a) | (((unsigned long long)d) << 32);
#else
# warning "unimplemented cycle counter"
return 0;
#endif
}
COMMON_SYSDEP void __cilkrts_short_pause(void)
{
#if __ICC >= 1110
# if __MIC__ || __MIC2__
_mm_delay_32(16); // stall for 16 cycles
# else
_mm_pause();
# endif
#elif defined __i386__ || defined __x86_64
__asm__("pause");
#else
# warning __cilkrts_short_pause empty
#endif
}
COMMON_SYSDEP int __cilkrts_xchg(volatile int *ptr, int x)
{
#if defined __i386__ || defined __x86_64
/* asm statement here works around icc bugs */
__asm__("xchgl %0,%a1" :"=r" (x) : "r" (ptr), "0" (x) :"memory");
#else
x = __sync_lock_test_and_set(ptr, x);
#endif
return x;
}
/*
* Restore the floating point state that is stored in a stack frame at each
* spawn. This should be called each time a frame is resumed.
*
* Only valid for IA32 and Intel64 processors.
*/
void restore_x86_fp_state (__cilkrts_stack_frame *sf) {
#ifdef RESTORE_X86_FP_STATE
__asm__ ( "ldmxcsr %0\n\t"
"fnclex\n\t"
"fldcw %1"
:
: "m" (sf->mxcsr), "m" (sf->fpcsr));
#endif
}
void sysdep_save_fp_ctrl_state(__cilkrts_stack_frame *sf)
{
// If we're not going to restore, don't bother saving it
#ifdef RESTORE_X86_FP_STATE
if (CILK_FRAME_VERSION_VALUE(sf->flags) >= 1)
{
__asm__ ("stmxcsr %0" : "=m" (sf->mxcsr));
__asm__ ("fnstsw %0" : "=m" (sf->fpcsr));
}
#endif
}
<doxygenlayout version="1.0">
<!--
# @copyright
# Copyright (C) 2011-2013, Intel Corporation
# All rights reserved.
#
# @copyright
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# @copyright
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-->
<!-- Navigation index tabs for HTML output -->
<navindex>
<tab type="mainpage" visible="yes" title=""/>
<tab type="pages" visible="yes" title="" intro=""/>
<tab type="modules" visible="yes" title="" intro=""/>
<tab type="namespaces" visible="yes" title="">
<tab type="namespaces" visible="yes" title="" intro=""/>
<tab type="namespacemembers" visible="yes" title="" intro=""/>
</tab>
<tab type="classes" visible="yes" title="Classes, Structs and Unions">
<tab type="classes" visible="yes" title="Classes, Structs and Unions" intro=""/>
<tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
<tab type="hierarchy" visible="yes" title="" intro=""/>
<tab type="classmembers" visible="yes" title="" intro=""/>
</tab>
<tab type="files" visible="yes" title="">
<tab type="files" visible="yes" title="" intro=""/>
<tab type="globals" visible="yes" title="" intro=""/>
</tab>
<tab type="globals" visible="yes" title="Global Functions" intro=""/>
<tab type="dirs" visible="yes" title="" intro=""/>
<tab type="examples" visible="yes" title="" intro=""/>
</navindex>
<!-- Layout definition for a class page -->
<class>
<briefdescription visible="yes"/>
<includes visible="$SHOW_INCLUDE_FILES"/>
<inheritancegraph visible="$CLASS_GRAPH"/>
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
<allmemberslink visible="yes"/>
<memberdecl>
<nestedclasses visible="yes" title=""/>
<publictypes title=""/>
<publicslots title=""/>
<signals title=""/>
<publicmethods title=""/>
<publicstaticmethods title=""/>
<publicattributes title=""/>
<publicstaticattributes title=""/>
<protectedtypes title=""/>
<protectedslots title=""/>
<protectedmethods title=""/>
<protectedstaticmethods title=""/>
<protectedattributes title=""/>
<protectedstaticattributes title=""/>
<packagetypes title=""/>
<packagemethods title=""/>
<packagestaticmethods title=""/>
<packageattributes title=""/>
<packagestaticattributes title=""/>
<properties title=""/>
<events title=""/>
<privatetypes title=""/>
<privateslots title=""/>
<privatemethods title=""/>
<privatestaticmethods title=""/>
<privateattributes title=""/>
<privatestaticattributes title=""/>
<friends title=""/>
<related title="" subtitle=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<typedefs title=""/>
<enums title=""/>
<constructors title=""/>
<functions title=""/>
<related title=""/>
<variables title=""/>
<properties title=""/>
<events title=""/>
</memberdef>
<usedfiles visible="$SHOW_USED_FILES"/>
<authorsection visible="yes"/>
</class>
<!-- Layout definition for a namespace page -->
<namespace>
<briefdescription visible="yes"/>
<memberdecl>
<nestednamespaces visible="yes" title=""/>
<classes visible="yes" title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
</memberdef>
<authorsection visible="yes"/>
</namespace>
<!-- Layout definition for a file page -->
<file>
<briefdescription visible="no"/>
<includegraph visible="$INCLUDE_GRAPH"/>
<includedbygraph visible="$INCLUDED_BY_GRAPH"/>
<detaileddescription title="Description"/>
<includes visible="no"/>
<sourcelink visible="yes"/>
<memberdecl>
<classes visible="yes" title="Structures and Classes"/>
<namespaces visible="yes" title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
<membergroups visible="yes"/>
</memberdecl>
<memberdef>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
</memberdef>
<authorsection/>
</file>
<!-- Layout definition for a group page -->
<group>
<briefdescription visible="yes"/>
<groupgraph visible="$GROUP_GRAPHS"/>
<memberdecl>
<classes visible="yes" title=""/>
<namespaces visible="yes" title=""/>
<dirs visible="yes" title=""/>
<nestedgroups visible="yes" title=""/>
<files visible="yes" title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<pagedocs/>
<inlineclasses title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
</memberdef>
<authorsection visible="yes"/>
</group>
<!-- Layout definition for a directory page -->
<directory>
<briefdescription visible="yes"/>
<directorygraph visible="yes"/>
<memberdecl>
<dirs visible="yes"/>
<files visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
</directory>
</doxygenlayout>
/* except-gcc.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2009-2013, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**************************************************************************/
/**
* @file except-gcc.h
*
* @brief ABI for gcc exception handling.
*
* @par Origin
* The code below is generally copied from the Intel Itanium ABI (Intel
* download 245370).
*/
#ifndef INCLUDED_EXCEPT_GCC_DOT_H
#define INCLUDED_EXCEPT_GCC_DOT_H
#ifndef __cplusplus
# error except-gcc.h should be used in C++ code only.
#endif
#include <cilk/common.h>
#include <exception>
#include <typeinfo>
struct __cxa_exception;
__CILKRTS_BEGIN_EXTERN_C
/** Unwind reason code (Itanium ABI 6.1.2.1) */
typedef enum _Unwind_Reason_Code {
_URC_NO_REASON = 0,
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
_URC_FATAL_PHASE2_ERROR = 2,
_URC_FATAL_PHASE1_ERROR = 3,
_URC_NORMAL_STOP = 4,
_URC_END_OF_STACK = 5,
_URC_HANDLER_FOUND = 6,
_URC_INSTALL_CONTEXT = 7,
_URC_CONTINUE_UNWIND = 8
} _Unwind_Reason_Code;
typedef struct _Unwind_Exception _Unwind_Exception;
/** Exception cleanup function pointer (Itanium ABI 6.1.2.2) */
typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code reason,
_Unwind_Exception *exc);
/**
* @brief Exception undwinding information
*
* This is copied from the Intel Itanium ABI except that the
* private fields are declared unsigned long for binary
* compatibility with gcc/g++ on 32 bit machines.
*/
struct _Unwind_Exception
{
uint64_t exception_class;
_Unwind_Exception_Cleanup_Fn exception_cleanup;
unsigned long private_1;
unsigned long private_2;
};
/** Throw or rethrow an exception */
_Unwind_Reason_Code
_Unwind_RaiseException(_Unwind_Exception *exception_object);
/** Resume an exception other than by rethrowing it. */
void _Unwind_Resume(_Unwind_Exception *exception_object);
/** Delete an exception object */
void _Unwind_DeleteException(_Unwind_Exception *exception_object);
/**
* C++ exception ABI.
* The following declarations are from
*
* http://www.codesourcery.com/public/cxx-abi/abi-eh.html#cxx-abi
*/
struct __cxa_exception {
std::type_info * exceptionType;
void (*exceptionDestructor)(void *);
std::unexpected_handler unexpectedHandler;
std::terminate_handler terminateHandler;
__cxa_exception * nextException;
int handlerCount;
int handlerSwitchValue;
const char * actionRecord;
const char * languageSpecificData;
void * catchTemp;
void * adjustedPtr;
_Unwind_Exception unwindHeader;
};
static inline __cxa_exception *to_cxx(_Unwind_Exception *e)
{
return ((__cxa_exception *)(e+1)) - 1;
}
typedef struct __cxa_eh_globals {
__cxa_exception *caughtExceptions;
unsigned int uncaughtExceptions;
} __cxa_eh_globals;
__cxa_eh_globals*__cxa_get_globals(void) throw();
__CILKRTS_END_EXTERN_C
#endif // ! defined(INCLUDED_EXCEPT_GCC_DOT_H)
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment