Changes in / [22bdc34:e6d39fe]


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/Paper.tex

    r22bdc34 re6d39fe  
    1919\usepackage{listings}                                           % format program code
    2020\usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt]{subfig}
    21 \renewcommand{\thesubfigure}{(\Alph{subfigure})}
    22 \captionsetup{justification=raggedright,singlelinecheck=false}
     21\renewcommand{\thesubfigure}{(\alph{subfigure})}
    2322\usepackage{siunitx}
    2423\sisetup{ binary-units=true }
     
    9998\newcommand{\abbrevFont}{\textit}                       % set empty for no italics
    10099\@ifundefined{eg}{
    101 \newcommand{\EG}{\abbrevFont{e}\abbrevFont{g}}
     100\newcommand{\EG}{\abbrevFont{e}.\abbrevFont{g}.}
    102101\newcommand*{\eg}{%
    103102        \@ifnextchar{,}{\EG}%
     
    106105}}{}%
    107106\@ifundefined{ie}{
    108 \newcommand{\IE}{\abbrevFont{i}\abbrevFont{e}}
     107\newcommand{\IE}{\abbrevFont{i}.\abbrevFont{e}.}
    109108\newcommand*{\ie}{%
    110109        \@ifnextchar{,}{\IE}%
     
    144143                _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, __attribute, __attribute__,
    145144                auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, __const, __const__,
    146                 coroutine, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, finally,
     145                coroutine, disable, dtype, enable, __extension__, exception, fallthrough, fallthru, finally,
    147146                __float80, float80, __float128, float128, forall, ftype, _Generic, _Imaginary, __imag, __imag__,
    148147                inline, __inline, __inline__, __int128, int128, __label__, monitor, mutex, _Noreturn, one_t, or,
     
    170169literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    171170        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    172         {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,
     171        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,
    173172moredelim=**[is][\color{red}]{`}{`},
    174173}% lstset
     
    217216\author[1]{Thierry Delisle}
    218217\author[1]{Peter A. Buhr*}
    219 \authormark{DELISLE \textsc{et al.}}
    220 
    221 \address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Waterloo, ON}, \country{Canada}}}
    222 
    223 \corres{*Peter A. Buhr, Cheriton School of Computer Science, University of Waterloo, 200 University Avenue West, Waterloo, ON, N2L 3G1, Canada. \email{pabuhr{\char`\@}uwaterloo.ca}}
    224 
    225 \fundingInfo{Natural Sciences and Engineering Research Council of Canada}
     218\authormark{Thierry Delisle \textsc{et al}}
     219
     220\address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Ontario}, \country{Canada}}}
     221
     222\corres{*Peter A. Buhr, \email{pabuhr{\char`\@}uwaterloo.ca}}
     223\presentaddress{Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada}
     224
    226225
    227226\abstract[Summary]{
    228227\CFA is a modern, polymorphic, \emph{non-object-oriented} extension of the C programming language.
    229228This paper discusses the design of the concurrency and parallelism features in \CFA, and the concurrent runtime-system.
    230 These features are created from scratch as ISO C lacks concurrency, relying largely on pthreads library.
     229These features are created from scratch as ISO C lacks concurrency, relying largely on pthreads.
    231230Coroutines and lightweight (user) threads are introduced into the language.
    232231In addition, monitors are added as a high-level mechanism for mutual exclusion and synchronization.
     
    256255Examples of high-level approaches are task based~\cite{TBB}, message passing~\cite{Erlang,MPI}, and implicit threading~\cite{OpenMP}.
    257256
    258 This paper uses the following terminology.
     257This paper used the following terminology.
    259258A \newterm{thread} is a fundamental unit of execution that runs a sequence of code and requires a stack to maintain state.
    260 Multiple simultaneous threads give rise to \newterm{concurrency}, which requires locking to ensure safe communication and access to shared data.
     259Multiple simultaneous threads gives rise to \newterm{concurrency}, which requires locking to ensure safe communication and access to shared data.
    261260% Correspondingly, concurrency is defined as the concepts and challenges that occur when multiple independent (sharing memory, timing dependencies, \etc) concurrent threads are introduced.
    262261\newterm{Locking}, and by extension locks, are defined as a mechanism to prevent progress of threads to provide safety.
    263262\newterm{Parallelism} is running multiple threads simultaneously.
    264263Parallelism implies \emph{actual} simultaneous execution, where concurrency only requires \emph{apparent} simultaneous execution.
    265 As such, parallelism only affects performance, which is observed through differences in space and/or time.
     264As such, parallelism is only observable in differences in performance, which is observed through differences in timing.
    266265
    267266Hence, there are two problems to be solved in the design of concurrency for a programming language: concurrency and parallelism.
    268 While these two concepts are often combined, they are distinct, requiring different tools~\cite[\S~2]{Buhr05a}.
     267While these two concepts are often combined, they are in fact distinct, requiring different tools~\cite[\S~2]{Buhr05a}.
    269268Concurrency tools handle synchronization and mutual exclusion, while parallelism tools handle performance, cost and resource utilization.
    270269
     
    279278
    280279The following is a quick introduction to the \CFA language, specifically tailored to the features needed to support concurrency.
    281 Most of the following code examples can be found on the \CFA website~\cite{Cforall}.
    282 
    283 \CFA is an extension of ISO-C, and therefore, supports all of the same paradigms as C.
    284 %It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opted out easily.
     280
     281\CFA is an extension of ISO-C and therefore supports all of the same paradigms as C.
     282It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opted out easily.
    285283Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code.
    286284The vast majority of the code produced by the \CFA translator respects memory layouts and calling conventions laid out by C.
    287 Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (\eg @this@) and inheritance, it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent
     285Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (\eg {\tt this}), it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent
    288286values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects.
     287Most of the following code examples can be found on the \CFA website~\cite{Cforall}.
    289288
    290289
     
    294293In regards to concurrency, the semantic difference between pointers and references are not particularly relevant, but since this document uses mostly references, here is a quick overview of the semantics:
    295294\begin{cfa}
    296 int x, y, z;
    297 int * p1 = &x, ** p2 = &p1, *** p3 = &p2,       $\C{// pointers to x}$
    298         & r1 = x,   && r2 = r1, &&& r3 = r2;    $\C{// references to x}$
    299 
    300 *p1 = 3; **p2 = 3; ***p3 = 3;                           $\C{// change x}$
    301   r1 = 3;    r2 = 3;      r3 = 3;                       $\C{// change x}$
    302 **p3 = &y; *p3 = &z;                                            $\C{// change p1, p2}$
    303 &&r3 = &y; &r3 = &z;                                            $\C{// change p1, p2}$
    304 int & ar[3] = {x, y, z};                                        $\C{// initialize array of references}$
    305 
    306 typeof( ar[1]) p;                                                       $\C{// is int, referenced object type}$
    307 typeof(&ar[1]) q;                                                       $\C{// is int \&, reference type}$
    308 sizeof( ar[1]) == sizeof(int);                          $\C{// is true, referenced object size}$
    309 sizeof(&ar[1]) == sizeof(int *);                        $\C{// is true, reference size}$
     295int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
     296        &r1 = x,    &&r2 = r1,   &&&r3 = r2;
     297***p3 = 3;                                                      $\C{// change x}$
     298r3    = 3;                                                      $\C{// change x, ***r3}$
     299**p3  = ...;                                            $\C{// change p1}$
     300*p3   = ...;                                            $\C{// change p2}$
     301int y, z, & ar[3] = {x, y, z};          $\C{// initialize array of references}$
     302typeof( ar[1]) p;                                       $\C{// is int, referenced object type}$
     303typeof(&ar[1]) q;                                       $\C{// is int \&, reference type}$
     304sizeof( ar[1]) == sizeof(int);          $\C{// is true, referenced object size}$
     305sizeof(&ar[1]) == sizeof(int *);        $\C{// is true, reference size}$
    310306\end{cfa}
    311307The important take away from this code example is that a reference offers a handle to an object, much like a pointer, but which is automatically dereferenced for convenience.
     
    630626\end{lrbox}
    631627\subfloat[3 States, internal variables]{\label{f:Coroutine3States}\usebox\myboxA}
    632 \qquad\qquad
     628\qquad
    633629\subfloat[1 State, internal variables]{\label{f:Coroutine1State}\usebox\myboxB}
    634630\caption{\CFA Coroutine Fibonacci Implementations}
     
    657653
    658654\begin{figure}
    659 \begin{cfa}[xleftmargin=4\parindentlnth]
     655\centering
     656\begin{cfa}
    660657`coroutine` Format {
    661658        char ch;                                                                $\C{// used for communication}$
  • doc/papers/general/Paper.tex

    r22bdc34 re6d39fe  
    1 \documentclass[AMA,STIX1COL]{WileyNJD-v2}
    2 
     1\documentclass[AMA,STIX1COL,STIXSMALL]{WileyNJD-v2}
    32\articletype{RESEARCH ARTICLE}%
    43
     
    1817\usepackage{upquote}                                            % switch curled `'" to straight
    1918\usepackage{listings}                                           % format program code
    20 \captionsetup{justification=raggedright,singlelinecheck=false}
    2119%\usepackage{enumitem}
    2220%\setlist[itemize]{topsep=3pt,itemsep=2pt,parsep=0pt}% global
     
    2927\renewcommand{\linenumberfont}{\scriptsize\sffamily}
    3028
    31 \lefthyphenmin=3                                                        % hyphen only after 4 characters
    32 \righthyphenmin=3
     29\lefthyphenmin=4                                                        % hyphen only after 4 characters
     30\righthyphenmin=4
    3331
    3432%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    8886\newcommand{\abbrevFont}{\textit}                       % set empty for no italics
    8987\@ifundefined{eg}{
    90 \newcommand{\EG}{\abbrevFont{e}\abbrevFont{g}}
     88\newcommand{\EG}{\abbrevFont{e}.\abbrevFont{g}.}
    9189\newcommand*{\eg}{%
    9290        \@ifnextchar{,}{\EG}%
     
    9593}}{}%
    9694\@ifundefined{ie}{
    97 \newcommand{\IE}{\abbrevFont{i}\abbrevFont{e}}
     95\newcommand{\IE}{\abbrevFont{i}.\abbrevFont{e}.}
    9896\newcommand*{\ie}{%
    9997        \@ifnextchar{,}{\IE}%
     
    131129\lstdefinelanguage{CFA}[ANSI]{C}{
    132130        morekeywords={
    133                 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, __attribute, __attribute__,
    134                 auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, __const, __const__,
    135                 coroutine, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, finally,
    136                 __float80, float80, __float128, float128, forall, ftype, _Generic, _Imaginary, __imag, __imag__,
    137                 inline, __inline, __inline__, __int128, int128, __label__, monitor, mutex, _Noreturn, one_t, or,
    138                 otype, restrict, __restrict, __restrict__, __signed, __signed__, _Static_assert, thread,
    139                 _Thread_local, throw, throwResume, timeout, trait, try, ttype, typeof, __typeof, __typeof__,
    140                 virtual, __volatile, __volatile__, waitfor, when, with, zero_t},
     131                _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, _At, __attribute,
     132                __attribute__, auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__,
     133                __const, __const__, disable, dtype, enable, exception, __extension__, fallthrough, fallthru,
     134                finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, _Noreturn, one_t,
     135                otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof,
     136                __typeof__, virtual, with, zero_t},
     137        morekeywords=[2]{
     138                _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex, or,
     139                resume, suspend, thread, _Thread_local, waitfor, when, yield},
    141140        moredirectives={defined,include_next}%
    142141}
     
    159158literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    160159        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    161         {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,
     160        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,
    162161moredelim=**[is][\color{red}]{`}{`},
    163162}% lstset
     
    181180\authormark{MOSS \textsc{et al}}
    182181
    183 \address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Waterloo, ON}, \country{Canada}}}
    184 
    185 \corres{*Peter A. Buhr, Cheriton School of Computer Science, University of Waterloo, 200 University Avenue West, Waterloo, ON, N2L 3G1, Canada. \email{pabuhr{\char`\@}uwaterloo.ca}}
    186 
    187 \fundingInfo{Natural Sciences and Engineering Research Council of Canada}
     182\address[1]{\orgdiv{David R. Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Ontario}, \country{Canada}}}
     183
     184\corres{*Peter A. Buhr, \email{pabuhr{\char`\@}uwaterloo.ca}}
     185\presentaddress{David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada}
     186
    188187
    189188\abstract[Summary]{
     
    229228Nevertheless, C, first standardized over thirty years ago, lacks many features that make programming in more modern languages safer and more productive.
    230229
    231 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C, while maintaining both source and runtime compatibility with C and a familiar programming model for programmers.
     230\CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C while maintaining both source compatibility with C and a familiar programming model for programmers.
    232231The four key design goals for \CFA~\cite{Bilson03} are:
    233232(1) The behaviour of standard C code must remain the same when translated by a \CFA compiler as when translated by a C compiler;
     
    329328A simple example is leveraging the existing type-unsafe (@void *@) C @bsearch@ to binary search a sorted float array:
    330329\begin{cfa}
    331 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (* compar)( const void *, const void * ));
     330void * bsearch( const void * key, const void * base, size_t nmemb, size_t size,
     331                                         int (* compar)( const void *, const void * ));
    332332int comp( const void * t1, const void * t2 ) {
    333333         return *(double *)t1 < *(double *)t2 ? -1 : *(double *)t2 < *(double *)t1 ? 1 : 0;
     
    336336double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$
    337337\end{cfa}
    338 which can be augmented simply with generalized, type-safe, \CFA-overloaded wrappers:
     338which can be augmented simply with a generalized, type-safe, \CFA-overloaded wrappers:
    339339\begin{cfa}
    340340forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) {
     
    398398        T ?++( T * );
    399399};
    400 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {$\C{// use trait}$
     400forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {  // use trait
    401401        `T` total = { `0` };                                    $\C{// instantiate T from 0 by calling its constructor}$
    402402        for ( unsigned int i = 0; i < size; i += 1 ) total `+=` a[i]; $\C{// select appropriate +}$
     
    576576        return (scalar(U)){ a.value + b.value };
    577577}
    578 scalar(metres) half_marathon = { 21_093 };
    579 scalar(litres) swimming_pool = { 2_500_000 };
     578scalar(metres) half_marathon = { 21093 };
     579scalar(litres) swimming_pool = { 2500000 };
    580580scalar(metres) marathon = half_marathon + half_marathon;
    581581scalar(litres) two_pools = swimming_pool + swimming_pool;
     
    724724\end{cfa}
    725725Here, the mass assignment sets all members of @s@ to zero.
    726 Since tuple-index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member-tuple expressions to manually restructure a tuple (\eg rearrange, drop, and duplicate components).
     726Since tuple-index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member tuple expressions to manually restructure a tuple (\eg rearrange, drop, and duplicate components).
    727727\begin{cfa}
    728728[int, int, long, double] x;
     
    18791879\lstDeleteShortInline@%
    18801880\begin{tabular}{@{}l@{\hspace{3em}}l|l@{}}
    1881 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}}      & \multicolumn{1}{c|}{\textbf{C Implicit Hoisting}}     & \multicolumn{1}{c}{\textbf{\CFA}}     \\
     1881\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}}      & \multicolumn{1}{c}{\textbf{C Implicit Hoisting}}      & \multicolumn{1}{|c}{\textbf{\CFA}}    \\
    18821882\hline
    18831883\begin{cfa}
     
    20022002{
    20032003        VLA  x,            y = { 20, 0x01 },     z = y; $\C{// z points to y}$
    2004         //      ?{}( x );   ?{}( y, 20, 0x01 );   ?{}( z, y );
     2004        //    ?{}( x );   ?{}( y, 20, 0x01 );    ?{}( z, y );
    20052005        ^x{};                                                                   $\C{// deallocate x}$
    20062006        x{};                                                                    $\C{// reallocate x}$
     
    20272027These semantics closely mirror the rule for implicit declaration of constructors in \CC\cite[p.~186]{ANSI98:C++}.
    20282028
    2029 In some circumstance programmers may not wish to have implicit constructor and destructor generation and calls.
    2030 In these cases, \CFA provides the initialization syntax \lstinline|S x `@=` {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated.
    2031 Any C initializer can be the right-hand side of an \lstinline|@=| initializer, \eg \lstinline|VLA a @= { 0, 0x0 }|, with the usual C initialization semantics.
    2032 The same syntax can be used in a compound literal, \eg \lstinline|a = VLA`@`{ 0, 0x0 }|, to create a C-style literal.
     2029In some circumstance programmers may not wish to have constructor and destructor calls.
     2030In these cases, \CFA provides the initialization syntax \lstinline|S x @= {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated.
     2031Any C initializer can be the right-hand side of an \lstinline|@=| initializer, \eg \lstinline|VLA a @= { 0, 0x0 }|, with the usual C initialization semantics.
    20332032The point of \lstinline|@=| is to provide a migration path from legacy C code to \CFA, by providing a mechanism to incrementally convert to implicit initialization.
    20342033
     
    20552054\begin{cfa}
    2056205520_`hh`     // signed char
    2057 21_`hh`u   // unsigned char
     205621_`hh`u    // unsigned char
    2058205722_`h`       // signed short int
    2059205823_u`h`     // unsigned short int
    2060 24`z`         // size_t
     205924`z`       // size_t
    20612060\end{cfa}
    20622061&
     
    20892088To provide this precision, \CFA introduces a new type @zero_t@ as the type of literal @0@ (somewhat analagous to @nullptr_t@ and @nullptr@ in \CCeleven);
    20902089@zero_t@ can only take the value @0@, but has implicit conversions to the integer and pointer types so that C code involving @0@ continues to work.
    2091 With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ( (x) != 0 )@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?( T, zero_t )@.
     2090With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ((x) != 0)@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?(T, zero_t)@.
    20922091\CC makes types truthy by adding a conversion to @bool@;
    20932092prior to the addition of explicit cast operators in \CCeleven, this approach had the pitfall of making truthy types transitively convertable to any numeric type;
     
    21642163\lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}}
    21652164\lstDeleteShortInline@%
    2166 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2167 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{\CC}}      \\
     2165\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2166\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
    21682167\begin{cfa}
    21692168struct W {
     
    22612260\begin{cfa}
    22622261MIN
     2262
    22632263MAX
     2264
    22642265PI
    22652266E
     
    22672268&
    22682269\begin{cfa}
    2269 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN
    2270 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX
     2270SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN,
     2271                FLT_MIN, DBL_MIN, LDBL_MIN
     2272SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX,
     2273                FLT_MAX, DBL_MAX, LDBL_MAX
    22712274M_PI, M_PIl
    22722275M_E, M_El
     
    24412444ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) );
    24422445ip = (int *)realloc( ip, 2 * dim * sizeof( int ) );
    2443 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) );
    2444 
     2446ip = (int *)realloc( ip, 4 * dim * sizeof( int ) );
     2447                        memset( ip, fill, 4 * dim * sizeof( int ) );
    24452448ip = memalign( 16, sizeof( int ) );
    24462449ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) );
  • src/Common/utility.h

    r22bdc34 re6d39fe  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 20 22:35:33 2018
    13 // Update Count     : 38
     12// Last Modified On : Thu Apr 19 16:21:44 2018
     13// Update Count     : 37
    1414//
    1515
     
    437437
    438438// -----------------------------------------------------------------------------
    439 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most
     439// O(1) polymorphic integer log2, using clz, which returns the number of leading 0-bits, starting at the most
    440440// significant bit (single instruction on x86)
    441441
    442442template<typename T>
    443 inline constexpr T ilog2(const T & t) {
     443inline constexpr T log2(const T & t) {
    444444        if ( std::is_integral<T>::value ) {
    445445                const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1;
     
    449449        } // if
    450450        return -1;
    451 } // ilong2
     451}
    452452
    453453
  • src/Parser/DeclarationNode.cc

    r22bdc34 re6d39fe  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 20 22:37:20 2018
    13 // Update Count     : 1063
     12// Last Modified On : Thu Apr 19 15:09:29 2018
     13// Update Count     : 1062
    1414//
    1515
     
    562562        checkQualifiers( type, q->type );
    563563        if ( (builtin == Zero || builtin == One) && error.length() == 0 ) {
    564                 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ilog2( q->type->qualifiers.val )], builtinTypeNames[builtin] );
     564                SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[log2( q->type->qualifiers.val )], builtinTypeNames[builtin] );
    565565//              appendError( error, string( "questionable qualifiers" ) );
    566566        } // if
  • src/tests/concurrent/examples/boundedBufferEXT.c

    r22bdc34 re6d39fe  
    88// Created On       : Wed Apr 18 22:52:12 2018
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Fri Apr 20 22:25:14 2018
    11 // Update Count     : 6
     10// Last Modified On : Wed Apr 18 22:56:17 2018
     11// Update Count     : 2
    1212//
    1313
     
    2020//Duration default_preemption() { return 0; }
    2121
    22 enum { BufferSize = 50 };
     22enum { BufferSize = 5 };
    2323
    2424forall( otype T )
     
    3333forall( otype T )
    3434int query( Buffer(T) & buffer ) { return buffer.count; }
    35 
    36 forall( otype T )                                                                               // forward
    37 T remove( Buffer(T) & mutex buffer );
    3835
    3936forall( otype T )
  • src/tests/concurrent/examples/boundedBufferINT.c

    r22bdc34 re6d39fe  
    88// Created On       : Mon Oct 30 12:45:13 2017
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Fri Apr 20 22:18:18 2018
    11 // Update Count     : 78
     10// Last Modified On : Tue Jan  2 12:18:18 2018
     11// Update Count     : 33
    1212//
    1313
    14 #include <stdlib>                                                                               // random
    15 #include <fstream>
     14#include <stdlib>
     15#include <fstream>                                                                              // random
    1616#include <kernel>
    1717#include <thread>
    1818#include <unistd.h>                                                                             // getpid
    1919
    20 //Duration default_preemption() { return 0; }
    21 
    22 enum { BufferSize = 50 };
    23 
    24 forall( otype T )
    2520monitor Buffer {
    2621        condition full, empty;
    2722        int front, back, count;
    28         T elements[BufferSize];
     23        int elements[20];
    2924};
    3025
    31 forall( otype T )
    32 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
     26void ?{}( Buffer & buffer ) {
     27        buffer.front = buffer.back = buffer.count = 0;
     28}
    3329
    34 forall( otype T )
    35 int query( Buffer(T) & buffer ) { return buffer.count; }
     30int query( Buffer & buffer ) { return buffer.count; }
    3631
    37 forall( otype T )
    38 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
    39         if ( count == BufferSize ) wait( empty );
     32void insert( Buffer & mutex buffer, int elem ) with( buffer ) {
     33        if ( count == 20 ) wait( empty );
    4034        elements[back] = elem;
    41         back = ( back + 1 ) % BufferSize;
     35        back = ( back + 1 ) % 20;
    4236        count += 1;
    4337        signal( full );
    4438}
    4539
    46 forall( otype T )
    47 T remove( Buffer(T) & mutex buffer ) with( buffer ) {
     40int remove( Buffer & mutex buffer ) with( buffer ) {
    4841        if ( count == 0 ) wait( full );
    49         T elem = elements[front];
    50         front = ( front + 1 ) % BufferSize;
     42        int elem = elements[front];
     43        front = ( front + 1 ) % 20;
    5144        count -= 1;
    5245        signal( empty );
     
    5447}
    5548
    56 const int Sentinel = -1;
    57 
    5849thread Producer {
    59         Buffer(int) & buffer;
     50        Buffer & buffer;
    6051        unsigned int N;
    6152};
    62 void main( Producer & prod ) with( prod ) {
    63         for ( int i = 1; i <= N; i += 1 ) {
     53void main( Producer & prod ) {
     54        for ( int i = 1; i <= prod.N; i += 1 ) {
    6455                yield( random( 5 ) );
    65                 insert( buffer, 1 );
     56                insert( prod.buffer, 1 );
    6657        } // for
     58        insert( prod.buffer, -1 );
    6759}
    68 void ?{}( Producer & prod, Buffer(int) * buffer, int N ) {
     60void ?{}( Producer & prod, Buffer * buffer, unsigned int N ) {
    6961        &prod.buffer = buffer;
    7062        prod.N = N;
     
    7264
    7365thread Consumer {
    74         Buffer(int) & buffer;
    75         int & sum;                                                                                      // summation of producer values
     66        Buffer & buffer;
     67        int & sum;                                              // summation of producer values
    7668};
    77 void main( Consumer & cons ) with( cons ) {
    78         sum = 0;
     69void main( Consumer & cons ) {
     70        cons.sum = 0;
    7971        for ( ;; ) {
    8072                yield( random( 5 ) );
    81                 int item = remove( buffer );
    82           if ( item == Sentinel ) break;                                        // sentinel ?
    83                 sum += item;
     73                int item = remove( cons.buffer );
     74                if ( item == -1 ) break;                                // sentinel ?
     75                cons.sum += item;
    8476        } // for
    8577}
    86 void ?{}( Consumer & cons, Buffer(int) * buffer, int & sum ) {
     78void ?{}( Consumer & cons, Buffer * buffer, int * sum ) {
    8779        &cons.buffer = buffer;
    88         &cons.sum = &sum;
     80        &cons.sum = sum;
    8981}
    9082
    9183int main() {
    92         Buffer(int) buffer;
    93         enum { Prods = 4, Cons = 5 };
     84        Buffer buffer;
     85        enum { Prods = 5, Cons = 5 };
    9486        Producer * prods[Prods];
    9587        Consumer * cons[Cons];
     88        const int Sentinel = -1;
    9689        int sums[Cons];
    9790        int i;
     
    10194        srandom( 1003 );
    10295
    103         for ( i = 0; i < Cons; i += 1 ) {                                       // create consumers
    104                 cons[i] = new( &buffer, sums[i] );
     96        for ( i = 0; i < Cons; i += 1 ) {                       // create consumers
     97                cons[i] = new( &buffer, &sums[i] );
    10598        } // for
    106         for ( i = 0; i < Prods; i += 1 ) {                                      // create producers
    107                 prods[i] = new( &buffer, 100000 );
     99        for ( i = 0; i < Prods; i += 1 ) {                      // create producers
     100                prods[i] = new( &buffer, 100000u );
    108101        } // for
    109102
    110         for ( i = 0; i < Prods; i += 1 ) {                                      // wait for producers to finish
     103        for ( i = 0; i < Prods; i += 1 ) {                      // wait for producers to finish
    111104                delete( prods[i] );
    112105        } // for
    113         for ( i = 0; i < Cons; i += 1 ) {                                       // generate sentinal values to stop consumers
     106        for ( i = 0; i < Cons; i += 1 ) {                       // generate sentinal values to stop consumers
    114107                insert( buffer, Sentinel );
    115108        } // for
    116109        int sum = 0;
    117         for ( i = 0; i < Cons; i += 1 ) {                                       // wait for consumers to finish
     110        for ( i = 0; i < Cons; i += 1 ) {                       // wait for consumers to finish
    118111                delete( cons[i] );
    119112                sum += sums[i];
     
    124117// Local Variables: //
    125118// tab-width: 4 //
    126 // compile-command: "cfa boundedBufferINT.c" //
     119// compile-command: "cfa boundedBuffer.c" //
    127120// End: //
Note: See TracChangeset for help on using the changeset viewer.