├── AUTHORS ├── COPYING ├── ChangeLog ├── FAQ ├── Makefile.am ├── bfnnconv.pl ├── cilk-faq.bfnn ├── html.refs ├── m-ascii.pl ├── m-html.pl ├── m-info.pl ├── m-lout.pl └── m-post.pl ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── THANKS ├── acinclude.m4 ├── bootstrap.sh ├── cilk2c ├── .indent.pro ├── ANSI-C.c ├── ANSI-C.h ├── ANSI-C.y ├── BUGS ├── Makefile.am ├── Makefile.in ├── analyze.c ├── ast.c ├── ast.h ├── astEquals.c ├── astEquals.h ├── astModify.c ├── astModify.h ├── astgen ├── atmTransform.c ├── atmTransform.h ├── basics.h ├── c4.c ├── c4.l ├── complex-types.c ├── config.h ├── constexpr.c ├── container.c ├── conversions.c ├── conversions.h ├── dataflow.c ├── dataflow.h ├── elide.c ├── gbuf.c ├── gbuf.h ├── heap.h ├── hint.c ├── initializer.c ├── initializer.h ├── list.c ├── list.h ├── main.c ├── operators.c ├── operators.h ├── output.c ├── print-ast.c ├── procedure.c ├── profile.c ├── sem-check.c ├── sideeffects.c ├── simplify.c ├── stringParse.c ├── stringParse.h ├── strings.c ├── sue.c ├── symbol.c ├── symbol.h ├── testEquals.c ├── testEquals.h ├── transform.c ├── type.c ├── type.h ├── type2.c ├── typequal.c ├── typequal.h ├── verify-parse.c ├── warning.c ├── wildcard.c ├── wildcard.h ├── wildcardTable.c └── wildcardTable.h ├── compile ├── config.guess ├── config.h.in ├── config.sub ├── configure.ac ├── depcomp ├── doc ├── Makefile.am ├── cactus.eps ├── cactus.pdf ├── cilk.bib ├── copyright.tex ├── defs.tex ├── fib-compile.fig ├── fib.tex ├── fib2.tex ├── impl-notes.tex ├── intro.tex ├── lanref.tex ├── library-spec.tex ├── manual.pdf ├── manual.tex ├── misc.tex ├── model.eps ├── model.fig ├── model.pdf ├── people.tex ├── prog-guide.tex ├── supertech.sty ├── version.tex └── version.tex.in ├── examples ├── Makefile.am ├── bucket.cilk ├── cholesky-lib.cilk ├── cholesky.cilk ├── cilksort.cilk ├── ck.cilk ├── fft.cilk ├── fib-serial.c ├── fib.cilk ├── game.cilk ├── getoptions.c ├── getoptions.h ├── heat.cilk ├── hello.cilk ├── kalah.cilk ├── knapsack-example1.input ├── knapsack-example2.input ├── knapsack-example3.input ├── knapsack.cilk ├── lu.cilk ├── magic.cilk ├── matmul.cilk ├── nfib-lib.cilk ├── nfib.cilk ├── plu.cilk ├── queens.cilk ├── rand.cilk ├── rectmul.cilk ├── spacemul.cilk ├── strassen.cilk ├── test-errno.cilk ├── test-locks.cilk ├── test-void-func.cilk ├── testall.cilk └── velin.cilk ├── install-sh ├── ltmain.sh ├── missing ├── runtime ├── Makefile.am ├── PROTOCOLS ├── TODO ├── barrier.c ├── cilk-cilk2c-pre.h ├── cilk-cilk2c.h ├── cilk-conf.h ├── cilk-internal.h ├── cilk-lib.cilkh ├── cilk-lib.h ├── cilk-sysdep.h ├── cilk-sysdep.h.in ├── cilk.c ├── cilk.h ├── cilkrt0.c ├── cmdline.c ├── debug.c ├── gcc-builtin.h ├── hooks.c ├── internal-malloc.c ├── invoke-main.c ├── malloc.c ├── mutex.c ├── sched.c ├── stats.c ├── sysdep.c ├── timing.c └── workers.c ├── support ├── Makefile.am ├── automake-cilk ├── cilk.m4 ├── cilkc.c ├── dotemacs.el ├── make-temp-file.c └── make-temp-file.h └── ylwrap /AUTHORS: -------------------------------------------------------------------------------- 1 | The Cilk project is led by Prof. Charles E. Leiserson of the MIT 2 | Laboratory for Computer Science and is supported in part by NSF Grant 3 | E1A-9975036. Previous support was provided in part by DARPA Grant 4 | F30602-97-1-0270. 5 | 6 | The current maintainer of Cilk is Bradley C. Kuszmaul 7 | , who is responsible for the Cilk-5.4 release. 8 | 9 | Cilk-5.4 is the product of the effort of many people over many years. 10 | The following people contributed code, example programs, and/or 11 | documentation to the Cilk-5.4 system: 12 | 13 | Eitan Ben Amos 14 | Robert D. Blumofe 15 | Guang-Ien Cheng 16 | Don Dailey 17 | Mingdong Feng 18 | Matteo Frigo 19 | Bradley C. Kuszmaul 20 | Charles E. Leiserson 21 | Phil Lisiecki 22 | Alberto Medina 23 | Robert Miller 24 | Ofra Pavlovitz 25 | Harald Prokop 26 | Keith H. Randall 27 | Bin Song 28 | Andy Stark 29 | Volker Strumpen 30 | 31 | The cilk2c translator is derived from the c2c program written by 32 | 33 | Robert Miller 34 | 35 | In turn, c2c uses the ANSI C grammar and lexer written by 36 | 37 | James A. Roskind 38 | 39 | and modified by 40 | 41 | Eric A. Brewer 42 | Michael D. Noakes 43 | 44 | These people have worked on previous versions of Cilk: 45 | 46 | Michael Halbherr 47 | Christopher F. Joerg 48 | Howard Lu 49 | Aske Plaat 50 | Richard Tauriello 51 | Daricha Techopitayakul 52 | Yuli Zhou 53 | -------------------------------------------------------------------------------- /FAQ/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = bfnnconv.pl* html.refs m-html.pl m-lout.pl cilk-faq.bfnn \ 2 | m-ascii.pl m-info.pl m-post.pl cilk-faq.ascii 3 | PERL=perl -I$(srcdir) 4 | 5 | all cilk-faq.ascii: cilk-faq.bfnn 6 | @echo converting 1 ... 7 | $(PERL) $(srcdir)/bfnnconv.pl $(srcdir)/cilk-faq.bfnn 8 | @echo converting 2 ... 9 | $(PERL) $(srcdir)/bfnnconv.pl $(srcdir)/cilk-faq.bfnn 10 | 11 | clean-local: 12 | rm -f *~ core a.out *.lout *.ps *.info *.ascii *.xrefdb *.post 13 | rm -rf *.html 14 | -------------------------------------------------------------------------------- /FAQ/html.refs: -------------------------------------------------------------------------------- 1 | \ References for the Cilk FAQ 2 | \ 3 | the Cilk web page \ http://supertech.lcs.mit.edu/cilk 4 | SourceForge (www.sourceforge.net) \ http://www.sourceforge.net 5 | Categories of Free and Non-Free Software \ http://www.gnu.org/philosophy/categories.html 6 | -------------------------------------------------------------------------------- /FAQ/m-ascii.pl: -------------------------------------------------------------------------------- 1 | ## ASCII output 2 | # Copyright (C) 1993-1995 Ian Jackson. 3 | 4 | # This file is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2, or (at your option) 7 | # any later version. 8 | 9 | # It is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with GNU Emacs; see the file COPYING. If not, write to 16 | # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 02111-1307, USA. 18 | 19 | # (Note: I do not consider works produced using these BFNN processing 20 | # tools to be derivative works of the tools, so they are NOT covered 21 | # by the GPL. However, I would appreciate it if you credited me if 22 | # appropriate in any documents you format using BFNN.) 23 | 24 | sub ascii_init { 25 | open(ASCII,">$prefix.ascii"); 26 | } 27 | 28 | sub ascii_startmajorheading { 29 | print ASCII '='x79,"\n\n"; 30 | $ascii_status= 'h'; 31 | &ascii_text($_[0] ? "Section $_[0]. " : ''); 32 | } 33 | 34 | sub ascii_startminorheading { 35 | print ASCII '-'x79,"\n\n"; 36 | $ascii_status= 'h'; 37 | } 38 | 39 | sub ascii_italic { &ascii_text('*'); } 40 | sub ascii_enditalic { $ascii_para .= '*'; } 41 | 42 | sub ascii_email { &ascii_text('<'); } sub ascii_endemail { &ascii_text('>'); } 43 | 44 | sub ascii_ftpon { } sub ascii_endftpon { } 45 | sub ascii_ftpin { } sub ascii_endftpin { } 46 | sub ascii_docref { } sub ascii_enddocref { } 47 | sub ascii_courier { } sub ascii_endcourier { } 48 | sub ascii_newsgroup { } sub ascii_endnewsgroup { } 49 | sub ascii_ftpsilent { $ascii_ignore++; } 50 | sub ascii_endftpsilent { $ascii_ignore--; } 51 | 52 | sub ascii_text { 53 | return if $ascii_ignore; 54 | if ($ascii_status eq '') { 55 | $ascii_status= 'p'; 56 | } 57 | $ascii_para .= $_[0]; 58 | } 59 | 60 | sub ascii_tab { 61 | local ($n) = $_[0]-length($ascii_para); 62 | $ascii_para .= ' 'x$n if $n>0; 63 | } 64 | 65 | sub ascii_newline { 66 | return unless $ascii_status eq 'p'; 67 | &ascii_writepara; 68 | } 69 | 70 | sub ascii_writepara { 71 | local ($thisline, $thisword, $rest); 72 | for (;;) { 73 | last unless $ascii_para =~ m/\S/; 74 | $thisline= $ascii_indentstring; 75 | for (;;) { 76 | last unless $ascii_para =~ m/^(\s*\S+)/; 77 | unless (length($1) + length($thisline) < 75 || 78 | length($thisline) == length($ascii_indentstring)) { 79 | last; 80 | } 81 | $thisline .= $1; 82 | $ascii_para= $'; 83 | } 84 | $ascii_para =~ s/^\s*//; 85 | print ASCII $thisline,"\n"; 86 | $ascii_indentstring= $ascii_nextindent; 87 | last unless length($ascii_para); 88 | } 89 | $ascii_status= ''; $ascii_para= ''; 90 | } 91 | 92 | sub ascii_endpara { 93 | return unless $ascii_status eq 'p'; 94 | &ascii_writepara; 95 | print ASCII "\n"; 96 | } 97 | 98 | sub ascii_endheading { 99 | $ascii_para =~ s/\s*$//; 100 | print ASCII "$ascii_para\n\n"; 101 | $ascii_status= ''; 102 | $ascii_para= ''; 103 | } 104 | 105 | sub ascii_endmajorheading { &ascii_endheading(@_); } 106 | sub ascii_endminorheading { &ascii_endheading(@_); } 107 | 108 | sub ascii_startverbatim { 109 | $ascii_vstatus= $ascii_status; 110 | &ascii_writepara; 111 | } 112 | 113 | sub ascii_verbatim { 114 | print ASCII $_[0],"\n"; 115 | } 116 | 117 | sub ascii_endverbatim { 118 | $ascii_status= $ascii_vstatus; 119 | } 120 | 121 | sub ascii_finish { 122 | close(ASCII); 123 | } 124 | 125 | sub ascii_startindex { $ascii_status= ''; } 126 | sub ascii_endindex { $ascii_status= 'p'; } 127 | 128 | sub ascii_endindexitem { 129 | printf ASCII " %-11s %-.66s\n",$ascii_left,$ascii_para; 130 | $ascii_status= 'p'; 131 | $ascii_para= ''; 132 | } 133 | 134 | sub ascii_startindexitem { 135 | $ascii_left= $_[1]; 136 | } 137 | 138 | sub ascii_startindexmainitem { 139 | $ascii_left= $_[1]; 140 | print ASCII "\n" if $ascii_status eq 'p'; 141 | } 142 | 143 | sub ascii_startindent { 144 | $ascii_istatus= $ascii_status; 145 | &ascii_writepara; 146 | $ascii_indentstring= " $ascii_indentstring"; 147 | $ascii_nextindent= " $ascii_nextindent"; 148 | } 149 | 150 | sub ascii_endindent { 151 | $ascii_indentstring =~ s/^ //; 152 | $ascii_nextindent =~ s/^ //; 153 | $ascii_status= $ascii_istatus; 154 | } 155 | 156 | sub ascii_startpackedlist { $ascii_plc=0; } 157 | sub ascii_endpackedlist { &ascii_newline if !$ascii_plc; } 158 | sub ascii_packeditem { 159 | &ascii_newline if !$ascii_plc; 160 | &ascii_tab($ascii_plc*40+5); 161 | $ascii_plc= !$ascii_plc; 162 | } 163 | 164 | sub ascii_startlist { 165 | &ascii_endpara; 166 | $ascii_indentstring= " $ascii_indentstring"; 167 | $ascii_nextindent= " $ascii_nextindent"; 168 | } 169 | 170 | sub ascii_endlist { 171 | &ascii_endpara; 172 | $ascii_indentstring =~ s/^ //; 173 | $ascii_nextindent =~ s/^ //; 174 | } 175 | 176 | sub ascii_item { 177 | &ascii_newline; 178 | $ascii_indentstring =~ s/ $/* /; 179 | } 180 | 181 | sub ascii_pageref { 182 | &ascii_text("Q$_[1] \`"); 183 | } 184 | 185 | sub ascii_endpageref { 186 | &ascii_text("'"); 187 | } 188 | 189 | 1; 190 | -------------------------------------------------------------------------------- /FAQ/m-info.pl: -------------------------------------------------------------------------------- 1 | ## Info output 2 | # Copyright (C) 1993-1995 Ian Jackson. 3 | 4 | # This file is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2, or (at your option) 7 | # any later version. 8 | 9 | # It is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with GNU Emacs; see the file COPYING. If not, write to 16 | # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 02111-1307, USA. 18 | 19 | # (Note: I do not consider works produced using these BFNN processing 20 | # tools to be derivative works of the tools, so they are NOT covered 21 | # by the GPL. However, I would appreciate it if you credited me if 22 | # appropriate in any documents you format using BFNN.) 23 | 24 | sub info_init { 25 | open(INFO,">$prefix.info"); 26 | print INFO <'); } 56 | 57 | sub info_ftpon { } sub info_endftpon { } 58 | sub info_ftpin { } sub info_endftpin { } 59 | sub info_docref { } sub info_enddocref { } 60 | sub info_courier { } sub info_endcourier { } 61 | sub info_newsgroup { } sub info_endnewsgroup { } 62 | sub info_ftpsilent { $info_ignore++; } 63 | sub info_endftpsilent { $info_ignore--; } 64 | 65 | sub info_text { 66 | return if $info_ignore; 67 | if ($info_status eq '') { 68 | $info_status= 'p'; 69 | } 70 | $info_para .= $_[0]; 71 | } 72 | 73 | sub info_tab { 74 | local ($n) = $_[0]-length($info_para); 75 | $info_para .= ' 'x$n if $n>0; 76 | } 77 | 78 | sub info_newline { 79 | return unless $info_status eq 'p'; 80 | print INFO &info_writepara; 81 | } 82 | 83 | sub info_writepara { 84 | local ($thisline, $thisword, $rest, $output); 85 | for (;;) { 86 | last unless $info_para =~ m/\S/; 87 | $thisline= $info_indentstring; 88 | for (;;) { 89 | last unless $info_para =~ m/^(\s*\S+)/; 90 | unless (length($1) + length($thisline) < 75 || 91 | length($thisline) == length($info_indentstring)) { 92 | last; 93 | } 94 | $thisline .= $1; 95 | $info_para= $'; 96 | } 97 | $info_para =~ s/^\s*//; 98 | $output.= $thisline."\n"; 99 | $info_indentstring= $info_nextindent; 100 | last unless length($info_para); 101 | } 102 | $info_status= ''; $info_para= ''; 103 | return $output; 104 | } 105 | 106 | sub info_endpara { 107 | return unless $info_status eq 'p'; 108 | print INFO &info_writepara; 109 | print INFO "\n"; 110 | } 111 | 112 | sub info_endheading { 113 | $info_para =~ s/\s*$//; 114 | print INFO "$info_para\n\n"; 115 | $info_status= ''; 116 | $info_para= ''; 117 | } 118 | 119 | sub info_endmajorheading { &info_endheading(@_); } 120 | sub info_endminorheading { &info_endheading(@_); } 121 | 122 | sub info_startverbatim { 123 | print INFO &info_writepara; 124 | } 125 | 126 | sub info_verbatim { 127 | print INFO $_[0],"\n"; 128 | } 129 | 130 | sub info_endverbatim { 131 | $info_status= $info_vstatus; 132 | } 133 | 134 | sub info_finish { 135 | close(INFO); 136 | } 137 | 138 | sub info_startindex { 139 | &info_endpara; 140 | $info_moredetail= ''; 141 | $info_status= ''; 142 | } 143 | 144 | sub info_endindex { 145 | print INFO "$info_moredetail\n" if length($info_moredetail); 146 | } 147 | 148 | sub info_endindexitem { 149 | $info_indentstring= sprintf("* %-17s ",$info_label.'::'); 150 | $info_nextindent= ' 'x20; 151 | local ($txt); 152 | $txt= &info_writepara; 153 | if ($info_main) { 154 | print INFO $label.$txt; 155 | $txt =~ s/^.{20}//; 156 | $info_moredetail.= $txt; 157 | } else { 158 | $info_moredetail.= $label.$txt; 159 | } 160 | $info_indentstring= $info_nextindent= ''; 161 | $info_status='p'; 162 | } 163 | 164 | sub info_startindexitem { 165 | print INFO "* Menu:\n" if $info_status eq ''; 166 | $info_status= ''; 167 | $info_label= $_[2]; 168 | $info_main= 0; 169 | } 170 | 171 | sub info_startindexmainitem { 172 | print INFO "* Menu:\n" if $info_status eq ''; 173 | $info_label= $_[2]; 174 | $info_main= 1; 175 | $info_moredetail .= "\n$_[2], "; 176 | $info_status= ''; 177 | } 178 | 179 | sub info_startindent { 180 | $info_istatus= $info_status; 181 | print INFO &info_writepara; 182 | $info_indentstring= " $info_indentstring"; 183 | $info_nextindent= " $info_nextindent"; 184 | } 185 | 186 | sub info_endindent { 187 | $info_indentstring =~ s/^ //; 188 | $info_nextindent =~ s/^ //; 189 | $info_status= $info_istatus; 190 | } 191 | 192 | sub info_startpackedlist { $info_plc=0; } 193 | sub info_endpackedlist { &info_newline if !$info_plc; } 194 | sub info_packeditem { 195 | &info_newline if !$info_plc; 196 | &info_tab($info_plc*40+5); 197 | $info_plc= !$info_plc; 198 | } 199 | 200 | sub info_startlist { 201 | $info_istatus= $info_status; 202 | print INFO &info_writepara; 203 | $info_indentstring= " $info_indentstring"; 204 | $info_nextindent= " $info_nextindent"; 205 | } 206 | 207 | sub info_endlist { 208 | $info_indentstring =~ s/^ //; 209 | $info_nextindent =~ s/^ //; 210 | $info_status= $info_lstatus; 211 | } 212 | 213 | sub info_item { 214 | &info_newline; 215 | $info_indentstring =~ s/ $/* /; 216 | } 217 | 218 | sub info_pageref { 219 | &info_text("*Note Question $_[1]:: \`"); 220 | } 221 | 222 | sub info_endpageref { 223 | &info_text("'"); 224 | } 225 | 226 | 1; 227 | -------------------------------------------------------------------------------- /FAQ/m-post.pl: -------------------------------------------------------------------------------- 1 | ## POST output 2 | # Copyright (C) 1993-1995 Ian Jackson. 3 | 4 | # This file is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2, or (at your option) 7 | # any later version. 8 | 9 | # It is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with GNU Emacs; see the file COPYING. If not, write to 16 | # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 02111-1307, USA. 18 | 19 | # (Note: I do not consider works produced using these BFNN processing 20 | # tools to be derivative works of the tools, so they are NOT covered 21 | # by the GPL. However, I would appreciate it if you credited me if 22 | # appropriate in any documents you format using BFNN.) 23 | 24 | sub post_init { 25 | open(POST,">$prefix.post"); 26 | } 27 | 28 | sub post_startmajorheading { 29 | print POST '='x79,"\n\n"; 30 | $post_status= 'h'; 31 | &post_text($_[0] ? "Section $_[0]. " : ''); 32 | } 33 | 34 | sub post_startminorheading { 35 | print POST '-'x77,"\n\n"; 36 | $post_status= 'h'; 37 | } 38 | 39 | sub post_italic { &post_text('*'); } 40 | sub post_enditalic { $post_para .= '*'; } 41 | 42 | sub post_email { &post_text('<'); } sub post_endemail { &post_text('>'); } 43 | 44 | sub post_ftpon { } sub post_endftpon { } 45 | sub post_ftpin { } sub post_endftpin { } 46 | sub post_docref { } sub post_enddocref { } 47 | sub post_courier { } sub post_endcourier { } 48 | sub post_newsgroup { } sub post_endnewsgroup { } 49 | sub post_ftpsilent { $post_ignore++; } 50 | sub post_endftpsilent { $post_ignore--; } 51 | 52 | sub post_text { 53 | return if $post_ignore; 54 | if ($post_status eq '') { 55 | $post_status= 'p'; 56 | } 57 | $post_para .= $_[0]; 58 | } 59 | 60 | sub post_tab { 61 | local ($n) = $_[0]-length($post_para); 62 | $post_para .= ' 'x$n if $n>0; 63 | } 64 | 65 | sub post_newline { 66 | return unless $post_status eq 'p'; 67 | &post_writepara; 68 | } 69 | 70 | sub post_writepara { 71 | local ($thisline, $thisword, $rest); 72 | for (;;) { 73 | last unless $post_para =~ m/\S/; 74 | $thisline= $post_indentstring; 75 | for (;;) { 76 | last unless $post_para =~ m/^(\s*\S+)/; 77 | unless (length($1) + length($thisline) < 75 || 78 | length($thisline) == length($post_indentstring)) { 79 | last; 80 | } 81 | $thisline .= $1; 82 | $post_para= $'; 83 | } 84 | $post_para =~ s/^\s*//; 85 | print POST $thisline,"\n"; 86 | $post_indentstring= $post_nextindent; 87 | last unless length($post_para); 88 | } 89 | $post_status= ''; $post_para= ''; 90 | } 91 | 92 | sub post_endpara { 93 | return unless $post_status eq 'p'; 94 | &post_writepara; 95 | print POST "\n"; 96 | } 97 | 98 | sub post_endheading { 99 | $post_para =~ s/\s*$//; 100 | print POST "$post_para\n\n"; 101 | $post_status= ''; 102 | $post_para= ''; 103 | } 104 | 105 | sub post_endmajorheading { &post_endheading(@_); } 106 | sub post_endminorheading { &post_endheading(@_); } 107 | 108 | sub post_startverbatim { 109 | $post_vstatus= $post_status; 110 | &post_writepara; 111 | } 112 | 113 | sub post_verbatim { 114 | print POST $_[0],"\n"; 115 | } 116 | 117 | sub post_endverbatim { 118 | $post_status= $post_vstatus; 119 | } 120 | 121 | sub post_finish { 122 | close(POST); 123 | } 124 | 125 | sub post_startindex { $post_status= ''; } 126 | sub post_endindex { $post_status= 'p'; } 127 | 128 | sub post_endindexitem { 129 | printf POST " %-11s %-.66s\n",$post_left,$post_para; 130 | $post_status= 'p'; 131 | $post_para= ''; 132 | } 133 | 134 | sub post_startindexitem { 135 | $post_left= $_[1]; 136 | } 137 | 138 | sub post_startindexmainitem { 139 | $post_left= $_[1]; 140 | print POST "\n" if $post_status eq 'p'; 141 | } 142 | 143 | sub post_startindent { 144 | $post_istatus= $post_status; 145 | &post_writepara; 146 | $post_indentstring= " $post_indentstring"; 147 | $post_nextindent= " $post_nextindent"; 148 | } 149 | 150 | sub post_endindent { 151 | $post_indentstring =~ s/^ //; 152 | $post_nextindent =~ s/^ //; 153 | $post_status= $post_istatus; 154 | } 155 | 156 | sub post_startpackedlist { $post_plc=0; } 157 | sub post_endpackedlist { &post_newline if !$post_plc; } 158 | sub post_packeditem { 159 | &post_newline if !$post_plc; 160 | &post_tab($post_plc*40+5); 161 | $post_plc= !$post_plc; 162 | } 163 | 164 | sub post_startlist { 165 | &post_endpara; 166 | $post_indentstring= " $post_indentstring"; 167 | $post_nextindent= " $post_nextindent"; 168 | } 169 | 170 | sub post_endlist { 171 | &post_endpara; 172 | $post_indentstring =~ s/^ //; 173 | $post_nextindent =~ s/^ //; 174 | } 175 | 176 | sub post_item { 177 | &post_newline; 178 | $post_indentstring =~ s/ $/* /; 179 | } 180 | 181 | sub post_pageref { 182 | &post_text("Q$_[1] \`"); 183 | } 184 | 185 | sub post_endpageref { 186 | &post_text("'"); 187 | } 188 | 189 | 1; 190 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = cilk2c runtime support examples doc FAQ 2 | EXTRA_DIST = THANKS bootstrap.sh 3 | 4 | all-check: 5 | $(MAKE) clean 6 | $(MAKE) check 7 | $(MAKE) clean 8 | $(MAKE) check CILKCFLAGS='-O2 -cilk-debug' 9 | $(MAKE) clean 10 | $(MAKE) check CILKCFLAGS='-O2 -cilk-profile' 11 | $(MAKE) clean 12 | $(MAKE) check CILKCFLAGS='-O2 -cilk-profile -cilk-debug' 13 | 14 | 15 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Changes since Cilk-5.3.2: 2 | * Put cilk system under subversion control, and got rid of almost all program-generated from the subversion system. 3 | 4 | * Get nondeterminator to work again. 5 | 6 | Changes since Cilk-5.3.1: 7 | 8 | * Support for MacOS X. 9 | 10 | * Fixed memory leak in runtime system. 11 | 12 | * cilk2c: accept C9X flexible arrays. 13 | 14 | Changes since Cilk-5.3: 15 | 16 | * Patched to use the unofficial gcc-2.96 that comes with redhat-7.0. 17 | 18 | * cilk2c: stricter typechecking for inlet calls. Do not apply usual 19 | call conversions. 20 | 21 | * Added support for libhoard. 22 | 23 | * cilk2c: fixed bug regarding function redeclarations. 24 | 25 | Changes since Cilk-5.2: 26 | 27 | * Cilk is now released under the GNU General Public License. 28 | 29 | * The `cilk' command now automates all stages of compilation 30 | and linking. Use `cilk -O2 hello.cilk -o hello' to compile 31 | a simple program. 32 | 33 | * Improved GNU/Linux support. cilk2c can now parse all Linux/glibc-2 include 34 | files. 35 | 36 | * INCOMPATIBLE CHANGE: header file cilk-compat.h is no longer required 37 | and it is not provided. 38 | 39 | * Fixed many bugs in cilk2c. 40 | 41 | * Cilk now always runs on top of POSIX threads. The Cilk-5.2 42 | distinction between threaded and process version has disappeared. 43 | 44 | * The GNU linker is no longer required. Cilk should run on 45 | any system that supports gcc, GNU make, and POSIX threads. 46 | 47 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This directory contains Cilk, a language for multithreaded parallel 2 | programming based on ANSI C. Cilk is designed for general-purpose 3 | parallel programming, but it is especially effective for exploiting 4 | dynamic, highly asynchronous parallelism. This release contains the 5 | Cilk compiler, the Cilk runtime system, and example programs. 6 | 7 | This release of Cilk is targeted at the computing community at large, 8 | and not only at parallel-computing specialists. We tried to make Cilk 9 | easy to install and to use. If you know the C language, you should be 10 | able to write simple parallel Cilk programs quickly. 11 | 12 | Cilk has been developed since 1994 at the MIT Laboratory for Computer 13 | Science by Prof. Charles E. Leiserson and his group. Besides being 14 | used for research and teaching, Cilk was the system used to code the 15 | three world-class chess programs *Tech, *Socrates, and Cilkchess. 16 | Over the years, implementations of Cilk have run on computers ranging 17 | from networks of Linux laptops to an 1824-nodes Intel Paragon. 18 | 19 | The current Cilk-5.3 release runs on symmetric multiprocessor (SMP) 20 | machines that support Posix threads, GNU make, and gcc. Cilk-5.3 was 21 | developed and tested mainly on GNU/Linux, but porting Cilk to other 22 | Unix systems where the GNU compilation tools are available should be 23 | quite easy. You can also run Cilk-5.3 on uniprocessor machines. This 24 | configuration is useful for program development and debugging, even 25 | though you will not get any parallel speedup. 26 | 27 | The doc/ directory contains the Cilk manual. The cilk2c/ and runtime/ 28 | directories contain the Cilk compiler and runtime system, 29 | respectively. The examples/ directory contains example programs. 30 | 31 | Check the RELEASE-NOTES for information about this release. 32 | 33 | SYSTEM REQUIREMENTS 34 | ------------------- 35 | 36 | In order to run Cilk, you need the following packages: 37 | 38 | * A recent version of gcc. Cilk-5.3 was tested with gcc-2.95, 39 | gcc-2.8.x and egcs-1.1. gcc-2.7.x does not work. 40 | 41 | * An implementation of POSIX threads. Cilk-5.3 was tested with 42 | LinuxThreads (glibc-2.1) on linux/386 and linux/powerpc, 43 | Solaris 2.6, and IRIX 6.5. 44 | 45 | * A recent version of GNU make. GNU make 3.77 is known to 46 | work. 47 | 48 | * The GNU linker is desirable (although not required). 49 | Cilk can be compiled as a shared libraries if the GNU linker 50 | is available. 51 | 52 | The following processor families are supported: 53 | 54 | * Intel IA-32. (tested on Pentium, Pentium II, and Pentium III) 55 | * SPARC. (tested on UltraSPARC-I) 56 | * PowerPC. (tested on PowerPC 750 aka G3) 57 | * Alpha. (tested on 21264) 58 | * MIPS. (tested on R10000) 59 | * Intel IA-64. 60 | 61 | Porting to other architectures requires a few lines of assembly code 62 | to implement memory barriers and mutual-exclusion locks. 63 | 64 | BUILDING FROM SCRATCH 65 | --------------------- 66 | 67 | If you choose to build Cilk straight out of the subversion repository, 68 | you will find that certain files are not present. These files include 69 | aclocal.m4 70 | configure.in 71 | and many Makefile.in files in various directories. 72 | configure 73 | 74 | To build those files, you will need aclocal, automake, and autoconf.I 75 | made this work on a redhat 7.3. I made it work with automake 1.6.3-3 76 | and autoconf-2.57-2 (both from rawhide.) 77 | automake-1.4p5-4 doesn't work, but automake-1.6.3-3 with autoconf-2.53-8 seems OK. 78 | 79 | You do this: 80 | 81 | aclocal 82 | automake 83 | autoconf 84 | ./configure CFLAGS="-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200809L" --disable-static 85 | make 86 | 87 | COPYRIGHT 88 | --------- 89 | 90 | Copyright (c) 2000 Massachusetts Institute of Technology 91 | Copyright (c) 2000 Matteo Frigo 92 | Portions of cilk2c Copyright (c) 1989, 1990 James A. Roskind 93 | 94 | 95 | LICENSE 96 | ------- 97 | 98 | Cilk is distributed under the terms of the GNU General Public License. 99 | See file COPYING for details. 100 | 101 | 102 | CONTACTS 103 | -------- 104 | 105 | For new releases, documentation, and up-to-date information, please 106 | refer to 107 | 108 | http://supertech.lcs.mit.edu/cilk 109 | 110 | 111 | Cilk is currently maintained by Matteo Frigo . 112 | Please send email to cilk-support@lists.sourceforge.net for 113 | suggestions, bug reports, and questions about Cilk. 114 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | These organizations donated computer time: 2 | 3 | * Massachusetts Institute of Technology (4-way Pentium Pro, Alpha 21264) 4 | * Technical University, Vienna (Origin 2000) 5 | * Biomedin, s.r.l. (Linux PowerPC) 6 | * Prosa/Linuxcare (2-way Pentium II) 7 | * Sourceforge (4-way IA-64) 8 | 9 | These people sent suggestions and/or bug reports for Cilk-5.3: 10 | 11 | * Eyal Baruch 12 | * Gianluca Moro 13 | * Keith Randall 14 | * Geoffrey Irving 15 | * Simone Severini 16 | 17 | The Cilk project is supported in part by NSF Grant E1A-9975036. 18 | Previous support was provided in part by DARPA Grant F30602-97-1-0270. 19 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | autoreconf --verbose --install --symlink --force 2 | -------------------------------------------------------------------------------- /cilk2c/.indent.pro: -------------------------------------------------------------------------------- 1 | -kr -cs -i5 -sc -sob -cli4 -TNode -TSueType -TGeneric -TList -TFILE -TContect -TDeclKind -TOutputContext -TScope -TSymbolTable -TTableType -TConflictProc -TShadowProc -TExitscopeProc -TVersionType -TSUEtype -TConstNode -TidNode -TbinopNode -TunaryNode -TcastNode -TcommaNode -TternaryNode -TarrayNode -TcallNode -TinitializerNode -TimplicitcastNode -TlabelNode -TSwitchNode -TCaseNode -TDefaultNode -TIfNode -TIfElseNode -TWhileNode -TDoNode -TForNode -TGotoNode -TContinueNode -TBreakNode -TReturnNode -TBlockNode -TprimNode -TtdefNode -TptrNode -TadclNode -TfdclNode -TsdclNode -TudclNode -TedclNode -TdeclNode -TattribNode -TprocNode -TtextNode -TasmNode -TasmargNode -TspawnNode -TsyncNode -TinletcallNode -TresumeNode -TabortNode -TdoublereturnNode -TonabortNode -TsynchedNode -TspawncounterNode -TCoord -TFlowValue -TListMarker -TBool -TSymbol -TTypeQual -------------------------------------------------------------------------------- /cilk2c/BUGS: -------------------------------------------------------------------------------- 1 | - If the type of the return argument and the return type of the procedure 2 | are not the same size, bad things happen. 3 | 4 | - incomplete array declarations don't work correctly yet. For 5 | instance, the code 6 | 7 | int a[] = {1,2,3}; 8 | 9 | won't compile correctly inside a cilk procedure. If you add the 10 | array dimension, then everything works fine, as in 11 | 12 | int a[3] = {1,2,3}; 13 | 14 | - cilk2c doesn't allow variables defined as "const" in array dimension 15 | declarations. The following code compiles smoothly with gcc: 16 | 17 | const int x = 17; 18 | void foo() { 19 | int y[x][x]; 20 | } 21 | 22 | However, cilk2c doesn't allow it. Instead, you must use a define: 23 | 24 | #define x 17 25 | void foo() { 26 | int y[x][x]; 27 | } 28 | 29 | 30 | - No warning for multi-character character constants. 31 | 32 | - Cilk2c sometimes generates code that causes gcc to complain about 33 | a possibly uninitialized use of a variable. It happens in the 34 | following situation: 35 | 36 | int x; 37 | for(...) { 38 | spawn foo(); 39 | x = 7; 40 | } 41 | 42 | Dataflow analysis determines that x might be dirty before the spawn, 43 | and therefore puts a _frame->x = x; instruction before the spawn as 44 | part of the state saving statements. However, gcc realizes (correctly) 45 | that this is a use of an uninitialized variable. However, since we 46 | are only saving a variable whose restored value will never be used, 47 | we are OK. It would be nice to come up with some way of convincing 48 | gcc not to issue such a warning. 49 | 50 | - Implicit type conversion in return statements doesn't work correctly. 51 | In the following code: 52 | 53 | cilk float foo(void) 54 | { 55 | int i; 56 | i = spawn fib(20); 57 | sync; 58 | return i; 59 | } 60 | 61 | foo may return an invalid value to its parent (the variable i may be 62 | memcpy()'d into the receiver of its parent without being type converted 63 | to a float). To avoid this problem, use a typecast in your return 64 | statement: 65 | 66 | return (float)i; 67 | 68 | 69 | MINOR BUGS - These don't really need to be fixed, but it would be nice if 70 | they were. 71 | 72 | - cilk2c doesn't check printf format strings against printf's other 73 | arguments. Therefore, gcc (which does such a check) gives a warning 74 | when it compiles the code. 75 | 76 | - If a procedure has no spawns in it, we don't need to generate a slow 77 | version for it (or signature, for that matter). In fact, we may not 78 | even need to generate a frame. Note that some parts of the frame may 79 | be required for critical path measurements, etc. 80 | 81 | - The '=' in a spawn statement doesn't do any assignment conversion. 82 | It would be nice if the following code would compile: 83 | 84 | cilk float foo(); 85 | cilk void bar() { 86 | int x; 87 | x = spawn foo(); 88 | } 89 | 90 | We could compile the spawn by using C's automatic assignment conversion 91 | as follows: 92 | 93 | int _tmp; 94 | PUSH_FRAME(...); 95 | _tmp = spawn foo(); 96 | XPOP_FRAME_RESULT(_tmp, ...); 97 | x = _tmp; 98 | 99 | Currently, the type of _tmp is the type of the spawned function, not 100 | of the receiver. This should be reversed. 101 | 102 | - Strange bug: Defining a cilk-procedure prototype in a .h file that 103 | is included in an .cilk file produces a cilk2c error message: 104 | 105 | .h: cilk void fun(...); 106 | 107 | .cilk: #include ".h" 108 | 109 | leads to the following cilk2c message: 110 | 111 | .h:1: expecting a function definition 112 | .h:1: parse error 113 | 114 | - Volker 115 | 116 | Note: This is a "feature", not a bug. Cilk extension processing 117 | is turned off in .h files to be compatible with system .h files 118 | which have Cilk keywords like `abort' in them. Put your Cilk 119 | declarations in .cilkh files. -Keith 120 | 121 | - cilk2c doesn't like the first line - you must add more brackets, as in 122 | the second line, to get it through cilk2c. 123 | 124 | char foo[2][6] = {"hello", "xxxxx"}; 125 | char foo[2][6] = {{"hello"}, {"xxxxx"}}; 126 | 127 | - cilk2c doesn't allow declarations like 128 | 129 | extern int foo(int a[][]); 130 | 131 | I'm not sure if such a declaration is ANSI or not, but it looks 132 | fishy. However, all compilers accept it, so it may be ANSI. 133 | 134 | - cilk2c doesn't allow non-constant array initializers 135 | 136 | void foo (int a) 137 | { 138 | int b[1] = {a}; 139 | } 140 | 141 | Non-constant array initializers are a gcc extension - they are not ANSI. 142 | 143 | - cilk2c doesn't think constant "long long" expressions are constant. For 144 | example, for the code 145 | 146 | long long a[1] = { 10LL }; 147 | 148 | cilk2c complains that the initializer is not constant. Removing one of 149 | the Ls fixes the complaint. 150 | 151 | - not all forms of spawning a procedure via a pointer are supported. For 152 | example, the code 153 | 154 | void f(void (*g)()) 155 | { 156 | g(); 157 | (*g)(); 158 | } 159 | 160 | compiles with an ANSI-C compiler, but the cilk code 161 | 162 | #include 163 | cilk void f(cilk void (*g)()) 164 | { 165 | spawn g(); 166 | spawn (*g)(); 167 | sync; 168 | } 169 | 170 | gives a parse error in the `spawn (*g)()' statement. You can spawn 171 | a cilk procedure through a procedure pointer, but not through a 172 | dereferenced procedure pointer. 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /cilk2c/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = cilk2c 2 | 3 | cilk2c_SOURCES = analyze.c ast.c complex-types.c constexpr.c \ 4 | container.c conversions.c dataflow.c elide.c initializer.c list.c \ 5 | main.c operators.c output.c print-ast.c procedure.c profile.c \ 6 | simplify.c sideeffects.c sem-check.c strings.c sue.c symbol.c \ 7 | transform.c type.c type2.c typequal.c verify-parse.c warning.c gbuf.h \ 8 | gbuf.c ast.h basics.h config.h conversions.h dataflow.h heap.h \ 9 | initializer.h list.h operators.h symbol.h type.h typequal.h ANSI-C.y \ 10 | c4.l hint.c astModify.h astModify.c stringParse.h stringParse.c \ 11 | wildcard.h wildcard.c astEquals.h astEquals.c wildcardTable.h \ 12 | wildcardTable.c testEquals.h testEquals.c atmTransform.h \ 13 | atmTransform.c 14 | 15 | 16 | AM_YFLAGS = -d 17 | 18 | EXTRA_DIST = ANSI-C.c ANSI-C.h BUGS astgen .indent.pro 19 | $(cilk2c_OBJECTS) : ANSI-C.c ANSI-C.h 20 | -------------------------------------------------------------------------------- /cilk2c/astEquals.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (c) 1994-2003 Massachusetts Institute of Technology 3 | * Copyright (c) 2003 Jim Sukha 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | 21 | #ifndef _AST_EQUALS_H 22 | #define _AST_EQUALS_H 23 | 24 | 25 | #include "astModify.h" 26 | 27 | /*** Note: the behavior of these functions 28 | * on trees has been tested on expressions 29 | * and on most types of statements. However, 30 | * comparisons on declarations may not work. 31 | * 32 | * There are still questions remaining in the 33 | * Equals function about which fields for each 34 | * node to compare and which ones to ignore. 35 | * 36 | * For ex. an idNode has a decl field which is 37 | * currently being ignored. 38 | * Other nodes have fields which are filled in by 39 | * the semantic-checker (ex. a binop has a Type field). 40 | * These fields are also currently being ignored. 41 | * 42 | * 43 | * The test cases for these functions in testEquals.c 44 | * obtained the AST from the functions in stringParse.c 45 | * These AST's are often incomplete. Therefore, 46 | * it is more likely that these functions will 47 | * consider two things equal that one might consider 48 | * unequal, rather than the other way around. 49 | * 50 | * 51 | * In short - if you use these functions, be prepared to modify 52 | * them when things don't work... (especially the Equal___ functions 53 | * for each node) 54 | * 55 | * 56 | * 57 | * Things which are known to be odd? 58 | * 59 | * 1. structs - putting fields in different order 60 | * struct {int x; double y;} and struct {double y; int x;} 61 | * are different. 62 | * 63 | * 64 | * 65 | ***/ 66 | 67 | /*****************************************************************************/ 68 | 69 | /* Returns TRUE if S1 and S2 are equal strings (or both NULL) */ 70 | Bool EqualStrings(const char *s1, const char *s2); 71 | 72 | 73 | /* Returns TRUE if u1 and u2 have the same typ 74 | fields, or if they both NULL */ 75 | Bool EqualTypeNodes(Node *u1, Node *u2); 76 | 77 | 78 | /* Returns TRUE if n1 and n2 are equal nodes. n1 and n2 79 | can still have different children however. (i.e. any field 80 | which is labeled as ChildNode or ChildList can still be 81 | different). */ 82 | Bool EqualNodes(Node *n1, Node *n2); 83 | 84 | 85 | /* Returns TRUE if n1 and n2 represent the same syntax tree 86 | * Not every field is used in the equality comparison. 87 | * For example, the Coord field for nodes is ignored. 88 | * Only fields which make the node syntactically different 89 | * compared. 90 | */ 91 | Bool EqualAST(Node *n1, Node *n2); 92 | 93 | /* Same function as EqualAST, but takes in a list of nodes */ 94 | GLOBAL Bool EqualASTList(List *l1, List *l2); 95 | 96 | 97 | 98 | /* Returns TRUE if tree n1 contains n2. 99 | If either tree is NULL, returns FALSE */ 100 | Bool ContainsAST(Node *n1, Node *n2); 101 | 102 | /* Returns a pointer to the subtree of n1 which 103 | matches n2, or NULL if no such subtree is found. */ 104 | Node* ContainsSubtree(Node *n1, Node *n2); 105 | 106 | /* Same as previous two, except that all matches 107 | are returned. The list is stored in a post order, with 108 | the deepest matches in the tree coming first. */ 109 | List* GetAllMatchingSubtrees(Node *n1, Node *n2); 110 | 111 | /* Searches N1 for a subtree matching N2, and replaces it a copy of the 112 | REPLACEMENT tree. Returns TRUE if a replacement was made, FALSE otherwise. */ 113 | Bool ReplaceSyntaxSubtree(Node *n1, Node *n2, Node *replacement); 114 | 115 | /* Searches N1 for all subtrees matching N2, and replaces each with a copy of 116 | REPLACEMENT tree. Returns the number of replacements made. */ 117 | int ReplaceAllMatchingSubtrees(Node *original, Node *n2, Node *replacement); 118 | 119 | 120 | /*int ReplaceAllMatchingSubtreesInProgram(List *original, Node *match, Node *replacement);*/ 121 | 122 | 123 | Bool MatchReplacePatternTree(Node *original, Node *pattern, Node *replacement); 124 | 125 | GLOBAL Bool PatternEqualsAST(Node *original, Node *pattern); 126 | 127 | 128 | /* Attempts to match ORIGINAL to the specified PATTERN. The matching uses 129 | any wildcard values that were stored in wcTable. If the function 130 | returns TRUE, the appropriate wildcard values to satisfy the pattern 131 | match are stored in the table. 132 | The function requires wcTable has been initialized. 133 | */ 134 | GLOBAL Bool PatternMatch(Node *original, Node *pattern, WildcardTable *wcTable); 135 | 136 | /* Attempts to match ORIGINAL_TREE to the pattern string. If there is a match, 137 | originalTree is modified to reflect the change. Otherwise, returns NULL */ 138 | Node* MatchReplace(Node *originalTree, char *pattern, char *replacement); 139 | 140 | 141 | #endif /* ifndef _AST_EQUALS_H */ 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /cilk2c/astModify.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (c) 1994-2003 Massachusetts Institute of Technology 3 | * Copyright (c) 2003 Jim Sukha 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | 21 | #include "astModify.h" 22 | 23 | 24 | GLOBAL Node* CopyAST(Node *n) { 25 | return NodeCopy(n, SubtreeExact); 26 | } 27 | 28 | 29 | /* Replaces the node N1 points to with a copy of 30 | * the tree N2 points to. Requires that N1 and 31 | * N2 are both not NULL */ 32 | GLOBAL void ReplaceAST(Node *n1, Node *n2) { 33 | if (n1 && n2) { 34 | *n1 = *CopyAST(n2); 35 | } 36 | } 37 | 38 | 39 | 40 | /* Helper functions used for the ASTWALKTWO macro. */ 41 | 42 | PRIVATE void FillWildcardsFromTableFail(WildcardTable *UNUSED(wcTable)) { 43 | return; 44 | } 45 | 46 | PRIVATE Bool FillWildcardsFromTableContinue(Node *UNUSED(patternTree), 47 | Node *UNUSED(placeHolder), 48 | WildcardTable *UNUSED(wcTable)) { 49 | return TRUE; 50 | } 51 | 52 | 53 | PRIVATE void FillWildcardsFromTableHelper(Node *patternTree, 54 | Node *UNUSED(placeHolder), 55 | WildcardTable *wcTable) { 56 | Node *lookupValue; 57 | const char* wcName; 58 | 59 | if (patternTree) { 60 | 61 | if (IsWildcard(patternTree)) { 62 | wcName = GetWildcardName(patternTree); 63 | /* printf("Looking for wildcard with name %s \n", wcName);*/ 64 | lookupValue = LookupWildcard(wcTable, wcName); 65 | if (!lookupValue) { 66 | printf("Error: wildcard not found. \n"); 67 | /* PrintWildcardTable(stdout, wcTable);*/ 68 | /* printf("Printed table. \n");*/ 69 | } 70 | else { 71 | 72 | if (IsDecl(patternTree)) { 73 | patternTree->u.decl.name = lookupValue->u.id.text; 74 | patternTree->wTyp = NonWildcard; 75 | FillWildcardsFromTableHelper(patternTree, placeHolder, wcTable); 76 | } 77 | else { 78 | /* printf("Getting here to replace pattern tree:. \n");*/ 79 | /* PrintNode(stdout, patternTree, 4);*/ 80 | /* printf("\n");*/ 81 | 82 | ReplaceAST(patternTree,lookupValue); 83 | patternTree->wTyp = NonWildcard; 84 | } 85 | } 86 | } 87 | else { 88 | ASTWALKTWO(patternTree, placeHolder, wcTable, 89 | FillWildcardsFromTableHelper, 90 | FillWildcardsFromTableContinue, 91 | FillWildcardsFromTableFail); 92 | } 93 | 94 | } 95 | } 96 | 97 | 98 | 99 | /* Takes in PATTERN_TREE (an AST with wildcards) and a WildcardTable. 100 | * The tree is traversed, and the wildcards are filled in using 101 | * values stored in the table. 102 | * 103 | * 104 | */ 105 | GLOBAL void FillWildcardsFromTable(Node *patternTree, WildcardTable *wcTable) { 106 | FillWildcardsFromTableHelper(patternTree, NULL, wcTable); 107 | } 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /cilk2c/atmTransform.h: -------------------------------------------------------------------------------- 1 | #ifndef ATM_TRANSFORM_H 2 | #define ATM_TRANSFORM_H 3 | 4 | /* atmTransform.h*/ 5 | 6 | 7 | GLOBAL Node *PreSimplify(Node *node); 8 | GLOBAL List *PreSimplifyList(List *list); 9 | GLOBAL List *AtomicTransformProgram(List *list); 10 | 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /cilk2c/config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | * Copyright (c) 1994-2002 MIT Laboratory for Computer Science 9 | * Copyright (c) 2000 Matteo Frigo 10 | * Copyright (c) 2002 Bradley C. Kuszmaul 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | *************************************************************************/ 26 | #ifndef _CONFIG_H_ 27 | #define _CONFIG_H_ 28 | 29 | FILE_IDENTITY(config_ident, 30 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/config.h $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 31 | 32 | #include 33 | 34 | /* expected suffixes for input and output files */ 35 | #define INPUT_SUFFIX ".cilk" 36 | #define OUTPUT_SUFFIX ".c" 37 | 38 | /* preprocessor command lines */ 39 | /* #define DEFAULT_PREPROC "gcc -E -xc"*/ 40 | /* #define ANSI_PREPROC "gcc -E -ansi -xc"*/ 41 | 42 | /* maximum number of nested block scopes */ 43 | #define MAX_NESTED_SCOPES 100 44 | 45 | /* default warning level */ 46 | #define WARNING_LEVEL 4 47 | 48 | #if 0 49 | /* These DEFAULT_... symbols are obsolete. The default signedness for all 50 | * types but char is specified by ANSI C, and the logic in FinishPrimType 51 | * is hard-coded to follow ANSI. For char, c-to-c treats unspecified chars 52 | * as distinct types from signed char and unsigned char, so no default is 53 | * required. -- rcm */ 54 | /* basic types w/o signed or unsigned default to: */ 55 | #define DEFAULT_INT Sint 56 | #define DEFAULT_SHORT Sshort 57 | #define DEFAULT_LONG Slong 58 | #define DEFAULT_CHAR Schar 59 | #endif 60 | 61 | /* host types used hold values of each target type; 62 | i.e. TARGET_INT resolves to the type of the host used to 63 | represent ints on the target */ 64 | typedef char TARGET_CHAR; 65 | typedef int TARGET_INT; 66 | typedef unsigned int TARGET_UINT; 67 | typedef long TARGET_LONG; 68 | typedef unsigned long TARGET_ULONG; 69 | 70 | /* target limits */ 71 | #define TARGET_MAX_UCHAR 256 72 | #define TARGET_MAX_INT INT_MAX 73 | #define TARGET_MAX_UINT UINT_MAX 74 | #define TARGET_MAX_LONG LONG_MAX 75 | #define TARGET_MAX_ULONG ULONG_MAX 76 | 77 | /* Basic sizes and alignments */ 78 | #define CHAR_SIZE sizeof(char) 79 | #define CHAR_ALIGN CHAR_SIZE 80 | 81 | #define SHORT_SIZE sizeof(short) 82 | #define SHORT_ALIGN SHORT_SIZE 83 | 84 | #define INT_SIZE sizeof(int) 85 | #define INT_ALIGN INT_SIZE 86 | 87 | #define FLOAT_SIZE sizeof(float) 88 | #define FLOAT_ALIGN FLOAT_SIZE 89 | 90 | #define DOUBLE_SIZE sizeof(double) 91 | #define DOUBLE_ALIGN DOUBLE_SIZE 92 | 93 | #ifdef __GNUC__ 94 | #define LONGDOUBLE_SIZE sizeof(long double) 95 | #else 96 | #define LONGDOUBLE_SIZE sizeof(double) 97 | #endif 98 | #define LONGDOUBLE_ALIGN LONGDOUBLE_SIZE 99 | 100 | #define LONG_SIZE sizeof(long) 101 | #define LONG_ALIGN LONG_SIZE 102 | 103 | #ifdef __GNUC__ 104 | #define LONGLONG_SIZE sizeof(long long) 105 | #else 106 | #define LONGLONG_SIZE sizeof(long) 107 | #endif 108 | #define LONGLONG_ALIGN LONGLONG_SIZE 109 | 110 | #define POINTER_SIZE sizeof(void *) 111 | #define POINTER_ALIGN POINTER_SIZE 112 | 113 | #define BYTE_LENGTH CHAR_BIT 114 | #define WORD_LENGTH (INT_SIZE * BYTE_LENGTH) 115 | 116 | #endif /* ifndef _CONFIG_H_ */ 117 | -------------------------------------------------------------------------------- /cilk2c/container.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2000 Matteo Frigo 12 | * Copyright (c) 2002 Bradley C. Kuszmaul 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #include "ast.h" 31 | FILE_IDENTITY(ident, 32 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/container.c $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 33 | 34 | typedef struct { 35 | NodeType typ; 36 | List *cases; 37 | List *exits; 38 | } Container; 39 | 40 | PRIVATE Container stack[MAX_SCOPE_DEPTH]; 41 | PRIVATE Container *top = NULL; 42 | 43 | GLOBAL void PushContainer(NodeType typ) 44 | { 45 | if (top == NULL) 46 | top = stack; 47 | else 48 | top++; 49 | 50 | top->typ = typ; 51 | top->cases = top->exits = NULL; 52 | } 53 | 54 | GLOBAL Node *PopContainer(Node *n) 55 | { 56 | ListMarker marker; 57 | Node *containee; 58 | 59 | assert(n->typ == top->typ); 60 | assert(top != NULL); 61 | 62 | IterateList(&marker, top->exits); 63 | while (NextOnList(&marker, (GenericREF) & containee)) { 64 | switch (containee->typ) { 65 | case Break: 66 | containee->u.Break.container = n; 67 | break; 68 | case Continue: 69 | assert(n->typ != Switch); 70 | containee->u.Continue.container = n; 71 | break; 72 | default: 73 | FAIL("unexpected containee type"); 74 | } 75 | } 76 | 77 | IterateList(&marker, top->cases); 78 | while (NextOnList(&marker, (GenericREF) & containee)) { 79 | assert(n->typ == Switch); 80 | switch (containee->typ) { 81 | case Case: 82 | containee->u.Case.container = n; 83 | break; 84 | case Default: 85 | containee->u.Default.container = n; 86 | n->u.Switch.has_default = TRUE; 87 | break; 88 | default: 89 | FAIL("unexpected containee type"); 90 | } 91 | } 92 | 93 | /* store cases list into enclosing switch node */ 94 | if (n->typ == Switch) 95 | n->u.Switch.cases = top->cases; 96 | 97 | /* memory leak: exits list */ 98 | 99 | if (top == stack) 100 | top = NULL; 101 | else 102 | top--; 103 | 104 | return (n); 105 | } 106 | 107 | GLOBAL Node *AddContainee(Node *c) 108 | { 109 | Container *container; 110 | 111 | if (top == NULL) { 112 | switch (c->typ) { 113 | case Case: 114 | case Default: 115 | goto NoSwitch; 116 | case Break: 117 | SyntaxErrorCoord(c->coord, 118 | "no enclosing loop or switch statement found"); 119 | return (c); 120 | case Continue: 121 | goto NoLoop; 122 | default: 123 | break; 124 | } 125 | } 126 | switch (c->typ) { 127 | case Case: 128 | case Default: 129 | for (container = top; container >= stack; container--) { 130 | if (container->typ == Switch) { 131 | if (container->cases == NULL) 132 | container->cases = MakeNewList(c); 133 | else 134 | AppendItem(container->cases, c); 135 | return (c); 136 | } 137 | } 138 | NoSwitch: 139 | /* didn't find an enclosing switch... */ 140 | SyntaxErrorCoord(c->coord, "no enclosing switch statement"); 141 | break; 142 | case Break: 143 | if (top->exits == NULL) 144 | top->exits = MakeNewList(c); 145 | else 146 | AppendItem(top->exits, c); 147 | break; 148 | case Continue: 149 | for (container = top; container >= stack; container--) { 150 | if (container->typ != Switch) { 151 | if (container->exits == NULL) 152 | container->exits = MakeNewList(c); 153 | else 154 | AppendItem(container->exits, c); 155 | return (c); 156 | } 157 | } 158 | NoLoop: 159 | /* didn't find an enclosing loop... */ 160 | SyntaxErrorCoord(c->coord, "no enclosing loop"); 161 | break; 162 | default: 163 | FAIL("unexpected node type"); 164 | } 165 | return (c); 166 | } 167 | -------------------------------------------------------------------------------- /cilk2c/conversions.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2000 Matteo Frigo 12 | * Copyright (c) 2002 Bradley C. Kuszmaul 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #ifndef _CONVERSIONS_H_ 31 | #define _CONVERSIONS_H_ 32 | FILE_IDENTITY(conversions_h_ident, 33 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/conversions.h $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 34 | 35 | 36 | GLOBAL Node *UsualUnaryConversions(Node *node, Bool f_to_d); 37 | GLOBAL Node *UsualUnaryConversionType(Node *type); 38 | GLOBAL void UsualBinaryConversions(Node **node1p, Node **node2p); 39 | GLOBAL void UsualPointerConversions(Node **node1p, Node **node2p, Bool allow_void_or_zero); 40 | GLOBAL Node *AssignmentConversions(Node *expr, Node *to_type); 41 | GLOBAL Node *CallConversions(Node *expr, Node *to_type); 42 | GLOBAL Node *ReturnConversions(Node *expr, Node *to_type); 43 | GLOBAL Node *CastConversions(Node *expr, Node *to_type); 44 | GLOBAL Node *ConditionalConversions(Node **truep, Node **falsep); 45 | 46 | #endif /* _CONVERSIONS_H_ */ 47 | -------------------------------------------------------------------------------- /cilk2c/dataflow.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Rob Miller 6 | * 7 | *************************************************************************/ 8 | /* 9 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 10 | * Copyright (c) 2000 Matteo Frigo 11 | * Copyright (c) 2002 Bradley C. Kuszmaul 12 | * 13 | * This program is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program; if not, write to the Free Software 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | * 27 | */ 28 | 29 | #ifndef _DATAFLOW_H_ 30 | #define _DATAFLOW_H_ 31 | 32 | FILE_IDENTITY(dataflow_h_ident, 33 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/dataflow.h $ $LastChangedBy: bradley $ $Rev: 2672 $ $Date: 2005-12-20 13:30:02 -0500 (Tue, 20 Dec 2005) $"); 34 | 35 | typedef unsigned long BitVector; 36 | #define MAX_BITVECTOR_LENGTH (sizeof(BitVector) * CHAR_BIT) 37 | 38 | typedef struct { 39 | Bool undefined; 40 | union { 41 | BitVector bitvector; 42 | List *list; 43 | Generic *ptr; 44 | } u; 45 | } FlowValue; 46 | 47 | typedef struct { 48 | /* Structures used in analysis */ 49 | FlowValue gen, kill; 50 | 51 | /* Analysis results */ 52 | List *livevars; 53 | List *dirtyvars; 54 | } Analysis; 55 | 56 | typedef enum { 57 | Backwards, 58 | Forwards 59 | } Direction; 60 | 61 | typedef enum { 62 | EntryPoint, 63 | ExitPoint 64 | } Point; 65 | 66 | typedef FlowValue (*MeetOp) (FlowValue, FlowValue); 67 | typedef FlowValue (*TransOp) (Node *, FlowValue, Point, Bool); 68 | typedef Bool (*EqualOp) (FlowValue, FlowValue); 69 | 70 | /* from dataflow.c */ 71 | GLOBAL void IterateDataFlow( 72 | Node *root, /* root node */ 73 | FlowValue init, /* input value for root node */ 74 | Direction dir, /* direction */ 75 | MeetOp meet, /* meet operation */ 76 | EqualOp equal, /* equality operation */ 77 | TransOp trans /* transfer function */ 78 | ); 79 | 80 | /* from analyze.c */ 81 | GLOBAL List *RegisterVariables(Node *node, List *vars); 82 | 83 | GLOBAL void PV(List *vars); 84 | GLOBAL int PrintVariables(GBUF *,List *vars); 85 | GLOBAL int PrintAnalysis(GBUF *,Node *node); 86 | 87 | GLOBAL void AnalyzeLiveVariables(Node *root, List *vars); 88 | GLOBAL void AnalyzeReturnFlow(Node *root); 89 | 90 | GLOBAL void AnalyzeProgram(List *program); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /cilk2c/gbuf.c: -------------------------------------------------------------------------------- 1 | #include 2 | //#include 3 | //#include 4 | //#include 5 | //#include 6 | 7 | GLOBAL int gbprintf(GBUF *gb, const char *format, ...) { 8 | int r; 9 | va_list ap; 10 | va_start(ap, format); 11 | r=gb->vfprintf_fun(gb->state, format, ap); 12 | va_end(ap); 13 | return r; 14 | } 15 | GLOBAL int gbputs (const char *string, GBUF *gb) { 16 | return gb->fputs_fun(string, gb->state); 17 | } 18 | 19 | /********************************************* 20 | * functions for creating output to a string. 21 | *********************************************/ 22 | 23 | struct mbuffer { 24 | char *string; 25 | char *tail; 26 | int n_chars_left; /* Number of characters left in the buffer (including the tailing \0) */ 27 | }; 28 | 29 | PRIVATE void init_mbuffer (char *array, int arraysize, struct mbuffer *b) { 30 | b->string=array; 31 | b->tail =array; 32 | assert(arraysize>0); 33 | b->n_chars_left=arraysize; 34 | array[0]=0; 35 | } 36 | 37 | /* Act like fputs. */ 38 | PRIVATE int add_string_to_mbuffer(const char *string, void *state) { 39 | struct mbuffer *b=state; 40 | int l = strlen(string); 41 | if (l+1>b->n_chars_left) return -1; 42 | strcpy(b->tail, string); /* Don't use strncpy, because that fills in the whole tail of the dest with nulls. Slow and error prone. */ 43 | b->tail+=l; 44 | b->n_chars_left-=l; 45 | return l; 46 | } 47 | 48 | PRIVATE void free_mbuffer (void *s) { 49 | free(s); 50 | } 51 | 52 | GLOBAL int vfprintf_to_mbuffer (void *state, const char *format, va_list ap) { 53 | struct mbuffer *mb = state; 54 | int oldavail = mb->n_chars_left; 55 | int n_written = vsnprintf(mb->tail, oldavail, format, ap); 56 | if (n_written>=oldavail || n_written<0) { 57 | mb->tail[oldavail-1]=0; 58 | mb->tail+=oldavail; 59 | mb->n_chars_left=0; 60 | return -1; 61 | } else { 62 | mb->tail+=n_written; 63 | mb->n_chars_left-=n_written; 64 | return n_written; 65 | } 66 | } 67 | 68 | 69 | GLOBAL GBUF* make_string_gbuf (char *array, int arraysize) { 70 | GBUF *result = malloc(sizeof(*result)); 71 | struct mbuffer *mb = malloc(sizeof(*mb)); 72 | result->state = mb; 73 | result->fputs_fun = add_string_to_mbuffer; 74 | result->vfprintf_fun = vfprintf_to_mbuffer; 75 | result->free_state_fun = free_mbuffer; 76 | init_mbuffer(array, arraysize, mb); 77 | return result; 78 | } 79 | 80 | PRIVATE int add_string_to_file (const char *string, void *state) { 81 | FILE *f=state; 82 | return fputs(string, f); 83 | } 84 | 85 | PRIVATE int vfprintf_to_file (void *state, const char *format, va_list ap) { 86 | FILE *stream=state; 87 | return vfprintf(stream, format, ap); 88 | } 89 | 90 | GLOBAL GBUF* make_file_gbuf (FILE *f) { 91 | GBUF *result = malloc(sizeof(*result)); 92 | result->state = f; 93 | result->fputs_fun = add_string_to_file; 94 | result->vfprintf_fun = vfprintf_to_file; 95 | result->free_state_fun = 0; 96 | return result; 97 | } 98 | 99 | GLOBAL void free_gbuf (GBUF *gb) { 100 | if (gb->free_state_fun) gb->free_state_fun(gb->state); 101 | free(gb); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /cilk2c/gbuf.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct generalized_buffer { 5 | void *state; 6 | int (*fputs_fun)(const char *string, void *state); 7 | int (*vfprintf_fun)(void *state, const char *format, va_list); 8 | void (*free_state_fun)(void*); 9 | } GBUF; 10 | 11 | GLOBAL int gbprintf(GBUF *gb, const char *format, ...) __attribute__((format (printf, 2, 3))); 12 | GLOBAL int gbputs (const char *string, GBUF *gb); 13 | 14 | GLOBAL GBUF* make_string_gbuf (char *array, int arraysize); 15 | GLOBAL GBUF* make_file_gbuf (FILE *f); 16 | GLOBAL void free_gbuf(GBUF*); 17 | 18 | #define WITH_FILE_GBUF(gb,file,stmt) ({ GBUF *gb = make_file_gbuf(file); stmt; free_gbuf(gb); }) 19 | -------------------------------------------------------------------------------- /cilk2c/heap.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2002 Bradley C. Kuszmaul 12 | * 13 | * This program is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program; if not, write to the Free Software 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | * 27 | */ 28 | 29 | #ifndef _HEAP_H_ 30 | #define _HEAP_H_ 31 | FILE_IDENTITY(heap_h_ident, 32 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/heap.h $ $LastChangedBy: bradley $ $Rev: 1475 $ $Date: 2004-08-02 07:58:58 -0400 (Mon, 02 Aug 2004) $"); 33 | 34 | #define HeapNew(T) ((T *)HeapAllocate(1, sizeof(T))) 35 | #define HeapNewArray(T, c) ((T *)HeapAllocate(c, sizeof(T))) 36 | 37 | GLOBAL void *HeapAllocate(unsigned int number, unsigned int size); 38 | GLOBAL void HeapFree(void *ptr); 39 | 40 | #endif /* ifndef _HEAP_H_ */ 41 | -------------------------------------------------------------------------------- /cilk2c/initializer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2002 Bradley C. Kuszmaul 12 | * 13 | * This program is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program; if not, write to the Free Software 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | * 27 | */ 28 | 29 | #ifndef _INITIALIZER_H_ 30 | #define _INITIALIZER_H_ 31 | FILE_IDENTITY(initializer_h_ident, 32 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/initializer.h $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 33 | 34 | GLOBAL void SemCheckDeclInit(Node *decl, Bool blockp); 35 | GLOBAL Bool IsInitializer(Node *node); 36 | GLOBAL Node *InitializerCopy(Node *node); 37 | GLOBAL int InitializerLength(Node *node); 38 | GLOBAL Node *InitializerFirstItem(Node *node); 39 | GLOBAL List *InitializerExprs(Node *node); 40 | GLOBAL Bool InitializerEmptyList(Node *node); 41 | GLOBAL void InitializerNext(Node *node); 42 | GLOBAL Node *InitializerAppendItem(Node *initializer, Node *element); 43 | GLOBAL Node *ArraySubtype(Node *node); 44 | GLOBAL int ArrayNumberElements(Node *node); 45 | GLOBAL SUEtype *StructUnionFields(Node *node); 46 | GLOBAL Node *UnionFirstField(Node *node); 47 | GLOBAL Node *SUE_MatchInitList(SUEtype *sue, Node *decl, Node *initializer, Bool top_p); 48 | 49 | #endif /* _INITIALIZER_H_ */ 50 | -------------------------------------------------------------------------------- /cilk2c/list.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2000 Matteo Frigo 12 | * Copyright (c) 2002 Matteo Frigo 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #ifndef _LIST_H_ 31 | #define _LIST_H_ 32 | FILE_IDENTITY(list_h_ident, 33 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/list.h $ $LastChangedBy: bradley $ $Rev: 1378 $ $Date: 2004-06-22 00:03:24 -0400 (Tue, 22 Jun 2004) $"); 34 | 35 | typedef struct liststruct List; 36 | 37 | typedef struct { 38 | List *first, *current, *tail; 39 | } ListMarker; 40 | 41 | GLOBAL Generic *FirstItem(List *list); 42 | GLOBAL Generic *LastItem(List *list); 43 | GLOBAL Generic *SetItem(List *list, Generic *element); 44 | GLOBAL List *Rest(List *list); 45 | GLOBAL List *Last(List *list); 46 | GLOBAL int ListLength(List *list); 47 | 48 | GLOBAL List *FindItem(List *list, Generic *item); 49 | GLOBAL List *RemoveItem(List *list, Generic *item); 50 | 51 | GLOBAL List *MakeNewList(Generic *item); 52 | GLOBAL List *ConsItem(Generic *item, List *list); 53 | GLOBAL List *AppendItem(List *list, Generic *item); 54 | GLOBAL List *JoinLists(List *list1, List *list2); 55 | GLOBAL List *ListCopy(List *list); 56 | 57 | #define List1 MakeNewList 58 | GLOBAL List *List2(Generic *x1, Generic *x2); 59 | GLOBAL List *List3(Generic *x1, Generic *x2, Generic *x3); 60 | GLOBAL List *List4(Generic *x1, Generic *x2, Generic *x3, Generic *x4); 61 | GLOBAL List *List5(Generic *x1, Generic *x2, Generic *x3, Generic *x4, Generic *x5); 62 | 63 | /* ListMarker passed by reference in the following */ 64 | GLOBAL void IterateList(ListMarker *, List *); 65 | GLOBAL Bool NextOnList(ListMarker *, GenericREF itemref); 66 | GLOBAL List *InsertList(ListMarker *marker, List *list); 67 | GLOBAL List *SplitList(ListMarker *marker); 68 | GLOBAL void SetCurrentOnList(ListMarker *marker, Generic *handle); 69 | GLOBAL List *NextChunkOnList(ListMarker *, int chunksize); 70 | GLOBAL Bool EndOfList(ListMarker *marker); 71 | 72 | GLOBAL List *Mapc(List *, void(*f)(Generic*)); /* apply f to every element of the list. */ 73 | GLOBAL List *DeleteIf(List *, int(*f)(Generic*)); /* modify the list to remove every element for which f() returns non-zero. */ 74 | 75 | #endif /* ifndef _LIST_H_ */ 76 | -------------------------------------------------------------------------------- /cilk2c/operators.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2000 Matteo Frigo 12 | * Copyright (c) 2002 Bradley C. Kuszmaul 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #ifndef _OPERATORS_H_ 31 | #define _OPERATORS_H_ 32 | FILE_IDENTITY(operators_h_ident, 33 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/operators.h $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 34 | 35 | /* unary/binary operator table information */ 36 | typedef struct { 37 | const char *text; /* text of the operator */ 38 | const char *name; /* name of the operator for debugging */ 39 | short unary_prec; /* unary precedence, all unary ops are right assoc */ 40 | short binary_prec; /* binary precedence */ 41 | Bool left_assoc; /* TRUE iff binary op is left associative */ 42 | Bool (*unary_eval) (Node *); 43 | Bool (*binary_eval) (Node *); 44 | } OpEntry; 45 | 46 | GLOBAL extern OpEntry Operator[MAX_OPERATORS]; /* operators.c */ 47 | 48 | /* from operators.c */ 49 | GLOBAL void InitOperatorTable(void); /* operators.c */ 50 | GLOBAL int OpPrecedence(NodeType typ, OpType op, Bool *left_assoc); 51 | GLOBAL Node *EvaluateConstantExpr(Node *); 52 | GLOBAL Bool ApplyUnary(Node *unary); /* operators.c */ 53 | 54 | #endif /* _OPERATORS_H_ */ 55 | -------------------------------------------------------------------------------- /cilk2c/sideeffects.c: -------------------------------------------------------------------------------- 1 | /* Determine whether an expression has side effects in it. 2 | * 3 | * Copyright (C) 2003 Bradley C. Kuszmaul 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | #include "ast.h" 21 | 22 | FILE_IDENTITY(ident, 23 | "$HeadURL: https://bradley.lcs.mit.edu/svn/repos/cilk/current.Bug66/cilk2c/simplify.c $ $LastChangedBy: bradley $ $Rev: 387 $ $Date: 2003-05-01 14:39:50 -0400 (Thu, 01 May 2003) $"); 24 | 25 | 26 | PRIVATE Bool SideeffectsList(List *list); 27 | 28 | #define SideeffectsNop(kind,utype) PRIVATE Bool Sideeffects##kind(utype##Node *UNUSED(u)) { return FALSE; } 29 | 30 | 31 | SideeffectsNop(Id,id) 32 | SideeffectsNop(Label,label) 33 | SideeffectsNop(Goto,Goto) 34 | SideeffectsNop(Default,Default) 35 | SideeffectsNop(Continue,Continue) 36 | SideeffectsNop(Break,Break) 37 | SideeffectsNop(Prim,prim) 38 | SideeffectsNop(Sync,sync) 39 | SideeffectsNop(Abort,abort) 40 | SideeffectsNop(Synched,synched) 41 | SideeffectsNop(Attrib,attrib) 42 | SideeffectsNop(Text,text) 43 | SideeffectsNop(Const,Const) 44 | SideeffectsNop(Tdef,tdef) 45 | SideeffectsNop(Ptr,ptr) 46 | SideeffectsNop(Adcl,adcl) 47 | SideeffectsNop(Fdcl,fdcl) 48 | SideeffectsNop(Sdcl,sdcl) 49 | SideeffectsNop(Udcl,udcl) 50 | SideeffectsNop(Edcl,edcl) 51 | SideeffectsNop(Proc,proc) 52 | 53 | PRIVATE Bool SideeffectsUnary (unaryNode *u) { 54 | if (IsIncDecOp(u->op)) return TRUE; 55 | else if (u->op==SIZEOF) return FALSE; 56 | else if (u->op==ALIGNOF) return FALSE; 57 | else return SideeffectsNode(u->expr); 58 | } 59 | 60 | PRIVATE Bool SideeffectsBinop (binopNode *u) { 61 | if (IsAssignmentOp(u->op)) return TRUE; 62 | else { 63 | switch (u->op) { 64 | case Cast: 65 | case ':': 66 | case DESIGNATED_INITIALIZER: 67 | return SideeffectsNode(u->right); 68 | case '.': 69 | case ARROW: 70 | return SideeffectsNode(u->left); 71 | case '+': 72 | case '-': 73 | case '*': 74 | case '/': 75 | case '%': 76 | case LS: 77 | case RS: 78 | case '<': 79 | case '>': 80 | case LE: 81 | case GE: 82 | case EQ: 83 | case NE: 84 | case '&': 85 | case '^': 86 | case '|': 87 | case ANDAND: 88 | case OROR: 89 | return SideeffectsNode(u->left) || SideeffectsNode(u->right); 90 | default: 91 | printf("%s:%d Unhandled case %d\n", __FILE__, __LINE__, u->op); 92 | abort(); 93 | } 94 | } 95 | } 96 | 97 | PRIVATE Bool SideeffectsCast (castNode *u) { 98 | return SideeffectsNode(u->expr); 99 | } 100 | 101 | PRIVATE Bool SideeffectsComma (commaNode *u) { 102 | return SideeffectsList(u->exprs); 103 | } 104 | 105 | PRIVATE Bool SideeffectsConstructor (constructorNode *u) { 106 | return SideeffectsNode(u->initializerlist); 107 | } 108 | PRIVATE Bool SideeffectsTernary (ternaryNode *u) { 109 | return (SideeffectsNode(u->cond) 110 | || SideeffectsNode(u->true) 111 | || SideeffectsNode(u->false)); 112 | } 113 | 114 | PRIVATE Bool SideeffectsArray (arrayNode *u) { 115 | return SideeffectsNode(u->name) || SideeffectsList(u->dims); 116 | } 117 | 118 | PRIVATE Bool SideeffectsCall (UNUSED(callNode *u)) { 119 | return TRUE; /* assume that evaluating a function call will cause side effects.*/ 120 | } 121 | 122 | PRIVATE Bool SideeffectsInitializer (initializerNode *u) { 123 | return SideeffectsList(u->exprs); 124 | } 125 | 126 | PRIVATE Bool SideeffectsImplicitCast (implicitcastNode *u) { 127 | return SideeffectsNode(u->expr); 128 | } 129 | 130 | PRIVATE Bool SideeffectsSwitch (SwitchNode *u) { 131 | return SideeffectsNode(u->expr) || SideeffectsNode(u->stmt); 132 | } 133 | 134 | PRIVATE Bool SideeffectsCase (CaseNode *u) { 135 | assert(!SideeffectsNode(u->expr)); /* It is supposed to be a constant*/ 136 | return FALSE; 137 | } 138 | 139 | 140 | PRIVATE Bool SideeffectsIf (IfNode *u) { 141 | return SideeffectsNode(u->expr) 142 | || SideeffectsNode(u->stmt); 143 | } 144 | 145 | PRIVATE Bool SideeffectsIfElse (IfElseNode *u) { 146 | return SideeffectsNode(u->expr) 147 | || SideeffectsNode(u->true) 148 | || SideeffectsNode(u->false); 149 | } 150 | 151 | PRIVATE Bool SideeffectsWhile (WhileNode *u) { 152 | return SideeffectsNode(u->expr) 153 | || SideeffectsNode(u->stmt); 154 | } 155 | 156 | PRIVATE Bool SideeffectsDo (DoNode *u) { 157 | return SideeffectsNode(u->stmt) 158 | || SideeffectsNode(u->expr); 159 | } 160 | 161 | PRIVATE Bool SideeffectsFor (ForNode *u) { 162 | return SideeffectsNode(u->init) 163 | || SideeffectsNode(u->cond) 164 | || SideeffectsNode(u->next) 165 | || SideeffectsNode(u->stmt); 166 | } 167 | 168 | PRIVATE Bool SideeffectsReturn (ReturnNode *u) { 169 | return SideeffectsNode(u->expr); 170 | } 171 | 172 | PRIVATE Bool SideeffectsBlock (BlockNode *u) { 173 | return SideeffectsList(u->decl) 174 | || SideeffectsList(u->stmts); 175 | } 176 | 177 | PRIVATE Bool SideeffectsAsm(asmNode *u) { 178 | return (u->output!=NULL) 179 | || SideeffectsList(u->input); 180 | } 181 | 182 | PRIVATE Bool SideeffectsAsmArg(asmargNode *u) { 183 | return SideeffectsNode(u->expr); 184 | } 185 | 186 | PRIVATE Bool SideeffectsBuiltinVaArg(builtinvaargNode *u) { 187 | return SideeffectsNode(u->expr); 188 | } 189 | 190 | PRIVATE Bool SideeffectsSpawn(UNUSED(spawnNode *u)) { 191 | return TRUE; 192 | } 193 | 194 | PRIVATE Bool SideeffectsInletCall(UNUSED(inletcallNode *u)) { 195 | return TRUE; 196 | } 197 | 198 | 199 | PRIVATE Bool SideeffectsXBlock (XBlockNode *u) { 200 | return SideeffectsList(u->decl) 201 | || SideeffectsList(u->stmts); 202 | } 203 | 204 | 205 | PRIVATE Bool SideeffectsDecl(declNode *u) { 206 | return SideeffectsNode(u->init); 207 | } 208 | 209 | GLOBAL Bool SideeffectsNode(Node *node) { 210 | if (node == NULL) 211 | return FALSE; 212 | #define CODE(name, node, union) return Sideeffects##name(union) 213 | ASTSWITCH(node, CODE) 214 | #undef CODE 215 | UNREACHABLE; 216 | } 217 | PRIVATE Bool SideeffectsList(List *list) { 218 | List *aptr; 219 | for (aptr = list; aptr; aptr = Rest(aptr)) { 220 | Node *item = FirstItem(aptr); 221 | 222 | if (SideeffectsNode(item)) return TRUE; 223 | } 224 | return FALSE; 225 | } 226 | -------------------------------------------------------------------------------- /cilk2c/strings.c: -------------------------------------------------------------------------------- 1 | 2 | /************************************************************************* 3 | * 4 | * C-to-C Translator 5 | * 6 | * Adapted from Clean ANSI C Parser 7 | * Eric A. Brewer, Michael D. Noakes 8 | * 9 | *************************************************************************/ 10 | /* 11 | * Copyright (c) 1949-2002 Massachusetts Institute of Technology 12 | * Copyright (c) 2000 Matteo Frigo 13 | * Copyright (c) 2002 Bradley C. Kuszmaul 14 | * 15 | * This program is free software; you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation; either version 2 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This program is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program; if not, write to the Free Software 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 28 | * 29 | */ 30 | 31 | #include "basics.h" 32 | 33 | FILE_IDENTITY(ident, 34 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/strings.c $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 35 | 36 | #define TABLE_SIZE 231 37 | 38 | typedef struct eT { 39 | char *string; 40 | struct eT *next; 41 | } entryType; 42 | 43 | PRIVATE entryType *hash_table[TABLE_SIZE]; 44 | 45 | /* copy_string: 46 | * Copy string to create location, and return the create location. 47 | */ 48 | PRIVATE char *copy_string(const char *string) 49 | { 50 | char *new_string; 51 | 52 | new_string = HeapNewArray(char, strlen(string) + 1); 53 | return strcpy(new_string, string); 54 | } 55 | 56 | /* hash table function */ 57 | PRIVATE short hash_function(const char *string) 58 | { 59 | unsigned short i, k; 60 | unsigned long val; 61 | 62 | assert(string != NULL); 63 | 64 | val = (short) string[0] + 1; 65 | for (i = 1; i < 8; i++) { 66 | if (string[i] == 0) 67 | break; 68 | k = string[i] & 0x3f; 69 | val *= k + 7; 70 | } 71 | return ((short) (val % TABLE_SIZE)); 72 | } 73 | 74 | GLOBAL char *UniqueString(const char *string) 75 | { 76 | short bucket = hash_function(string); 77 | entryType *entry; 78 | 79 | for (entry = hash_table[bucket]; entry != NULL; entry = entry->next) 80 | if (strcmp(string, entry->string) == 0) 81 | return (entry->string); 82 | 83 | /* not found */ 84 | entry = HeapNew(entryType); 85 | 86 | entry->string = copy_string(string); 87 | entry->next = hash_table[bucket]; 88 | hash_table[bucket] = entry; 89 | 90 | return (entry->string); 91 | } 92 | -------------------------------------------------------------------------------- /cilk2c/symbol.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2000 Matteo Frigo 12 | * Copyright (c) 2002 Bradley C. Kuszmaul 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #ifndef _SYMBOL_H_ 31 | #define _SYMBOL_H_ 32 | FILE_IDENTITY(symbol_h_ident, 33 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/symbol.h $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 34 | 35 | /* two kinds of symbol tables: nested scope or one large flat scope */ 36 | typedef enum { 37 | Nested, Flat 38 | } TableType; 39 | 40 | GLOBAL extern short Level; /* scope depth, initially zero */ 41 | 42 | typedef void (*ConflictProc) (Generic *orig, Generic *create); 43 | typedef void (*ShadowProc) (Generic *create, Generic *shadowed); 44 | typedef void (*ExitscopeProc) (Generic *dead); 45 | 46 | /* create a create symbol table: 47 | * `shadow' is called when one symbol shadows another, 48 | * if `shadow' is NULL then no action is taken; 49 | * `exitscope' is called when an entry becomes dead, 50 | * if it is NULL then no action is taken */ 51 | GLOBAL SymbolTable *NewSymbolTable(const char *name, TableType kind, 52 | ShadowProc, ExitscopeProc); 53 | 54 | GLOBAL void ResetSymbolTable(SymbolTable *table); 55 | 56 | GLOBAL void PrintSymbolTable(FILE *out, SymbolTable *table); 57 | 58 | GLOBAL void EnterScope(void); 59 | GLOBAL void ExitScope(void); 60 | 61 | GLOBAL Bool LookupSymbol(SymbolTable *, const char *name, Generic **var); 62 | 63 | GLOBAL Generic *InsertSymbol(SymbolTable *, const char *name, Generic *var, 64 | ConflictProc); 65 | 66 | GLOBAL void MoveToOuterScope(SymbolTable *, const char *name); 67 | 68 | GLOBAL const char *InsertUniqueSymbol(SymbolTable *table, Generic *var, const char *root); 69 | 70 | typedef struct { 71 | SymbolTable *table; 72 | int i; 73 | void *chain; 74 | } SymbolTableMarker; 75 | 76 | GLOBAL void IterateSymbolTable(SymbolTableMarker *, SymbolTable *); 77 | GLOBAL Bool NextInSymbolTable(SymbolTableMarker *, const char **name, GenericREF itemref); 78 | 79 | #endif /* ifndef _SYMBOL_H_ */ 80 | -------------------------------------------------------------------------------- /cilk2c/testEquals.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (c) 1994-2003 Massachusetts Institute of Technology 3 | * Copyright (c) 2003 Jim Sukha 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | 21 | #ifndef _TEST_EQUALS_H 22 | #define _TEST_EQUALS_H 23 | 24 | #include "ast.h" 25 | #include "astEquals.h" 26 | 27 | /* Defined in main.c*/ 28 | extern Node* ParseStringIntoSyntaxTree(char *inputString); 29 | 30 | void TestParseString(char* input); 31 | 32 | /* Returns TRUE if the strings parse into 33 | trees with equal root nodes. (FALSE if 34 | either string parses incorrectly. */ 35 | Bool TestEqualNodes(char *str1, char *str2); 36 | 37 | /* Returns TRUE if the strings parse into 38 | equal trees. (FALSE if 39 | either string parses incorrectly. */ 40 | Bool TestEqualSyntaxTrees(char *str1, char *str2); 41 | 42 | /* Returns TRUE if tree represented by str1 contains 43 | the tree in str2 */ 44 | Bool TestContainsSyntaxTrees(char *str1, char *str2); 45 | 46 | Node* TestReplaceSyntaxSubtree(char *str1, char *str2, char *str3); 47 | 48 | Node* TestContainsSubtree(char *str1, char *str2); 49 | 50 | 51 | 52 | /* void TestWildcardTable();*/ 53 | 54 | /* Returns TRUE if all strings passed in parse without error into 55 | syntax trees. */ 56 | Bool RunParseStringTest(char *testStrings[], int numStrings); 57 | 58 | Bool RunEqualNodeTestCases(); 59 | Bool RunEqualASTTreeTestCases(); 60 | Bool RunContainsASTTreeTestCases(); 61 | Bool RunReplaceASTTestCases(); 62 | Bool RunContainsSubtreeTestCases(); 63 | Bool RunReplaceSyntaxSubtreeTestCases(); 64 | Bool RunCopyASTTestCases(); 65 | Bool RunGetAllMatchingSubtreeTestCase(); 66 | Bool RunReplaceAllMatchingSubtreeTestCases(); 67 | 68 | Bool RunPatternEqualTestCases(); 69 | Bool RunPatternMatchReplaceTestCases(); 70 | 71 | 72 | 73 | GLOBAL void RunAllEqualsTests(); 74 | GLOBAL void RunWildcardParsingTests(); 75 | 76 | GLOBAL void RunAllTests(); 77 | 78 | /* Does sizeof on each of the nodes 79 | in the union u in Node struct */ 80 | GLOBAL void PrintNodeSizes(); 81 | 82 | GLOBAL void UserPromptParseTest(); 83 | 84 | #endif /*ifndef _TEST_EQUALS_H */ 85 | 86 | 87 | -------------------------------------------------------------------------------- /cilk2c/warning.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * C-to-C Translator 4 | * 5 | * Adapted from Clean ANSI C Parser 6 | * Eric A. Brewer, Michael D. Noakes 7 | * 8 | *************************************************************************/ 9 | /* 10 | * Copyright (c) 1994-2002 Massachusetts Institute of Technology 11 | * Copyright (c) 2000 Matteo Frigo 12 | * Copyright (c) 2002 Bradley C. Kuszmaul 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #include "basics.h" 31 | 32 | FILE_IDENTITY(ident, 33 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/cilk2c/warning.c $ $LastChangedBy: bradley $ $Rev: 1341 $ $Date: 2004-06-08 08:20:40 -0400 (Tue, 08 Jun 2004) $"); 34 | 35 | #ifndef NO_STDARG 36 | #include 37 | #define VA_START(ap,fmt) va_start(ap,fmt) 38 | #else 39 | /* for many older Unix platforms: use varargs */ 40 | #include 41 | extern int vfprintf(FILE *, const char *, void *); 42 | #define VA_START(ap,fmt) va_start(ap) 43 | #endif 44 | 45 | GLOBAL int Line = 1, Errors = 0, Warnings = 0; 46 | GLOBAL int LineOffset = 0; 47 | 48 | GLOBAL void Fail(const char *file, int line, const char *msg) /* __attribute__((noreturn)) */ 49 | { 50 | fprintf(stderr, "Assertion failed in %s, line %d\n", file, line); 51 | fprintf(stderr, "\t%s\n", msg); 52 | 53 | if (strcmp(PhaseName, "Parsing") == 0) { 54 | fprintf(stderr, "Input: %s, line %d\n", Filename, Line); 55 | } 56 | #if 0 57 | exit(10); 58 | #endif 59 | abort(); 60 | } 61 | 62 | GLOBAL void SyntaxError(const char *fmt,...) 63 | { 64 | va_list ap; 65 | VA_START(ap, fmt); 66 | 67 | Errors++; 68 | fprintf(stderr, "%s:%d: ", Filename, Line); 69 | vfprintf(stderr, fmt, ap); 70 | fputc('\n', stderr); 71 | va_end(ap); 72 | } 73 | 74 | GLOBAL void Warning(int level, const char *fmt,...) 75 | { 76 | va_list ap; 77 | VA_START(ap, fmt); 78 | 79 | if (level > WarningLevel) 80 | return; 81 | Warnings++; 82 | fprintf(stderr, "%s:%d: Warning: ", Filename, Line); 83 | vfprintf(stderr, fmt, ap); 84 | fputc('\n', stderr); 85 | va_end(ap); 86 | } 87 | 88 | GLOBAL void Hint(const char *fmt,...) 89 | { 90 | va_list ap; 91 | VA_START(ap, fmt); 92 | 93 | fprintf(stderr, "%s:%d: Hint: ", Filename, Line); 94 | vfprintf(stderr, fmt, ap); 95 | fputc('\n', stderr); 96 | va_end(ap); 97 | } 98 | 99 | GLOBAL void SyntaxErrorCoord(Coord c, const char *fmt,...) 100 | { 101 | va_list ap; 102 | VA_START(ap, fmt); 103 | 104 | Errors++; 105 | PRINT_COORD(stderr, c); 106 | fprintf(stderr, ": "); 107 | vfprintf(stderr, fmt, ap); 108 | fputc('\n', stderr); 109 | va_end(ap); 110 | } 111 | 112 | GLOBAL void WarningCoord(int level, Coord c, const char *fmt,...) 113 | { 114 | va_list ap; 115 | VA_START(ap, fmt); 116 | 117 | if (level > WarningLevel) 118 | return; 119 | Warnings++; 120 | PRINT_COORD(stderr, c); 121 | fprintf(stderr, ": Warning: "); 122 | vfprintf(stderr, fmt, ap); 123 | fputc('\n', stderr); 124 | va_end(ap); 125 | } 126 | 127 | GLOBAL void HintCoord(Coord c, const char *fmt,...) 128 | { 129 | va_list ap; 130 | VA_START(ap, fmt); 131 | 132 | PRINT_COORD(stderr, c); 133 | fprintf(stderr, ": hint: "); 134 | vfprintf(stderr, fmt, ap); 135 | fputc('\n', stderr); 136 | va_end(ap); 137 | } 138 | -------------------------------------------------------------------------------- /cilk2c/wildcard.h: -------------------------------------------------------------------------------- 1 | #ifndef _WILDCARD_H 2 | #define _WILDCARD_H 3 | 4 | #include 5 | #include "basics.h" 6 | 7 | 8 | typedef enum { 9 | WildcardD, /* Identifier wildcard %d */ 10 | WildcardE, /* Expression wildcard %e */ 11 | WildcardT, /* Type wildcard %t */ 12 | NonWildcard /* A normal node. */ 13 | } WildcardType; 14 | 15 | /* Prints the letter corresponding to the WildcardType 16 | to file, or "-" if not a wildcard. */ 17 | GLOBAL void PrintTypeLetter(FILE *out, WildcardType t); 18 | 19 | /* Returns the type of wildcard given the string name */ 20 | GLOBAL WildcardType WildcardTypeFromName(const char* wcName); 21 | 22 | 23 | 24 | /* Scans through INPUT_STRING, from left to right, 25 | and returns a List of the WildcardType's found. */ 26 | GLOBAL List* GetWildcardTypes(char* inputString); 27 | 28 | 29 | /* Scans through INPUT_STRING, from left to right, 30 | and returns a List of strings corresponding 31 | to the names of the wildcards found. */ 32 | GLOBAL List* GetWildcardNames(const char *str); 33 | 34 | /* This procedure takes all the unnamed 35 | wildcards in the string and assigns them 36 | unique names. (named and unnamed wildcards 37 | should not be mixed in the same string). See 38 | implementation in c4.l */ 39 | GLOBAL char* NameAllWildcards(const char *inputString); 40 | 41 | 42 | /**** Test case code **/ 43 | 44 | /* Testing PrintTypeLetter */ 45 | GLOBAL Bool TestWildcardLetterFunctions(); 46 | 47 | /* Goes through a set of strings, calls GetWildcardTypes(), 48 | and prints the the output. 49 | Returns TRUE if all tests are passed. */ 50 | GLOBAL Bool TestGetWildcardTypeCases(); 51 | 52 | 53 | /* Goes through a set of strings, calls GetWildcardTypes(), 54 | and prints the the output. 55 | Not an automated test. */ 56 | GLOBAL Bool TestGetWildcardNameCases(); 57 | 58 | /* Testing PrintTypeLetter */ 59 | GLOBAL Bool TestWildcardLetterFunctions(); 60 | 61 | /* This is an automated test, but it will break if 62 | we change FIRST_NEW_WC_NAME and NUM_EXTRA_DIGITS from 63 | * 100 and 3, respectively. */ 64 | GLOBAL Bool TestNameAllWildcards(); 65 | 66 | #endif /* _WILDCARD_H */ 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /cilk2c/wildcardTable.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (c) 1994-2003 Massachusetts Institute of Technology 3 | * Copyright (c) 2003 Jim Sukha 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | #include "ast.h" 21 | #include "symbol.h" 22 | #include "wildcardTable.h" 23 | 24 | /* Use a Symbol Table for a wildcard table */ 25 | 26 | struct wildcardTableStruct { 27 | SymbolTable *symtable; 28 | int tableKey; 29 | }; 30 | 31 | GLOBAL WildcardTable *NewWildcardTable(int tableKey) { 32 | WildcardTable *create; 33 | 34 | create = HeapNew(WildcardTable); 35 | create->symtable = NewSymbolTable("Wildcards", Flat, NULL, NULL); 36 | create->tableKey = tableKey; 37 | 38 | return create; 39 | } 40 | 41 | /* Clears the contents of the wildcard table */ 42 | GLOBAL void ResetWildcardTable(WildcardTable *table) { 43 | if (table != NULL) { 44 | ResetSymbolTable(table->symtable); 45 | } 46 | } 47 | 48 | 49 | 50 | /* Looks up NAME in the wildcard table, and returns 51 | the corresponding node (or NULL if not found) */ 52 | GLOBAL Node* LookupWildcard(WildcardTable *table, const char *name) { 53 | Node *answer; 54 | Bool found = FALSE; 55 | 56 | if (table != NULL) { 57 | found = LookupSymbol(table->symtable, UniqueString(name), (GenericREF) &answer); 58 | } 59 | 60 | if (found) { 61 | /* printf("Found %s in table. \n", name);*/ 62 | return answer; 63 | } 64 | else { 65 | return NULL; 66 | } 67 | } 68 | 69 | 70 | /* Simply replaces old token. */ 71 | PRIVATE void wildcard_conflict(Node *orig, Node *create) 72 | { 73 | *orig = *create; 74 | } 75 | 76 | 77 | /* Inserts wildcard with specified NAME into the TABLE. Any entry with 78 | the same name gets replaced. NULL values can not be 79 | inserted into the table. */ 80 | GLOBAL void InsertWildcard(WildcardTable *table, const char *name, Node* wildcardValue) { 81 | if ((table != NULL) && (wildcardValue != NULL)) { 82 | InsertSymbol(table->symtable, UniqueString(name), wildcardValue, (ConflictProc) wildcard_conflict); 83 | } 84 | } 85 | 86 | 87 | GLOBAL void PrintWildcardTable(FILE *out, WildcardTable *table) { 88 | 89 | SymbolTableMarker tableWalk; 90 | const char *symName; 91 | Node *currentNode; 92 | 93 | if (table == NULL) { 94 | fprintf(out, "\nNull Wildcard Table\n"); 95 | } 96 | else { 97 | fprintf(out, "\nWildcard Table %d: \n", table->tableKey); 98 | IterateSymbolTable(&tableWalk, table->symtable); 99 | while (NextInSymbolTable(&tableWalk, &symName, (GenericREF)¤tNode)) { 100 | fprintf(out, "Wildcard %s: ", symName); 101 | /* MyOutputExpr(out, currentNode);*/ 102 | } 103 | fprintf(out, "\n"); 104 | /* PrintSymbolTable(out, table->symtable);*/ 105 | } 106 | } 107 | 108 | -------------------------------------------------------------------------------- /cilk2c/wildcardTable.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (c) 1994-2003 Massachusetts Institute of Technology 3 | * Copyright (c) 2003 Jim Sukha 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | 21 | #ifndef _WILDCARD_TABLE_H 22 | #define _WILDCARD_TABLE_H 23 | 24 | 25 | typedef struct wildcardTableStruct WildcardTable; 26 | 27 | 28 | GLOBAL WildcardTable *NewWildcardTable(int tableKey); 29 | 30 | /* Clears the contents of the wildcard table */ 31 | GLOBAL void ResetWildcardTable(WildcardTable *table); 32 | 33 | /* Looks up NAME in the wildcard table, and returns 34 | the corresponding node (or NULL if not found) */ 35 | GLOBAL Node* LookupWildcard(WildcardTable *table, const char *name); 36 | 37 | 38 | /* Inserts wildcard with specified NAME into the TABLE. Any entry with 39 | the same name gets replaced. */ 40 | GLOBAL void InsertWildcard(WildcardTable *table, const char *name, Node* wildcardValue); 41 | 42 | 43 | GLOBAL void PrintWildcardTable(FILE *out, WildcardTable *table); 44 | 45 | #endif /* _WILDCARD_TABLE_H */ 46 | 47 | -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand `-c -o'. 3 | 4 | scriptversion=2005-05-14.22 5 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. 7 | # Written by Tom Tromey . 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | case $1 in 33 | '') 34 | echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35 | exit 1; 36 | ;; 37 | -h | --h*) 38 | cat <<\EOF 39 | Usage: compile [--help] [--version] PROGRAM [ARGS] 40 | 41 | Wrapper for compilers which do not understand `-c -o'. 42 | Remove `-o dest.o' from ARGS, run PROGRAM with the remaining 43 | arguments, and rename the output as expected. 44 | 45 | If you are trying to build a whole package this is not the 46 | right script to run: please start by reading the file `INSTALL'. 47 | 48 | Report bugs to . 49 | EOF 50 | exit $? 51 | ;; 52 | -v | --v*) 53 | echo "compile $scriptversion" 54 | exit $? 55 | ;; 56 | esac 57 | 58 | ofile= 59 | cfile= 60 | eat= 61 | 62 | for arg 63 | do 64 | if test -n "$eat"; then 65 | eat= 66 | else 67 | case $1 in 68 | -o) 69 | # configure might choose to run compile as `compile cc -o foo foo.c'. 70 | # So we strip `-o arg' only if arg is an object. 71 | eat=1 72 | case $2 in 73 | *.o | *.obj) 74 | ofile=$2 75 | ;; 76 | *) 77 | set x "$@" -o "$2" 78 | shift 79 | ;; 80 | esac 81 | ;; 82 | *.c) 83 | cfile=$1 84 | set x "$@" "$1" 85 | shift 86 | ;; 87 | *) 88 | set x "$@" "$1" 89 | shift 90 | ;; 91 | esac 92 | fi 93 | shift 94 | done 95 | 96 | if test -z "$ofile" || test -z "$cfile"; then 97 | # If no `-o' option was seen then we might have been invoked from a 98 | # pattern rule where we don't need one. That is ok -- this is a 99 | # normal compilation that the losing compiler can handle. If no 100 | # `.c' file was seen then we are probably linking. That is also 101 | # ok. 102 | exec "$@" 103 | fi 104 | 105 | # Name of file we expect compiler to create. 106 | cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 107 | 108 | # Create the lock directory. 109 | # Note: use `[/.-]' here to ensure that we don't use the same name 110 | # that we are using for the .o file. Also, base the name on the expected 111 | # object file name, since that is what matters with a parallel build. 112 | lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d 113 | while true; do 114 | if mkdir "$lockdir" >/dev/null 2>&1; then 115 | break 116 | fi 117 | sleep 1 118 | done 119 | # FIXME: race condition here if user kills between mkdir and trap. 120 | trap "rmdir '$lockdir'; exit 1" 1 2 15 121 | 122 | # Run the compile. 123 | "$@" 124 | ret=$? 125 | 126 | if test -f "$cofile"; then 127 | mv "$cofile" "$ofile" 128 | elif test -f "${cofile}bj"; then 129 | mv "${cofile}bj" "$ofile" 130 | fi 131 | 132 | rmdir "$lockdir" 133 | exit $ret 134 | 135 | # Local Variables: 136 | # mode: shell-script 137 | # sh-indentation: 2 138 | # eval: (add-hook 'write-file-hooks 'time-stamp) 139 | # time-stamp-start: "scriptversion=" 140 | # time-stamp-format: "%:y-%02m-%02d.%02H" 141 | # time-stamp-end: "$" 142 | # End: 143 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* The C compiler to use when compiling code for pthreads */ 4 | #undef CILKC_PTHREAD_CC 5 | 6 | /* To be passed to the C compiler when compiling code for pthreads */ 7 | #undef CILKC_PTHREAD_CFLAGS 8 | 9 | /* The pthread libraries */ 10 | #undef CILKC_PTHREAD_LIBS 11 | 12 | /* "Use perfctr to measure critical path and work." */ 13 | #undef CILK_USE_PERFCTR 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_ALLOCA_H 17 | 18 | /* Define to 1 if you have the `clone' function. */ 19 | #undef HAVE_CLONE 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_DLFCN_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_FCNTL_H 26 | 27 | /* Define to 1 if you have the `gethrtime' function. */ 28 | #undef HAVE_GETHRTIME 29 | 30 | /* Define to 1 if you have the `gethrvtime' function. */ 31 | #undef HAVE_GETHRVTIME 32 | 33 | /* Define to 1 if you have the `gettimeofday' function. */ 34 | #undef HAVE_GETTIMEOFDAY 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_INTTYPES_H 38 | 39 | /* Define to 1 if you have the `m' library (-lm). */ 40 | #undef HAVE_LIBM 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_LIMITS_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_MALLOC_H 47 | 48 | /* Define to 1 if you have the `memalign' function. */ 49 | #undef HAVE_MEMALIGN 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_MEMORY_H 53 | 54 | /* Define if you have POSIX threads libraries and header files. */ 55 | #undef HAVE_PTHREAD 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_PTHREAD_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_SCHED_H 62 | 63 | /* Define to 1 if you have the `sched_setaffinity' function. */ 64 | #undef HAVE_SCHED_SETAFFINITY 65 | 66 | /* Define to 1 if you have the `sched_yield' function. */ 67 | #undef HAVE_SCHED_YIELD 68 | 69 | /* Define to 1 if you have the `sginap' function. */ 70 | #undef HAVE_SGINAP 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_SIGNAL_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_STDDEF_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_STDINT_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_STDLIB_H 83 | 84 | /* Define to 1 if you have the `strchr' function. */ 85 | #undef HAVE_STRCHR 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #undef HAVE_STRINGS_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #undef HAVE_STRING_H 92 | 93 | /* Define to 1 if you have the `strtoul' function. */ 94 | #undef HAVE_STRTOUL 95 | 96 | /* Define to 1 if you have the header file. */ 97 | #undef HAVE_SYS_STAT_H 98 | 99 | /* Define to 1 if you have the header file. */ 100 | #undef HAVE_SYS_TIME_H 101 | 102 | /* Define to 1 if you have the header file. */ 103 | #undef HAVE_SYS_TYPES_H 104 | 105 | /* Define to 1 if you have the header file. */ 106 | #undef HAVE_SYS_WAIT_H 107 | 108 | /* Define to 1 if you have the header file. */ 109 | #undef HAVE_UNISTD_H 110 | 111 | /* Define to 1 if you have the `yield' function. */ 112 | #undef HAVE_YIELD 113 | 114 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 115 | #undef NO_MINUS_C_MINUS_O 116 | 117 | /* Name of package */ 118 | #undef PACKAGE 119 | 120 | /* Define to the address where bug reports for this package should be sent. */ 121 | #undef PACKAGE_BUGREPORT 122 | 123 | /* Define to the full name of this package. */ 124 | #undef PACKAGE_NAME 125 | 126 | /* Define to the full name and version of this package. */ 127 | #undef PACKAGE_STRING 128 | 129 | /* Define to the one symbol short name of this package. */ 130 | #undef PACKAGE_TARNAME 131 | 132 | /* Define to the version of this package. */ 133 | #undef PACKAGE_VERSION 134 | 135 | /* Define to necessary symbol if this constant uses a non-standard name on 136 | your system. */ 137 | #undef PTHREAD_CREATE_JOINABLE 138 | 139 | /* Define to 1 if you have the ANSI C header files. */ 140 | #undef STDC_HEADERS 141 | 142 | /* Define to 1 if you can safely include both and . */ 143 | #undef TIME_WITH_SYS_TIME 144 | 145 | /* Define to 1 if your declares `struct tm'. */ 146 | #undef TM_IN_SYS_TIME 147 | 148 | /* Version number of package */ 149 | #undef VERSION 150 | 151 | /* Define if you are using the GNU linker */ 152 | #undef WITH_GNU_LD 153 | 154 | /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a 155 | `char[]'. */ 156 | #undef YYTEXT_POINTER 157 | 158 | /* Define to empty if `const' does not conform to ANSI C. */ 159 | #undef const 160 | 161 | /* Define to `__inline__' or `__inline' if that's what the C compiler 162 | calls it, or to nothing if 'inline' is not supported under any name. */ 163 | #ifndef __cplusplus 164 | #undef inline 165 | #endif 166 | 167 | /* Define to `unsigned int' if does not define. */ 168 | #undef size_t 169 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script. 2 | AC_INIT([cilk], [5.4.6]) 3 | AC_CONFIG_SRCDIR([config.h.in]) 4 | AM_CONFIG_HEADER([config.h runtime/cilk-sysdep.h]) 5 | AC_PREREQ(2.53) 6 | AM_INIT_AUTOMAKE 7 | AC_CANONICAL_HOST 8 | 9 | dnl Checks for programs. 10 | AC_PROG_CC 11 | AM_PROG_CC_C_O 12 | AM_PROG_LEX 13 | AC_PROG_YACC 14 | AC_PROG_INSTALL 15 | AC_PROG_LN_S 16 | AC_PROG_MAKE_SET 17 | AM_PROG_LIBTOOL 18 | 19 | AC_ARG_WITH(perfctr,[ --with-perfctr use the virtualized version of the timestamp counter to measure the critical path and work (requires the perfctr kernel patch)], with_perfctr=$withval, with_perfctr=no) 20 | 21 | dnl Checks for required programs. 22 | if test "$GCC" != "yes"; then 23 | AC_ERROR("I cannot find gcc. gcc is required for Cilk to work.") 24 | fi 25 | 26 | dnl Checks for libraries. 27 | AC_CHECK_LIB(m, sqrt) 28 | 29 | dnl Checks for header files. 30 | AC_HEADER_STDC 31 | AC_HEADER_SYS_WAIT 32 | AC_CHECK_HEADERS([alloca.h fcntl.h limits.h malloc.h stddef.h stdlib.h string.h strings.h sys/time.h unistd.h pthread.h sys/wait.h signal.h sched.h]) 33 | 34 | dnl Checks for typedefs, structures, and compiler characteristics. 35 | AC_C_CONST 36 | AC_C_INLINE 37 | AC_TYPE_SIZE_T 38 | AC_HEADER_TIME 39 | AC_STRUCT_TM 40 | 41 | dnl Checks for library functions. 42 | AC_CHECK_FUNCS(memalign) 43 | AC_CHECK_FUNCS(strchr) 44 | AC_CHECK_FUNCS(strtoul) 45 | AC_CHECK_FUNCS(gettimeofday) 46 | AC_CHECK_FUNCS(gethrtime) 47 | AC_CHECK_FUNCS(gethrvtime) 48 | AC_CHECK_FUNCS(sched_yield) 49 | AC_CHECK_FUNCS(clone) 50 | AC_CHECK_FUNCS(yield) 51 | AC_CHECK_FUNCS(sginap) 52 | AC_CHECK_FUNCS(sched_setaffinity) 53 | ACX_PTHREAD([THREADLIBS="$PTHREAD_LIBS "]) 54 | 55 | dnl check for perfctr 56 | PERFCTR_LIBS="" 57 | if test "$with_perfctr" = "yes"; then 58 | AC_DEFINE(CILK_USE_PERFCTR, 1, "Use perfctr to measure critical path and work.") 59 | PERFCTR_LIBS=-lperfctr 60 | fi 61 | AC_SUBST(PERFCTR_LIBS) 62 | 63 | AC_DEFINE_UNQUOTED(CILKC_PTHREAD_LIBS,"$PTHREAD_LIBS",[The pthread libraries]) 64 | AC_DEFINE_UNQUOTED(CILKC_PTHREAD_CFLAGS,"$PTHREAD_CFLAGS",[To be passed to the C compiler when compiling code for pthreads]) 65 | AC_DEFINE_UNQUOTED(CILKC_PTHREAD_CC,"$PTHREAD_CC",[The C compiler to use when compiling code for pthreads]) 66 | 67 | if test "$with_gnu_ld" == "yes"; then 68 | AC_DEFINE(WITH_GNU_LD,1,[Define if you are using the GNU linker]) 69 | fi 70 | 71 | AC_CONFIG_FILES([FAQ/Makefile 72 | Makefile 73 | cilk2c/Makefile 74 | doc/Makefile 75 | doc/version.tex 76 | examples/Makefile 77 | runtime/Makefile 78 | support/Makefile]) 79 | 80 | AC_OUTPUT 81 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | MANUAL_SRC = defs.tex impl-notes.tex manual.tex cactus.eps intro.tex \ 2 | misc.tex fib-compile.fig lanref.tex model.eps people.tex cilk.bib \ 3 | fib.tex library-spec.tex model.fig prog-guide.tex copyright.tex \ 4 | fib2.tex supertech.sty version.tex cactus.pdf model.pdf 5 | 6 | EXTRA_DIST = manual.pdf $(MANUAL_SRC) version.tex.in 7 | 8 | manual.pdf: $(MANUAL_SRC) 9 | pdflatex manual 10 | bibtex manual 11 | pdflatex manual 12 | pdflatex manual 13 | 14 | clean-local: 15 | rm -f *.dvi *~ *.log *.aux *.bbl *.blg *.ps *.toc *.lof nohup.out 16 | rm -f manual.pdf 17 | 18 | -------------------------------------------------------------------------------- /doc/cactus.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zakkak/cilk/80f08cb5f21222e077fe478454b760c9734368be/doc/cactus.pdf -------------------------------------------------------------------------------- /doc/copyright.tex: -------------------------------------------------------------------------------- 1 | \chapter{Copyright and Disclaimers} 2 | \label{app:copyright} 3 | 4 | {\sysnameversion} is Copyright \copyright{} 2000-2003 Massachusetts 5 | Institute of Technology, Copyright \copyright{} 2000 Matteo Frigo, 6 | Copyright 2002-2003 Bradley C. Kuszmaul. 7 | 8 | {\sysnameversion} is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 21 | USA. 22 | 23 | -------------------------------------------------------------------------------- /doc/defs.tex: -------------------------------------------------------------------------------- 1 | % -*-latex-*- 2 | 3 | \newcommand{\doclearpage}{\thispagestyle{empty}\phantom{.}\newpage} 4 | 5 | % Macros identify the system. 6 | \newcommand{\cilktm}{Cilk$^{\mbox{\scriptsize TM}}$} 7 | \newcommand{\sysname}{Cilk} 8 | \newcommand{\sysnameversion}{Cilk \VERSION} 9 | \newcommand{\sysversion}{\VERSION} 10 | 11 | % Syntax environment. 12 | \newenvironment{syntax}{\par\begingroup\vspace*{1ex} 13 | \noindent\hspace{2em}\begin{tabular}{lll}}{\end{tabular} 14 | \par\vspace{1ex}\endgroup} 15 | 16 | % Code environment. 17 | %\newenvironment{code}{\tt\begin{tabbing} 18 | % mmmmm\=mmm\=mmm\=mmm\=mmm\=\kill}{\end{tabbing}\rm\normalsize} 19 | 20 | % Cilk keywords 21 | \newcommand{\cilkkw}[1]{{\tt #1}} % and NOT \texttt. italic tt sucks 22 | 23 | % Indexing 24 | \newcommand{\indexcat}[3]{{\index{#2 #1#3}\index{#1!#2#3}}} 25 | \newcommand{\indexcats}[3]{{\index{#2 #1#3}\index{#1s!#2#3}}} 26 | \newcommand{\indexsub}[3]{{\index{#2#3}\index{#1!#2#3}}} 27 | \newcommand{\indexsubt}[4]{{\index{#3#4}\index{#1!#3#4}\index{#2!#3#4}}} 28 | \newcommand{\indexsymmet}[3]{{\index{#2!#1#3}\index{#1!#2#3}}} 29 | \newcommand{\indexhf}[2]{{\indexcats{header file}{#1}{#2}}} 30 | \newcommand{\indexkw}[2]{{\index{#1 keyword@\texttt{#1} keyword#2}\index{keywords!#1@\texttt{#1}#2}}} 31 | %\newcommand{\indexfn}[2]{{\indexcats{function}{#1@\texttt{#1}}{#2}}} 32 | \newcommand{\indexopt}[2]{{\index{#1 option#2}}} 33 | \newcommand{\indexfn}[2]{{\index{#1 function#2}}} 34 | \newcommand{\indexvar}[2]{{\index{#1 variable#2}}} 35 | \newcommand{\indextype}[2]{{\index{#1 type#2}}} 36 | \newcommand{\indexmac}[2]{{\index{#1 macro#2}}} 37 | \newcommand{\indexseg}[2]{{\index{#1 segment#2}}} 38 | \newcommand{\indexsubfn}[3]{{\index{#2 function#3}\index{#1!#2#3}}} 39 | \newcommand{\indexsubtype}[3]{{\index{#2 type#3}\index{#1!#2#3}}} 40 | \newcommand{\indexsymmetfn}[3]{{\index{#2 function!#1#3}\index{#1!#2#3}}} 41 | \newcommand{\indexcatkw}[3]{{\index{#2 keyword@\texttt{#2} keyword!#1#3}\index{keywords!#2@\texttt{#2}#3}\index{#1 #2@#1 \texttt{#2}#3}}} 42 | \newcommand{\indexalloc}[1]{{\index{storage allocation#1}\index{memory allocation#1}\index{shared memory!allocation#1}}} 43 | \newcommand{\indextiming}[2]{{\index{scheduling!#1#2}\index{scheduling!timing#2}\index{scheduling!statistics#2}\index{timing!#1#2}\index{statistics!#1#2}\index{#1#2}}} 44 | \newcommand{\indextimingnest}[2]{{\index{scheduling!#1#2}\index{timing!#1#2}\index{statistics!#1#2}\index{#1#2}}} 45 | \newcommand{\indextim}[1]{{\index{scheduling!timing#1}\index{scheduling!statistics#1}\index{timing#1}\index{statistics#1}}} 46 | \newcommand{\indexrace}[1]{{\index{race#1}\index{data race#1}\index{Nondeterminator!data race#1}\index{debugging!data race#1}}} 47 | \newcommand{\seealso}[2]{{{\it see also\/} #1}} 48 | 49 | 50 | \ifnum\pdftexversion>13 51 | \def\pdfimage#1#{\grabpdfimage{#1}} 52 | \def\grabpdfimage#1#2{% 53 | \pdfximage#1{#2}\pdfrefximage\pdflastximage 54 | } 55 | \fi 56 | 57 | \newcommand{\image}[2]{ 58 | \ifx\pdfoutput\undefined 59 | \mbox{\epsfig{file=#1.eps,height=#2}}% 60 | \else 61 | \mbox{{\pdfimage height #2 {#1.pdf}}}% 62 | \fi} 63 | \ifx\pdfoutput\undefined\else\pdfcompresslevel=9\fi -------------------------------------------------------------------------------- /doc/fib-compile.fig: -------------------------------------------------------------------------------- 1 | #FIG 3.2 2 | Landscape 3 | Center 4 | Inches 5 | Letter 6 | 100.00 7 | Single 8 | -2 9 | 1200 2 10 | 6 900 2475 8850 3375 11 | 2 4 0 1 -1 7 0 0 -1 0.000 0 0 7 0 0 5 12 | 3300 3375 3300 2475 1800 2475 1800 3375 3300 3375 13 | 2 4 0 1 -1 7 0 0 -1 0.000 0 0 7 0 0 5 14 | 5700 3375 5700 2475 4200 2475 4200 3375 5700 3375 15 | 2 4 0 1 -1 7 0 0 -1 0.000 0 0 7 0 0 5 16 | 8100 3375 8100 2475 6600 2475 6600 3375 8100 3375 17 | 2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 1 0 2 18 | 2 1 1.00 60.00 120.00 19 | 900 3075 1800 3075 20 | 2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 1 0 2 21 | 2 1 1.00 60.00 120.00 22 | 3300 3075 4200 3075 23 | 2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 1 0 2 24 | 2 1 1.00 60.00 120.00 25 | 5700 3075 6600 3075 26 | 2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 1 0 2 27 | 2 1 1.00 60.00 120.00 28 | 8100 3075 8775 3075 29 | 4 0 -1 0 0 0 12 0.0000 4 105 1380 1875 2700 source-to-source\001 30 | 4 0 -1 0 0 0 12 0.0000 4 180 645 1875 2865 compiler\001 31 | 4 0 -1 0 0 2 15 0.0000 0 150 570 2700 3300 cilk2c\001 32 | 4 0 -1 0 0 0 12 0.0000 4 180 840 4275 2700 c-compiler\001 33 | 4 0 -1 0 0 2 15 0.0000 0 150 315 5325 3300 gcc\001 34 | 4 0 -1 0 0 0 12 0.0000 4 180 495 6675 2700 linking\001 35 | 4 0 -1 0 0 0 12 0.0000 4 135 465 6675 2865 loader\001 36 | 4 0 -1 0 0 2 15 0.0000 0 150 180 7875 3300 ld\001 37 | 4 0 -1 0 0 0 12 0.0000 4 135 510 1050 3000 fib.cilk\001 38 | 4 0 -1 0 0 0 12 0.0000 4 135 330 3525 3000 fib.c\001 39 | 4 0 -1 0 0 0 12 0.0000 4 135 330 5925 3000 fib.o\001 40 | 4 0 -1 0 0 0 12 0.0000 4 135 195 8325 3000 fib\001 41 | -6 42 | 2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 1 0 2 43 | 2 1 1.00 60.00 120.00 44 | 6900 1800 6900 2475 45 | 4 0 -1 0 0 0 12 0.0000 4 135 300 7050 2100 Cilk\001 46 | 4 0 -1 0 0 0 12 0.0000 4 180 1245 7050 2340 Runtime System\001 47 | -------------------------------------------------------------------------------- /doc/fib.tex: -------------------------------------------------------------------------------- 1 | \begin{verbatim} 2 | struct _fib_frame { 3 | StackFrame header; 4 | struct {int n;} scope0; 5 | struct {int x;int y;} scope1; 6 | }; 7 | int fib(int n) 8 | { 9 | struct _fib_frame *_frame; 10 | _INIT_FRAME(_frame,sizeof(struct _fib_frame),_fib_sig); 11 | { 12 | if (n < 2) 13 | {_BEFORE_RETURN_FAST();return (n);} 14 | else { 15 | int x;int y; 16 | { _frame->header.entry=1; 17 | _frame->scope0.n=n; 18 | x=fib(n-1); 19 | _XPOP_FRAME_RESULT(_frame,0,x); 20 | } 21 | { _frame->header.entry=2; 22 | _frame->scope1.x=x; 23 | y=fib(n-2); 24 | _XPOP_FRAME_RESULT(_frame,0,y); 25 | } 26 | /* sync */; 27 | {_BEFORE_RETURN_FAST();return (x+y);} 28 | } 29 | } 30 | } 31 | \end{verbatim} 32 | -------------------------------------------------------------------------------- /doc/fib2.tex: -------------------------------------------------------------------------------- 1 | \begin{verbatim} 2 | static void _fib_slow(struct _fib_frame *_frame) 3 | { 4 | int n; 5 | switch (_frame->header.entry) { 6 | case 1: goto _sync1; 7 | case 2: goto _sync2; 8 | case 3: goto _sync3; 9 | } 10 | n=_frame->scope0.n; 11 | { 12 | if (n < 2) 13 | {_SET_RESULT((n));_BEFORE_RETURN_SLOW();return;} 14 | else { 15 | { int _temp0; 16 | _frame->header.entry=1; 17 | _frame->scope0.n=n; 18 | _temp0=fib(n-1); 19 | _XPOP_FRAME_RESULT(_frame,/* return nothing */,_temp0); 20 | _frame->scope1.x=_temp0; 21 | if (0) { _sync1:; n=_frame->scope0.n; } 22 | } 23 | { int _temp1; 24 | _frame->header.entry=2; 25 | _temp1=fib(n-2); 26 | _XPOP_FRAME_RESULT(_frame,/* return nothing */,_temp1); 27 | _frame->scope1.y=_temp1; 28 | if (0) { _sync2:; } 29 | } 30 | { _frame->header.entry=3; 31 | if (_SYNC) { 32 | return; 33 | _sync3:; 34 | } 35 | } 36 | { _SET_RESULT((_frame->scope1.x+_frame->scope1.y)); 37 | _BEFORE_RETURN_SLOW();return; 38 | } 39 | } 40 | } 41 | } 42 | \end{verbatim} 43 | -------------------------------------------------------------------------------- /doc/manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zakkak/cilk/80f08cb5f21222e077fe478454b760c9734368be/doc/manual.pdf -------------------------------------------------------------------------------- /doc/manual.tex: -------------------------------------------------------------------------------- 1 | % -*-latex-*- 2 | \documentclass[11pt,twoside]{report} 3 | \usepackage{ifthen} 4 | \usepackage{epsfig} 5 | 6 | % Macro definitions. 7 | \input{version} 8 | \input{defs} 9 | \usepackage{supertech} 10 | 11 | % 12 | % Use \notestrue to enable margin comments. For generating 13 | % the manual, set \notesfalse 14 | % 15 | %\notesfalse 16 | \notesfalse 17 | 18 | %\note{The standard page layout looks better to me (especially at twoside) 19 | %--- athena} 20 | 21 | % Page layout. 22 | %\oddsidemargin .5 in 23 | %\evensidemargin 0 in 24 | %\topmargin -0.5 in 25 | %\textwidth 6 in 26 | %\textheight 8.8 in 27 | 28 | \begin{document} 29 | 30 | 31 | % Title. 32 | \begin{titlepage} 33 | 34 | \begin{center} 35 | \vspace*{4cm} 36 | {\huge 37 | \textbf{\sysnameversion{}\\[.5cm] 38 | Reference Manual}}\\[.8cm] 39 | 40 | {\large 41 | Supercomputing Technologies Group\\ 42 | MIT Laboratory for Computer Science\\[.3cm] 43 | \texttt{http://supertech.lcs.mit.edu/cilk}\\[.6cm] 44 | } 45 | 46 | \vfill 47 | \hrule 48 | \vspace{.4cm} 49 | {\small Cilk is a trademark of the Massachusetts Institute of 50 | Technology.\\ 51 | The Cilk project is supported in part by NSF Grant E1A-9975036. 52 | Previous support was provided in part by DARPA Grant 53 | F30602-97-1-0270.\\ 54 | This manual is Copyright \copyright{} 1998 Massachusetts Institute of 55 | Technology.} 56 | \end{center} 57 | \end{titlepage} 58 | 59 | \doclearpage 60 | 61 | \pagestyle{headings} 62 | 63 | 64 | \pagenumbering{roman} 65 | 66 | 67 | % Preface: Release notes 68 | \addcontentsline{toc}{chapter}{Release Notes} 69 | \input{misc.tex} 70 | \cleardoublepage 71 | 72 | 73 | % Table of contents. 74 | \tableofcontents 75 | \cleardoublepage 76 | 77 | \pagenumbering{arabic} 78 | 79 | 80 | \input{intro.tex} 81 | 82 | \input{prog-guide.tex} 83 | 84 | \input{lanref.tex} 85 | 86 | \input{library-spec.tex} 87 | 88 | \input{impl-notes.tex} 89 | 90 | \cleardoublepage 91 | 92 | \appendix 93 | 94 | \input{people.tex} 95 | \input{copyright} 96 | 97 | \nocite{Blumofe92} 98 | \bibliographystyle{plain} 99 | \bibliography{cilk} 100 | 101 | \end{document} 102 | 103 | -------------------------------------------------------------------------------- /doc/model.fig: -------------------------------------------------------------------------------- 1 | #FIG 3.2 2 | Portrait 3 | Center 4 | Inches 5 | Letter 6 | 100.00 7 | Single 8 | -2 9 | 1200 2 10 | 6 4425 2025 8025 2925 11 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 5025 2475 309 309 5025 2475 5325 2550 12 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 6225 2475 309 309 6225 2475 6525 2550 13 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 7425 2475 309 309 7425 2475 7725 2550 14 | 2 1 0 1 -1 6 1 0 31 0.000 0 0 11 1 0 2 15 | 2 1 1.00 60.00 120.00 16 | 5325 2475 5925 2475 17 | 2 1 0 1 -1 6 1 0 31 0.000 0 0 11 1 0 2 18 | 2 1 1.00 60.00 120.00 19 | 6525 2475 7125 2475 20 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 21 | 8025 2925 8025 2025 4425 2025 4425 2925 8025 2925 22 | -6 23 | 6 8400 3600 9450 4500 24 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 8925 4050 309 309 8925 4050 9225 4125 25 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 26 | 9450 4500 9450 3600 8400 3600 8400 4500 9450 4500 27 | -6 28 | 6 4350 3600 7950 4500 29 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 4950 4050 309 309 4950 4050 5250 4125 30 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 6150 4050 309 309 6150 4050 6450 4125 31 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 7350 4050 309 309 7350 4050 7650 4125 32 | 2 1 0 1 -1 6 1 0 31 0.000 0 0 11 1 0 2 33 | 2 1 1.00 60.00 120.00 34 | 5250 4050 5850 4050 35 | 2 1 0 1 -1 6 1 0 31 0.000 0 0 11 1 0 2 36 | 2 1 1.00 60.00 120.00 37 | 6450 4050 7050 4050 38 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 39 | 7950 4500 7950 3600 4350 3600 4350 4500 7950 4500 40 | -6 41 | 6 525 3600 1575 4500 42 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 1050 4050 309 309 1050 4050 1350 4125 43 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 44 | 1575 4500 1575 3600 525 3600 525 4500 1575 4500 45 | -6 46 | 6 2175 3600 3225 4500 47 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 2700 4050 309 309 2700 4050 3000 4125 48 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 49 | 3225 4500 3225 3600 2175 3600 2175 4500 3225 4500 50 | -6 51 | 6 4650 5100 5700 6000 52 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 5175 5550 309 309 5175 5550 5475 5625 53 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 54 | 5700 6000 5700 5100 4650 5100 4650 6000 5700 6000 55 | -6 56 | 6 6450 5100 7500 6000 57 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 6975 5550 309 309 6975 5550 7275 5625 58 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 59 | 7500 6000 7500 5100 6450 5100 6450 6000 7500 6000 60 | -6 61 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 1950 2475 309 309 1950 2475 2250 2550 62 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 3150 2475 309 309 3150 2475 3450 2550 63 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 750 2475 309 309 750 2475 1050 2550 64 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 2100 1050 309 309 2100 1050 2400 1125 65 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 4350 1050 309 309 4350 1050 4650 1125 66 | 1 3 0 1 -1 24 1 0 20 0.000 1 0.0000 6525 1050 309 309 6525 1050 6825 1125 67 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 14 0 0 5 68 | 7200 1500 7200 600 1500 600 1500 1500 7200 1500 69 | 2 1 0 1 -1 6 1 0 31 0.000 0 0 11 1 0 2 70 | 2 1 1.00 60.00 120.00 71 | 1050 2475 1650 2475 72 | 2 1 0 1 -1 6 1 0 31 0.000 0 0 11 1 0 2 73 | 2 1 1.00 60.00 120.00 74 | 2250 2475 2850 2475 75 | 2 4 0 1 -1 6 2 0 31 0.000 0 0 11 0 0 5 76 | 3750 2925 3750 2025 150 2025 150 2925 3750 2925 77 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 78 | 2 1 1.00 60.00 120.00 79 | 2400 1050 4050 1050 80 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 81 | 2 1 1.00 60.00 120.00 82 | 4650 1050 6225 1050 83 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 84 | 2 1 1.00 60.00 120.00 85 | 3442 2392 6300 1275 86 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 87 | 2 1 1.00 60.00 120.00 88 | 4507 1320 4890 2197 89 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 90 | 2 1 1.00 60.00 120.00 91 | 7425 2175 6675 1350 92 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 93 | 2 1 1.00 60.00 120.00 94 | 817 2775 982 3765 95 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 96 | 2 1 1.00 60.00 120.00 97 | 2077 2760 2557 3780 98 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 99 | 2 1 1.00 60.00 120.00 100 | 1350 4050 2925 2700 101 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 102 | 2 1 1.00 60.00 120.00 103 | 2775 3757 3150 2775 104 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 105 | 2 1 1.00 60.00 120.00 106 | 4980 2790 4950 3750 107 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 108 | 2 1 1.00 60.00 120.00 109 | 7350 3750 7380 2782 110 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 111 | 2 1 1.00 60.00 120.00 112 | 4950 4350 5092 5257 113 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 114 | 2 1 1.00 60.00 120.00 115 | 6300 4327 6795 5280 116 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 117 | 2 1 1.00 60.00 120.00 118 | 5415 5377 7072 4192 119 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 120 | 2 1 1.00 60.00 120.00 121 | 7102 5295 7297 4357 122 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 123 | 2 1 1.00 60.00 120.00 124 | 6487 2647 8625 3975 125 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 126 | 2 1 1.00 60.00 120.00 127 | 8925 3750 7650 2700 128 | 2 1 0 1 -1 24 1 0 20 0.000 0 0 -1 1 0 2 129 | 2 1 1.00 60.00 120.00 130 | 1882 1275 892 2212 131 | -------------------------------------------------------------------------------- /doc/model.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zakkak/cilk/80f08cb5f21222e077fe478454b760c9734368be/doc/model.pdf -------------------------------------------------------------------------------- /doc/people.tex: -------------------------------------------------------------------------------- 1 | % -*-latex-*- 2 | \chapter{People} 3 | \label{app:people} 4 | 5 | The Cilk project is led by Prof. Charles E. Leiserson of the MIT 6 | Laboratory for Computer Science and has been funded in part by DARPA 7 | Grant F30602-97-1-0270. 8 | 9 | The current maintainer of Cilk is Bradley C. Kuszmaul 10 | (\texttt{bradley@bradley.lcs.mit.edu}), who is responsible for the 11 | {\sysnameversion} release. 12 | 13 | {\sysnameversion} is the product of the effort of many people over 14 | many years. The following people contributed code, example programs, 15 | and/or documentation to the {\sysnameversion} system: 16 | 17 | \begin{quote} 18 | \noindent 19 | Guang-Ien Cheng\\ 20 | Don Dailey\\ 21 | Mingdong Feng\\ 22 | Bradley C. Kuszmaul\\ 23 | Charles E.\ Leiserson\\ 24 | Phil Lisiecki\\ 25 | Alberto Medina\\ 26 | Ofra Pavlovitz\\ 27 | Harald Prokop\\ 28 | Keith H.\ Randall\\ 29 | Bin Song\\ 30 | Andy Stark\\ 31 | Volker Strumpen\\ 32 | \end{quote} 33 | 34 | \noindent All those who have worked on previous versions of Cilk: 35 | \begin{quote} 36 | \noindent 37 | Robert D. Blumofe\\ 38 | Michael Halbherr\\ 39 | Christopher F. Joerg\\ 40 | Howard Lu\\ 41 | Robert Miller\\ 42 | Aske Plaat\\ 43 | Richard Tauriello\\ 44 | Daricha Techopitayakul\\ 45 | Yuli Zhou\\ 46 | \end{quote} 47 | 48 | \pagebreak[3] 49 | 50 | %We gratefully acknowledge the contributions of many others, including: 51 | \noindent Finally, thanks to those who have spent valuable time with Cilk and 52 | contributed with their experience: 53 | \begin{quote} 54 | \noindent 55 | Arvind\\ 56 | Reid Barton\\ 57 | Ching Law\\ 58 | John Litvin\\ 59 | Igor Lyubashevskiy\\ 60 | Rolf Riesen\\ 61 | Andy Shaw\\ 62 | Mike Stupak\\ 63 | Adrian M.\ Soviani\\ 64 | Sivan Toledo\\ 65 | Svetoslav Tzvetkov\\ 66 | \end{quote} 67 | -------------------------------------------------------------------------------- /doc/version.tex: -------------------------------------------------------------------------------- 1 | \def\VERSION{5.4.6} 2 | -------------------------------------------------------------------------------- /doc/version.tex.in: -------------------------------------------------------------------------------- 1 | \def\VERSION{@VERSION@} 2 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # Simulate CILK before installation 2 | CILK=$(top_builddir)/support/cilkclocal 3 | 4 | SUFFIXES = .cilk 5 | NPROC = 4 6 | PROGFLAGS = --nproc $(NPROC) --yield 7 | 8 | CILKFLAGS=@CFLAGS@ 9 | CILKCOMPILE = $(CILK) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CILKFLAGS) $(CILKFLAGS) 10 | CILKLD = $(CILK) 11 | CILKLINK = $(CILKLD) $(AM_CILKFLAGS) $(CILKFLAGS) $(PERFCTR_LIBS) $(LDFLAGS) -o $@ 12 | LINK=$(CILKLINK) 13 | 14 | noinst_PROGRAMS=hello fib fib-serial testall ck magic knapsack queens \ 15 | cilksort fft test-locks bucket cholesky game nfib kalah matmul lu plu \ 16 | heat test-errno strassen rectmul spacemul \ 17 | test-void-func \ 18 | velin \ 19 | cholesky-lib \ 20 | nfib-lib 21 | MOSTLYCLEANFILES=pragma.E pragma.E.cilk pragma.E.c deprecated.log deprecated2.out deprecated2.log deprecated2.i 22 | 23 | GETOPTIONS_SRC = getoptions.c getoptions.h 24 | 25 | fib_serial_SOURCES = fib-serial.c 26 | fib-serial$(EXEEXT): $(fib_serial_OBJECTS) $(fib_serial_DEPENDENCIES) 27 | @rm -f fib-serial 28 | $(CC) -o $@ $(fib_serial_OBJECTS) $(LIBS) 29 | 30 | hello_SOURCES=hello.cilk 31 | fib_SOURCES=fib.cilk 32 | velin_SOURCES=velin.cilk 33 | testall_SOURCES=testall.cilk rand.cilk 34 | test_locks_SOURCES=test-locks.cilk 35 | test_errno_SOURCES=test-errno.cilk 36 | ck_SOURCES=ck.cilk rand.cilk $(GETOPTIONS_SRC) 37 | magic_SOURCES=magic.cilk $(GETOPTIONS_SRC) 38 | knapsack_SOURCES=knapsack.cilk $(GETOPTIONS_SRC) 39 | queens_SOURCES=queens.cilk 40 | cilksort_SOURCES=cilksort.cilk $(GETOPTIONS_SRC) 41 | fft_SOURCES=fft.cilk $(GETOPTIONS_SRC) 42 | bucket_SOURCES=bucket.cilk $(GETOPTIONS_SRC) 43 | cholesky_SOURCES=cholesky.cilk rand.cilk $(GETOPTIONS_SRC) 44 | cholesky_lib_SOURCES=cholesky-lib.cilk rand.cilk $(GETOPTIONS_SRC) 45 | matmul_SOURCES=matmul.cilk rand.cilk $(GETOPTIONS_SRC) 46 | game_SOURCES=game.cilk $(GETOPTIONS_SRC) 47 | nfib_SOURCES=nfib.cilk 48 | nfib_lib_SOURCES=nfib-lib.cilk 49 | kalah_SOURCES=kalah.cilk 50 | lu_SOURCES=lu.cilk $(GETOPTIONS_SRC) 51 | plu_SOURCES=plu.cilk $(GETOPTIONS_SRC) 52 | heat_SOURCES=heat.cilk $(GETOPTIONS_SRC) 53 | strassen_SOURCES=strassen.cilk $(GETOPTIONS_SRC) 54 | rectmul_SOURCES=rectmul.cilk $(GETOPTIONS_SRC) 55 | spacemul_SOURCES=spacemul.cilk $(GETOPTIONS_SRC) 56 | test_void_func_SOURCES=test-void-func.cilk 57 | 58 | EXTRA_DIST = knapsack-example1.input knapsack-example2.input \ 59 | knapsack-example3.input 60 | 61 | check: hello testall fft fib lu matmul cilksort heat test-locks test-errno 62 | @echo "Runnig Cilk tests. This will take a while." 63 | ./hello $(PROGFLAGS) 64 | ./test-void-func $(PROGFLAGS) 65 | ./test-locks $(PROGFLAGS) 66 | ./test-errno $(PROGFLAGS) 67 | ./testall $(PROGFLAGS) 68 | ./fft $(PROGFLAGS) -c 69 | ./fib $(PROGFLAGS) 35 70 | ./lu $(PROGFLAGS) -n 1024 71 | ./matmul $(PROGFLAGS) 1066 72 | ./cilksort $(PROGFLAGS) -n 3000000 73 | ./heat $(PROGFLAGS) 74 | ./strassen $(PROGFLAGS) 75 | ./velin $(PROGFLAGS) 76 | 77 | .cilk.o: 78 | $(CILKCOMPILE) -c -o $@ $< 79 | -------------------------------------------------------------------------------- /examples/fib-serial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int fib(int n) 5 | { 6 | if (n < 2) 7 | return (n); 8 | else { 9 | int x, y; 10 | x = fib(n - 1); 11 | y = fib(n - 2); 12 | return (x + y); 13 | } 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | int n, result; 19 | 20 | if (argc != 2) { 21 | fprintf(stderr, "Usage: fib [] \n"); 22 | exit(1); 23 | } 24 | n = atoi(argv[1]); 25 | result = fib(n); 26 | 27 | printf("Result: %d\n", result); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/fib.cilk: -------------------------------------------------------------------------------- 1 | static const char *ident __attribute__((__unused__)) 2 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/fib.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 3 | 4 | /* 5 | * Copyright (c) 1994-2003 Massachusetts Institute of Technology 6 | * Copyright (c) 2003 Bradley C. Kuszmaul 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | * 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | cilk int fib(int n) 29 | { 30 | if (n < 2) 31 | return (n); 32 | else { 33 | int x, y; 34 | x = spawn fib(n - 1); 35 | y = spawn fib(n - 2); 36 | sync; 37 | return (x + y); 38 | } 39 | } 40 | 41 | cilk int main(int argc, char *argv[]) 42 | { 43 | int n, result; 44 | 45 | if (argc != 2) { 46 | fprintf(stderr, "Usage: fib [] \n"); 47 | Cilk_exit(1); 48 | } 49 | n = atoi(argv[1]); 50 | result = spawn fib(n); 51 | sync; 52 | 53 | printf("Result: %d\n", result); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /examples/game.cilk: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a simple game to test aborts. Rules: There are two players 3 | * on a n x m board. The players alternate in putting a coin in 4 | * position (i,j). When (i,j) is filled with a coin, all positions 5 | * (i',j') for all i' <= i and j' <= j are filled as well. (Multiple 6 | * coins count as one.) The player who fills the board loses. 7 | * 8 | * Homework: prove that the first player has a winning strategy. 9 | * 10 | * I make no attempt to be clever in this program. 11 | * 12 | * Author: Matteo Frigo 13 | * This game was suggested by David Finberg, dfinberg@mit.edu . 14 | */ 15 | static const char *ident __attribute__((__unused__)) 16 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/game.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 17 | 18 | #include 19 | #include 20 | #include 21 | #include "config.h" 22 | #if HAVE_MALLOC_H 23 | #include 24 | #endif 25 | #include "getoptions.h" 26 | 27 | #define MAX_PROC 16 /* max # of processors */ 28 | 29 | #define M 5 30 | #define N 5 31 | 32 | /* well... this is one attempt to be clever */ 33 | #define FOR_ALL_POSITIONS(i,j) \ 34 | for (i = N - 1; i >= 0; --i) \ 35 | for (j = M - 1; j >= 0; --j) 36 | 37 | #define EMPTY 0 38 | #define COIN 1 39 | 40 | #define WIN 1000 41 | #define LOSE (-WIN) 42 | 43 | typedef int BOARD[N][M]; 44 | typedef int (*BOARDHACK)[M]; 45 | typedef int INDEX; 46 | 47 | int naborts[MAX_PROC]; 48 | 49 | int usage() 50 | /* 51 | * Not very useful since there are no options, but anyway to be 52 | * consistent with the other examples. 53 | */ 54 | { 55 | printf("\n" 56 | "This is a simple game to test aborts.\n" 57 | "Rules: There are two players on a n x m board. While the board\n" 58 | "is not full, each player puts a coin in position (i,j) and in\n" 59 | "all positions (i',j') for all i' <= i and j' <= j.\n" 60 | "(Multiple coins count as one.)\n" 61 | "The player who fills the board loses.\n\n" 62 | "\n" 63 | "Command: game [] [] \n\n" 64 | "Options: -h for this help\n" 65 | "Author: Matteo Frigo, athena@theory.lcs.mit.edu\n\n"); 66 | return 1; 67 | } 68 | 69 | void init_board(BOARD b) 70 | { 71 | INDEX i, j; 72 | 73 | FOR_ALL_POSITIONS(i, j) { 74 | b[i][j] = EMPTY; 75 | } 76 | } 77 | 78 | /* test if the move is legal */ 79 | #define legal(b, i, j) (b[i][j] == EMPTY) 80 | 81 | /* produce a new board nb with the given move */ 82 | void move(BOARD b, INDEX r, INDEX c, BOARD nb) 83 | { 84 | INDEX i, j; 85 | 86 | FOR_ALL_POSITIONS(i, j) { 87 | nb[i][j] = b[i][j]; 88 | } 89 | 90 | for (i = 0; i <= r; ++i) 91 | for (j = 0; j <= c; ++j) 92 | nb[i][j] = COIN; 93 | } 94 | 95 | /* return true if the position is lost */ 96 | #define lostp(b) (b[N - 1][M - 1] == COIN) 97 | 98 | /* do the negamax search */ 99 | cilk int negamax(BOARDHACK b, INDEX *movei, INDEX *movej, 100 | int alpha, int beta, int depth) 101 | { 102 | INDEX i, j; 103 | INDEX dummyi, dummyj; /* not used */ 104 | int done; 105 | 106 | inlet void catch(int evaluation, INDEX i1, INDEX j1, INDEX test) { 107 | Cilk_assert(test == i1 + j1); 108 | evaluation = -evaluation; 109 | 110 | if (evaluation > alpha) { 111 | alpha = evaluation; 112 | /* record the best so far */ 113 | /* TODO: how do we communicate new alpha to children? */ 114 | *movei = i1; 115 | *movej = j1; 116 | } 117 | if (alpha >= beta) { 118 | done = 1; 119 | ++naborts[Self]; 120 | abort; 121 | } 122 | } 123 | 124 | if (lostp(b)) 125 | return WIN - depth; /* winning earlier is better */ 126 | 127 | done = 0; 128 | 129 | FOR_ALL_POSITIONS(i, j) { 130 | if (legal(b, i, j)) { 131 | int (*nb)[M] = Cilk_alloca(sizeof(BOARD)); 132 | 133 | move(b, i, j, nb); 134 | catch( 135 | spawn negamax(nb, &dummyi, &dummyj, -beta, -alpha, 136 | depth + 1), i, j, i + j 137 | ); 138 | 139 | if (done) 140 | break; 141 | } 142 | } 143 | sync; 144 | 145 | return alpha; 146 | } 147 | 148 | char *specifiers[] = 149 | {"-benchmark", "-h", 0}; 150 | int opt_types[] = 151 | {BENCHMARK, BOOLARG, 0}; 152 | 153 | cilk int main(int argc, char *argv[]) 154 | { 155 | INDEX i, j; 156 | int (*b)[M]; 157 | int best = 1; 158 | int first = 1; 159 | int prev_best = 1; 160 | int k, n, player, benchmark, help; 161 | Cilk_time tm_begin, tm_elapsed; 162 | Cilk_time wk_begin, wk_elapsed; 163 | Cilk_time cp_begin, cp_elapsed; 164 | 165 | get_options(argc, argv, specifiers, opt_types, &benchmark, &help); 166 | 167 | if (help) 168 | return usage(); 169 | 170 | for (k = 0; k < MAX_PROC; ++k) 171 | naborts[i] = 0; 172 | 173 | b = malloc(sizeof(BOARD)); 174 | 175 | init_board(b); 176 | player = 0; 177 | 178 | /* Timing. "Start" timers */ 179 | sync; 180 | cp_begin = Cilk_user_critical_path; 181 | wk_begin = Cilk_user_work; 182 | tm_begin = Cilk_get_wall_time(); 183 | 184 | while (!lostp(b)) { 185 | player = !(player); 186 | best = spawn negamax(b, &i, &j, -100000, 100000, 0); 187 | sync; 188 | 189 | printf("%s found best move at %d,%d\n", 190 | ((player) ? "White" : "Black"), i, j); 191 | 192 | if (first) { 193 | Cilk_assert(best >= 0); 194 | first = 0; 195 | } else { 196 | Cilk_assert(best == -(prev_best + (prev_best > 0 ? 1 : -1))); 197 | } 198 | 199 | prev_best = best; 200 | 201 | move(b, i, j, b); 202 | for (i = 0; i < N; ++i) { 203 | for (j = 0; j < M; ++j) 204 | printf("%d ", b[i][j]); 205 | printf("\n"); 206 | } 207 | printf("\n"); 208 | } 209 | 210 | /* Timing. "Stop" timers */ 211 | tm_elapsed = Cilk_get_wall_time() - tm_begin; 212 | wk_elapsed = Cilk_user_work - wk_begin; 213 | cp_elapsed = Cilk_user_critical_path - cp_begin; 214 | 215 | for (k = n = 0; k < MAX_PROC; ++k) 216 | n += naborts[k]; 217 | 218 | printf("%s wins. Total # of aborts %d\n\n", 219 | ((!(player)) ? "White" : "Black"), n); 220 | 221 | printf("\nCilk Example: game\n"); 222 | printf(" running on %d processor%s\n\n", 223 | Cilk_active_size, Cilk_active_size > 1 ? "s" : ""); 224 | printf("Running time = %4f s\n", Cilk_wall_time_to_sec(tm_elapsed)); 225 | printf("Work = %4f s\n", Cilk_time_to_sec(wk_elapsed)); 226 | printf("Critical path = %4f s\n\n", Cilk_time_to_sec(cp_elapsed)); 227 | 228 | return 0; 229 | } 230 | -------------------------------------------------------------------------------- /examples/getoptions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* Used by example programs to evaluate command line options */ 8 | 9 | void get_options(int argc, char *argv[], char *specs[], int *types,...) 10 | { 11 | va_list ap; 12 | int type, i; 13 | int *intval; 14 | double *doubleval; 15 | long *longval; 16 | char *stringval; 17 | 18 | va_start(ap, types); 19 | 20 | while (((type = *types++) != 0) && (specs != 0)) { 21 | switch (type) { 22 | case INTARG: 23 | intval = (int *) va_arg(ap, int *); 24 | for (i = 1; i < (argc - 1); i++) 25 | if (!(strcmp(argv[i], specs[0]))) { 26 | *intval = atoi(argv[i + 1]); 27 | argv[i][0] = 0; 28 | argv[i + 1][0] = 0; 29 | } 30 | break; 31 | case DOUBLEARG: 32 | doubleval = (double *) va_arg(ap, double *); 33 | for (i = 1; i < (argc - 1); i++) 34 | if (!(strcmp(argv[i], specs[0]))) { 35 | *doubleval = atof(argv[i + 1]); 36 | argv[i][0] = 0; 37 | argv[i + 1][0] = 0; 38 | } 39 | break; 40 | case LONGARG: 41 | longval = (long *) va_arg(ap, long *); 42 | for (i = 1; i < (argc - 1); i++) 43 | if (!(strcmp(argv[i], specs[0]))) { 44 | *longval = atol(argv[i + 1]); 45 | argv[i][0] = 0; 46 | argv[i + 1][0] = 0; 47 | } 48 | break; 49 | case BOOLARG: 50 | intval = (int *) va_arg(ap, int *); 51 | *intval = 0; 52 | for (i = 1; i < argc; i++) 53 | if (!(strcmp(argv[i], specs[0]))) { 54 | *intval = 1; 55 | argv[i][0] = 0; 56 | } 57 | break; 58 | case STRINGARG: 59 | stringval = (char *) va_arg(ap, char *); 60 | for (i = 1; i < (argc - 1); i++) 61 | if (!(strcmp(argv[i], specs[0]))) { 62 | strcpy(stringval, argv[i + 1]); 63 | argv[i][0] = 0; 64 | argv[i + 1][0] = 0; 65 | } 66 | break; 67 | case BENCHMARK: 68 | intval = (int *) va_arg(ap, int *); 69 | *intval = 0; 70 | for (i = 1; i < argc; i++) { 71 | if (!(strcmp(argv[i], specs[0]))) { 72 | *intval = 2; 73 | if ((i + 1) < argc) { 74 | if (!(strcmp(argv[i + 1], "short"))) 75 | *intval = 1; 76 | if (!(strcmp(argv[i + 1], "medium"))) 77 | *intval = 2; 78 | if (!(strcmp(argv[i + 1], "long"))) 79 | *intval = 3; 80 | argv[i + 1][0] = 0; 81 | } 82 | argv[i][0] = 0; 83 | } 84 | } 85 | break; 86 | } 87 | specs++; 88 | } 89 | va_end(ap); 90 | 91 | for (i = 1; i < argc; i++) 92 | if (argv[i][0] != 0) 93 | printf("\nInvalid option: %s\n", argv[i]); 94 | 95 | } 96 | -------------------------------------------------------------------------------- /examples/getoptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Function to evaluate argv[]. specs is a 0 terminated array of command 3 | * line options and types an array that stores the type as one of 4 | */ 5 | #define INTARG 1 6 | #define DOUBLEARG 2 7 | #define LONGARG 3 8 | #define BOOLARG 4 9 | #define STRINGARG 5 10 | #define BENCHMARK 6 11 | /* 12 | * for each specifier. Benchmark is specific for cilk samples. 13 | * -benchmark or -benchmark medium sets integer to 2 14 | * -benchmark short returns 1 15 | * -benchmark long returns 2 16 | * a boolarg is set to 1 if the specifier appears in the option list ow. 0 17 | * The variables must be given in the same order as specified in specs. 18 | */ 19 | 20 | void get_options(int argc, char *argv[], char *specs[], int *types,...); 21 | -------------------------------------------------------------------------------- /examples/hello.cilk: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | cilk int main(int argc, char *argv[]) 4 | { 5 | printf("Hello, world!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /examples/knapsack-example1.input: -------------------------------------------------------------------------------- 1 | 3 90 2 | 100 80 3 | 80 45 4 | 80 45 5 | -------------------------------------------------------------------------------- /examples/knapsack-example2.input: -------------------------------------------------------------------------------- 1 | 28 1120 2 | 500 96 3 | 491 100 4 | 522 96 5 | 510 96 6 | 500 95 7 | 480 99 8 | 489 99 9 | 524 100 10 | 513 102 11 | 513 104 12 | 516 95 13 | 506 98 14 | 493 106 15 | 500 99 16 | 505 104 17 | 521 105 18 | 518 102 19 | 512 101 20 | 495 98 21 | 486 104 22 | 496 100 23 | 523 95 24 | 486 106 25 | 511 99 26 | 514 103 27 | 522 93 28 | 491 103 29 | 488 101 30 | 31 | -------------------------------------------------------------------------------- /examples/knapsack-example3.input: -------------------------------------------------------------------------------- 1 | 30 900 2 | 15 23 3 | 22 12 4 | 17 42 5 | 1 13 6 | 32 21 7 | 65 43 8 | 23 56 9 | 4 7 10 | 4 8 11 | 32 42 12 | 51 32 13 | 22 12 14 | 17 24 15 | 12 13 16 | 23 21 17 | 56 47 18 | 23 65 19 | 6 7 20 | 4 7 21 | 32 42 22 | 22 42 23 | 59 32 24 | 23 12 25 | 12 24 26 | 12 13 27 | 23 21 28 | 39 48 29 | 22 65 30 | 6 7 31 | 4 7 32 | 33 42 33 | 34 | -------------------------------------------------------------------------------- /examples/matmul.cilk: -------------------------------------------------------------------------------- 1 | /* 2 | * Rectangular matrix multiplication. 3 | * 4 | * See the paper ``Cache-Oblivious Algorithms'', by 5 | * Matteo Frigo, Charles E. Leiserson, Harald Prokop, and 6 | * Sridhar Ramachandran, FOCS 1999, for an explanation of 7 | * why this algorithm is good for caches. 8 | * 9 | * Author: Matteo Frigo 10 | */ 11 | static const char *ident __attribute__((__unused__)) 12 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/matmul.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 13 | 14 | /* 15 | * Copyright (c) 2003 Massachusetts Institute of Technology 16 | * 17 | * This program is free software; you can redistribute it and/or modify 18 | * it under the terms of the GNU General Public License as published by 19 | * the Free Software Foundation; either version 2 of the License, or 20 | * (at your option) any later version. 21 | * 22 | * This program is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | * GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program; if not, write to the Free Software 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 | * 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define REAL float 39 | 40 | extern int Cilk_rand(void); 41 | 42 | void zero(REAL *A, int n) 43 | { 44 | int i, j; 45 | 46 | for (i = 0; i < n; i++) { 47 | for (j = 0; j < n; j++) { 48 | A[i * n + j] = 0.0; 49 | } 50 | } 51 | } 52 | 53 | void init(REAL *A, int n) 54 | { 55 | int i, j; 56 | 57 | for (i = 0; i < n; i++) { 58 | for (j = 0; j < n; j++) { 59 | A[i * n + j] = (double)Cilk_rand(); 60 | } 61 | } 62 | } 63 | 64 | double maxerror(REAL *A, REAL *B, int n) 65 | { 66 | int i, j; 67 | double error = 0.0; 68 | 69 | for (i = 0; i < n; i++) { 70 | for (j = 0; j < n; j++) { 71 | double diff = (A[i * n + j] - B[i * n + j]) / A[i * n + j]; 72 | if (diff < 0) 73 | diff = -diff; 74 | if (diff > error) 75 | error = diff; 76 | } 77 | } 78 | return error; 79 | } 80 | 81 | void iter_matmul(REAL *A, REAL *B, REAL *C, int n) 82 | { 83 | int i, j, k; 84 | 85 | for (i = 0; i < n; i++) 86 | for (k = 0; k < n; k++) { 87 | REAL c = 0.0; 88 | for (j = 0; j < n; j++) 89 | c += A[i * n + j] * B[j * n + k]; 90 | C[i * n + k] = c; 91 | } 92 | } 93 | 94 | /* 95 | * A \in M(m, n) 96 | * B \in M(n, p) 97 | * C \in M(m, p) 98 | */ 99 | cilk void rec_matmul(REAL *A, REAL *B, REAL *C, int m, int n, int p, int ld, 100 | int add) 101 | { 102 | if ((m + n + p) <= 64) { 103 | int i, j, k; 104 | /* base case */ 105 | if (add) { 106 | for (i = 0; i < m; i++) 107 | for (k = 0; k < p; k++) { 108 | REAL c = 0.0; 109 | for (j = 0; j < n; j++) 110 | c += A[i * ld + j] * B[j * ld + k]; 111 | C[i * ld + k] += c; 112 | } 113 | } else { 114 | for (i = 0; i < m; i++) 115 | for (k = 0; k < p; k++) { 116 | REAL c = 0.0; 117 | for (j = 0; j < n; j++) 118 | c += A[i * ld + j] * B[j * ld + k]; 119 | C[i * ld + k] = c; 120 | } 121 | } 122 | } else if (m >= n && n >= p) { 123 | int m1 = m >> 1; 124 | spawn rec_matmul(A, B, C, m1, n, p, ld, add); 125 | spawn rec_matmul(A + m1 * ld, B, C + m1 * ld, m - m1, 126 | n, p, ld, add); 127 | } else if (n >= m && n >= p) { 128 | int n1 = n >> 1; 129 | spawn rec_matmul(A, B, C, m, n1, p, ld, add); 130 | sync; 131 | spawn rec_matmul(A + n1, B + n1 * ld, C, m, n - n1, p, ld, 1); 132 | } else { 133 | int p1 = p >> 1; 134 | spawn rec_matmul(A, B, C, m, n, p1, ld, add); 135 | spawn rec_matmul(A, B + p1, C + p1, m, n, p - p1, ld, add); 136 | } 137 | } 138 | 139 | cilk int main(int argc, char *argv[]) 140 | { 141 | int n; 142 | REAL *A, *B, *C1, *C2; 143 | double err; 144 | Cilk_time tm_begin, tm_elapsed; 145 | Cilk_time wk_begin, wk_elapsed; 146 | Cilk_time cp_begin, cp_elapsed; 147 | 148 | if (argc != 2) { 149 | fprintf(stderr, "Usage: matmul [] \n"); 150 | Cilk_exit(1); 151 | } 152 | n = atoi(argv[1]); 153 | 154 | A = malloc(n * n * sizeof(REAL)); 155 | B = malloc(n * n * sizeof(REAL)); 156 | C1 = malloc(n * n * sizeof(REAL)); 157 | C2 = malloc(n * n * sizeof(REAL)); 158 | 159 | init(A, n); 160 | init(B, n); 161 | zero(C1, n); 162 | zero(C2, n); 163 | 164 | iter_matmul(A, B, C1, n); 165 | 166 | /* Timing. "Start" timers */ 167 | sync; 168 | cp_begin = Cilk_user_critical_path; 169 | wk_begin = Cilk_user_work; 170 | tm_begin = Cilk_get_wall_time(); 171 | 172 | spawn rec_matmul(A, B, C2, n, n, n, n, 0); 173 | sync; 174 | 175 | /* Timing. "Stop" timers */ 176 | tm_elapsed = Cilk_get_wall_time() - tm_begin; 177 | wk_elapsed = Cilk_user_work - wk_begin; 178 | cp_elapsed = Cilk_user_critical_path - cp_begin; 179 | 180 | err = maxerror(C1, C2, n); 181 | 182 | printf("\nCilk Example: matmul\n"); 183 | printf(" running on %d processor%s\n\n", 184 | Cilk_active_size, Cilk_active_size > 1 ? "s" : ""); 185 | printf("Max error = %g\n", err); 186 | printf("Options: size = %d\n", n); 187 | printf("Running time = %4f s\n", Cilk_wall_time_to_sec(tm_elapsed)); 188 | printf("Work = %4f s\n", Cilk_time_to_sec(wk_elapsed)); 189 | printf("Critical path = %4f s\n", Cilk_time_to_sec(cp_elapsed)); 190 | printf("``MFLOPS'' = %4f\n\n", 191 | 2.0 * n * n * n / (1.0e6 * Cilk_wall_time_to_sec(tm_elapsed))); 192 | 193 | free(C2); 194 | free(C1); 195 | free(B); 196 | free(A); 197 | return 0; 198 | } 199 | -------------------------------------------------------------------------------- /examples/nfib-lib.cilk: -------------------------------------------------------------------------------- 1 | /* nfib computes fib times */ 2 | /* 3 | * This program is used to understand the behavior of the memory 4 | * allocator. In Cilk 5.[012], the memory allocator seems to use an 5 | * unbounded amount of space as grows. 6 | */ 7 | 8 | static const char *ident __attribute__((__unused__)) 9 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/nfib-lib.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 10 | 11 | /* 12 | * Copyright (c) 2003 Massachusetts Institute of Technology 13 | * 14 | * This program is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | * 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | cilk int fib(int n) 35 | { 36 | if (n < 2) 37 | return (n); 38 | else { 39 | int x, y; 40 | x = spawn fib(n - 1); 41 | y = spawn fib(n - 2); 42 | sync; 43 | return (x + y); 44 | } 45 | } 46 | 47 | extern EXPORT(fib)(CilkContext *const, int n); 48 | 49 | int main(int argc, char *argv[]) 50 | { 51 | int n, result = -1; 52 | int repeat, i; 53 | CilkContext *context; 54 | 55 | assert (argc>1); 56 | 57 | context = Cilk_init(&argc, argv); 58 | if( !context) 59 | return -1; 60 | 61 | n = atoi(argv[1]); 62 | 63 | if (argc > 2) 64 | repeat = atoi(argv[2]); 65 | else 66 | repeat = 1; 67 | 68 | for (i = 0; i < repeat; ++i) { 69 | result = EXPORT(fib)(context,n); 70 | printf("%d: n=%d Result: %d\n", i, n, result); 71 | } 72 | 73 | Cilk_terminate(context); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /examples/nfib.cilk: -------------------------------------------------------------------------------- 1 | const char ident[] = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/nfib.cilk $ $LastChangedBy: bradley $ $Rev: 517 $ $Date: 2004-06-23 08:32:01 -0400 (Wed, 23 Jun 2004) $"; 2 | 3 | /* 4 | * Copyright (c) 2003 Massachusetts Institute of Technology 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | /* nfib computes fib times */ 26 | /* 27 | * This program is used to understand the behavior of the memory 28 | * allocator. In Cilk 5.[012], the memory allocator seems to use an 29 | * unbounded amount of space as grows. 30 | */ 31 | cilk int fib(int n) 32 | { 33 | if (n < 2) 34 | return (n); 35 | else { 36 | int x, y; 37 | x = spawn fib(n - 1); 38 | y = spawn fib(n - 2); 39 | sync; 40 | return (x + y); 41 | } 42 | } 43 | 44 | cilk int main(int argc, char *argv[]) 45 | { 46 | int n, result = -1; 47 | int repeat, i; 48 | 49 | n = atoi(argv[1]); 50 | 51 | if (argc > 2) 52 | repeat = atoi(argv[2]); 53 | else 54 | repeat = 1; 55 | 56 | for (i = 0; i < repeat; ++i) { 57 | result = spawn fib(n); 58 | sync; 59 | } 60 | 61 | printf("Result: %d\n", result); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /examples/queens.cilk: -------------------------------------------------------------------------------- 1 | /* 2 | * A simple nqueens program to test abort 3 | * 4 | * Author: Keith Randall 5 | */ 6 | static const char *ident __attribute__((__unused__)) 7 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/queens.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 8 | /* 9 | * Copyright (c) 2000 Massachusetts Institute of Technology 10 | * Copyright (c) 2000 Matteo Frigo 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | /* 34 | * contains array of queen positions. Returns 1 35 | * if none of the queens conflict, and returns 0 otherwise. 36 | */ 37 | int ok(int n, char *a) 38 | { 39 | int i, j; 40 | char p, q; 41 | 42 | for (i = 0; i < n; i++) { 43 | p = a[i]; 44 | 45 | for (j = i + 1; j < n; j++) { 46 | q = a[j]; 47 | if (q == p || q == p - (j - i) || q == p + (j - i)) 48 | return 0; 49 | } 50 | } 51 | return 1; 52 | } 53 | 54 | /* 55 | * is an array of numbers. The entries of contain 56 | * queen positions already set. If there is any extension of 57 | * to a complete queen setting, returns one of these queen 58 | * settings (allocated from the heap). Otherwise, returns NULL. 59 | * Does not side-effect . 60 | */ 61 | 62 | cilk char *nqueens(int n, int j, char *a) 63 | { 64 | char *b; 65 | char *done = NULL; 66 | int i; 67 | 68 | inlet void catch(char *res) { 69 | if (res != NULL) { 70 | if (done == NULL) 71 | done = res; 72 | abort; 73 | } 74 | } if (n == j) { 75 | /* put good solution in heap, return pointer to it. */ 76 | b = malloc(n * sizeof(char)); 77 | memcpy(b, a, n * sizeof(char)); 78 | return b; 79 | } 80 | /* try each possible position for queen */ 81 | for (i = 0; i < n; i++) { 82 | /* allocate a temporary array and copy into it */ 83 | b = Cilk_alloca((j + 1) * sizeof(char)); 84 | memcpy(b, a, j * sizeof(char)); 85 | b[j] = i; 86 | if (ok(j + 1, b)) 87 | catch(spawn nqueens(n, j + 1, b)); 88 | 89 | if (done != NULL) 90 | break; 91 | } 92 | sync; 93 | 94 | return done; 95 | } 96 | 97 | cilk int cilk_main(int argc, char *argv[]) 98 | { 99 | int n; 100 | char *a; 101 | int i; 102 | 103 | if (argc < 2) { 104 | printf("%s: number of queens required\n", argv[0]); 105 | return 1; 106 | } 107 | if (argc > 2) 108 | printf("%s: extra arguments being ignored\n", argv[0]); 109 | 110 | n = atoi(argv[1]); 111 | a = Cilk_alloca(n * sizeof(char)); 112 | 113 | printf("running queens %d\n", n); 114 | a = spawn nqueens(n, 0, a); 115 | sync; 116 | if (a != NULL) { 117 | if (!ok(n, a)) 118 | printf("RESULT IS BAD!!!\n"); 119 | printf("result: "); 120 | for (i = 0; i < n; i++) 121 | printf("%2d ", a[i]); 122 | printf("\n"); 123 | } else 124 | printf("no possible result!\n"); 125 | 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /examples/rand.cilk: -------------------------------------------------------------------------------- 1 | static const char *ident __attribute__((__unused__)) 2 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/rand.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 3 | 4 | /* 5 | * Copyright (c) 2003 Massachusetts Institute of Technology 6 | * Copyright (c) 2003 Bradley C. Kuszmaul 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | * 22 | */ 23 | 24 | /***********************************************************\ 25 | * Random library functions for use by user 26 | \***********************************************************/ 27 | #include 28 | 29 | #ifndef RAND_MAX 30 | #define RAND_MAX 32767 31 | #endif 32 | 33 | static unsigned long rand_nxt = 0; 34 | static Cilk_lockvar rand_lock; 35 | 36 | int Cilk_rand(void) 37 | { 38 | int result; 39 | Cilk_lock(rand_lock); 40 | rand_nxt = rand_nxt * 1103515245 + 12345; 41 | result = (rand_nxt >> 16) % ((unsigned int) RAND_MAX + 1); 42 | Cilk_unlock(rand_lock); 43 | return result; 44 | } 45 | 46 | void Cilk_srand(unsigned int seed) 47 | { 48 | Cilk_lock(rand_lock); 49 | rand_nxt = seed; 50 | Cilk_unlock(rand_lock); 51 | } 52 | 53 | #if 0 54 | static void rand_init_hook(void) 55 | { 56 | Cilk_lock_init(rand_lock); 57 | } 58 | 59 | static void rand_init(void) __attribute__((constructor)); 60 | static void rand_init(void) 61 | { 62 | Cilk_add_hook(&Cilk_init_global_hooks, rand_init_hook); 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /examples/test-errno.cilk: -------------------------------------------------------------------------------- 1 | /* 2 | * This program checks that errno works correctly. 3 | * 4 | * On Solaris, multithreaded programs require -D_REENTRANT for errno 5 | * to work. If we forget -D_REENTRANT, this program will fail. 6 | * 7 | * Thanks to Kartik K. Agaram for the program. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | cilk int main(int argc, char *argv[]) 15 | { 16 | int fd; 17 | 18 | fd = open ("tHiS.fILe.DOES.not.exIST", O_RDONLY, 0644) ; 19 | 20 | if (fd == -1 && errno == ENOENT) { 21 | printf("OK\n"); 22 | return 0; 23 | } else { 24 | printf("BAD %d %d\n", fd, errno); 25 | return -1; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/test-locks.cilk: -------------------------------------------------------------------------------- 1 | static const char *ident __attribute__((__unused__)) 2 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/test-locks.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; 3 | 4 | /* 5 | * Copyright (c) 2003 Massachusetts Institute of Technology 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | * 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | #define N 10000000 28 | 29 | Cilk_lockvar lock; 30 | int n; 31 | 32 | cilk void increment(int count) 33 | { 34 | int i; 35 | if (count < 2) { 36 | for (i = 0; i < count; i++) { 37 | Cilk_lock(lock); 38 | n++; 39 | Cilk_unlock(lock); 40 | } 41 | } else { 42 | spawn increment(count / 2); 43 | spawn increment(count - (count / 2)); 44 | sync; 45 | } 46 | } 47 | 48 | cilk int main(void) 49 | { 50 | Cilk_lock_init(lock); 51 | n = 0; 52 | 53 | spawn increment(N); 54 | sync; 55 | 56 | if (n == N) { 57 | printf("OK\n"); 58 | return 0; 59 | } else { 60 | printf("BAD %d %d\n", n, N * 2); 61 | return -1; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /examples/test-void-func.cilk: -------------------------------------------------------------------------------- 1 | /* 2 | * This program checks that a function compiles correctly when it doesn't 3 | * have any incoming arguments or return value. 4 | */ 5 | 6 | #include 7 | int i = 0; 8 | 9 | cilk void func(void) { 10 | i++; 11 | } 12 | 13 | cilk void main(void) { 14 | spawn func(); 15 | spawn func(); 16 | spawn func(); 17 | sync; 18 | 19 | if( i==3 ) { 20 | printf("test_func_no_arg_no_ret OK\n"); 21 | } else { 22 | printf("test_func_no_arg_no_ret BAD\n"); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/velin.cilk: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int actives[2]; 4 | 5 | cilk int refine(void) { 6 | return 999; 7 | } 8 | 9 | cilk int main(void) { 10 | 11 | actives[2] = spawn refine(); 12 | if( actives[2] == 999 ) { 13 | printf("velin OK\n"); 14 | } 15 | else { 16 | printf("velin BAD\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /runtime/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libcilk.la libcilk.g.la libcilk.p.la libcilk.g.p.la 2 | pkglib_LIBRARIES = libcilkrt0.a libcilkrt0g.a libcilkrt0p.a libcilkrt0gp.a 3 | 4 | CILK_HFILES = cilk-cilk2c.h cilk.h cilk-lib.h cilk-lib.cilkh \ 5 | gcc-builtin.h cilk-cilk2c-pre.h 6 | 7 | CILK_CFILES = sysdep.c cilk.c sched.c hooks.c stats.c barrier.c \ 8 | cmdline.c internal-malloc.c timing.c invoke-main.c malloc.c debug.c \ 9 | workers.c mutex.c 10 | 11 | pkginclude_HEADERS = $(CILK_HFILES) cilk-conf.h cilk-sysdep.h 12 | 13 | CILK_SRC = cilk-internal.h $(CILK_CFILES) $(CILK_HFILES) 14 | COMMON_LINK_FLAGS = -version-info 1:3:0 @PTHREAD_LIBS@ 15 | 16 | AM_CFLAGS = $(PTHREAD_CFLAGS) 17 | CC = $(PTHREAD_CC) 18 | 19 | CILK_DEBUG = -DCILK_DEBUG=1 20 | CILK_PROFILE = -DCILK_TIMING=1 -DCILK_STATS=1 -DCILK_CRITICAL_PATH=1 21 | 22 | # startup library 23 | libcilkrt0_a_SOURCES = cilkrt0.c 24 | 25 | libcilkrt0g_a_SOURCES = cilkrt0.c 26 | libcilkrt0g_a_CPPFLAGS = $(CILK_DEBUG) 27 | 28 | libcilkrt0p_a_SOURCES = cilkrt0.c 29 | libcilkrt0p_a_CPPFLAGS = $(CILK_PROFILE) 30 | 31 | libcilkrt0gp_a_SOURCES = cilkrt0.c 32 | libcilkrt0gp_a_CPPFLAGS = $(CILK_PROFILE) $(CILK_DEBUG) 33 | 34 | # runtime system library 35 | libcilk_la_SOURCES = $(CILK_SRC) 36 | 37 | libcilk_g_la_SOURCES = $(CILK_SRC) 38 | libcilk_g_la_CPPFLAGS = $(CILK_DEBUG) 39 | 40 | libcilk_p_la_SOURCES = $(CILK_SRC) 41 | libcilk_p_la_CPPFLAGS = $(CILK_PROFILE) 42 | 43 | libcilk_g_p_la_SOURCES = $(CILK_SRC) 44 | libcilk_g_p_la_CPPFLAGS = $(CILK_PROFILE) $(CILK_DEBUG) 45 | 46 | EXTRA_DIST = PROTOCOLS 47 | -------------------------------------------------------------------------------- /runtime/PROTOCOLS: -------------------------------------------------------------------------------- 1 | % $HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/PROTOCOLS $ $LastChangedBy: bradley $ $Rev: 111 $ $Date: 2002-12-27 02:57:40 -0500 (Fri, 27 Dec 2002) $ 2 | 3 | % This file describes the protocols used by the runtime system, 4 | % and how the various locks interact. I find writing this 5 | % document convenient for myself, and it may help other people. 6 | 7 | 1) MEANING OF THE CLOSURE STATE 8 | 9 | A closure is in one of four states 10 | 11 | - CLOSURE_RUNNING: there is currently a processor working 12 | on the closure *OR* on one of the child frames. The closure 13 | is at the bottom of that processor's ready deque. 14 | 15 | - CLOSURE_SUSPENDED: the closure is in no queue and nobody is 16 | working on it. Can be provably-good stolen. 17 | 18 | - CLOSURE_READY: suspended closure whose join counter is zero. 19 | My idea is that the scheduler should be able to work 20 | with more than one closure in the ready queue. This 21 | is not used yet, but may simplify alternative scheduler 22 | policies (steal in the middle, etc) as well as abort. 23 | 24 | - CLOSURE_RETURNING: this is an intermediate state that causes 25 | only headache in protocols. Essentially, a RETURNING closure 26 | is dead for all purposes. It is only kept around because it 27 | carries a return value to be sent to the parent. In particular, 28 | one cannot to try to change the RETURNING state into something 29 | else. 30 | 31 | 2) LOCKS AND PRECEDENCES. 32 | 33 | The main locks in the system are ReadyDeque locks, and Closure locks. 34 | Rules for acquiring locks: 35 | 36 | A) a ReadyDeque lock must be acquired before any Closure lock. 37 | 38 | B) a processor can grab only one ReadyDeque lock at the time. 39 | 40 | C) Closure locks must be acquired downwards in the closure tree. 41 | 42 | In general, locks can be released in an arbitrary order, with the 43 | following IMPORTANT EXCEPTION: 44 | 45 | D) When obtaining a pointer to a closure K from a ReadyDeque or from 46 | the parent, you cannot release the source of the pointer until 47 | you have locked K and ensured that K is not returning (in that order). 48 | 49 | The reason for rule D) is that the return protocol does not lock a 50 | closure that is returning. However, the protocol is careful in 51 | removing all pointers to a closure before removing it, by locking the 52 | places that hold the pointer. RETURNING closures should be treated as 53 | non-existing; they are not really part of a ready queue or of the 54 | closure tree. The closure may disappear from the time you get the 55 | pointer to the time you look at the closure. Consequently, you must 56 | check whether a closure is returning in an atomic fashion. 57 | 58 | Rule D is automatic if you acquire locks in a stack-like fashion: 59 | 60 | lock A 61 | lock B 62 | .... 63 | unlock B 64 | unlock A 65 | 66 | Unfortunately, Keith insists that things should be different in the 67 | steal protocol, where he wants to 68 | 69 | lock queue 70 | lock closure 71 | if (stealable closure) 72 | do something 73 | unlock queue as soon as possible 74 | do something else 75 | unlock closure 76 | else 77 | unlock closure 78 | unlock queue 79 | 80 | (the reason is that he wants to release the victim as soon as 81 | possible, for performance reasons). 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /runtime/TODO: -------------------------------------------------------------------------------- 1 | Done 2 | barrier.c 3 | cmdline.c 4 | cilk-conf.h 5 | move-if-change 6 | gcc-builtin.h 7 | Doing 8 | Todo 9 | cilk.c 10 | cilk-cilk2c.h 11 | cilk-cilk2c-pre.h 12 | cilk-internal.h 13 | cilk-lib.h 14 | cilk-sysdep.h.in 15 | debug.c 16 | hooks.c 17 | internal-malloc.c 18 | invoke-main.c 19 | Makefile.am 20 | Makefile.in 21 | malloc.c 22 | mutex.c 23 | PROTOCOLS 24 | sched.c 25 | stamp-h2.in 26 | stats.c 27 | sysdep.c 28 | timing.c 29 | workers.c 30 | 31 | cilk.h 32 | Cilk_internal_malloc from nondeterminator is not called anymore. 33 | cilk_fake_lock and stuff need to be defined 34 | -------------------------------------------------------------------------------- /runtime/barrier.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Massachusetts Institute of Technology 3 | * Copyright (c) 2000 Matteo Frigo 4 | * Copyright (c) 2002 Massachusetts Institute of Technology 5 | * Copyright (c) 2002 Bradley C. Kuszmaul 6 | * 7 | * This library is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or (at 10 | * your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 20 | * USA. 21 | * 22 | */ 23 | 24 | /* 25 | * This file contains the code for barriers 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | FILE_IDENTITY(ident, 32 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/barrier.c $ $LastChangedBy: bradley $ $Rev: 1698 $ $Date: 2004-10-22 22:10:46 -0400 (Fri, 22 Oct 2004) $"); 33 | 34 | 35 | /***********************************************************\ 36 | * Code for barriers 37 | \***********************************************************/ 38 | /* sense-reversing barrier, see Hennessy & Patterson page 702 */ 39 | /* this barrier can be safely reused */ 40 | 41 | /* 42 | * Volker pointed out that the original code in H&P has a bug, 43 | * and provided a fix, which is used here 44 | */ 45 | void Cilk_barrier(CilkWorkerState *const ws) 46 | { 47 | int local_counter; 48 | 49 | ws->barrier_direction = !ws->barrier_direction; 50 | 51 | Cilk_mutex_wait(ws->context, ws, &USE_SHARED(barrier_lock)); 52 | local_counter = ++USE_SHARED(barrier_counter); 53 | Cilk_mutex_signal(ws->context, &USE_SHARED(barrier_lock)); 54 | 55 | if (local_counter == USE_PARAMETER(active_size)) { 56 | USE_SHARED(barrier_counter) = 0; 57 | USE_SHARED(barrier_release) = ws->barrier_direction; 58 | } else 59 | while (USE_SHARED(barrier_release) != ws->barrier_direction) 60 | if (USE_PARAMETER(options->yieldslice)) 61 | Cilk_yield(ws); 62 | } 63 | 64 | void Cilk_barrier_init(CilkContext *const context) 65 | { 66 | /* initialize the barrier code */ 67 | Cilk_mutex_init(context, &USE_SHARED1(barrier_lock)); 68 | USE_SHARED1(barrier_counter) = 0; 69 | USE_SHARED1(barrier_release) = 0; 70 | } 71 | 72 | void Cilk_barrier_per_worker_init(CilkWorkerState *const ws) 73 | { 74 | ws->barrier_direction = 0; 75 | } 76 | 77 | void Cilk_barrier_terminate(CilkContext *const context) 78 | { 79 | /* Destroy the mutex*/ 80 | Cilk_mutex_destroy(context, &USE_SHARED1(barrier_lock)); 81 | } 82 | -------------------------------------------------------------------------------- /runtime/cilk-cilk2c.h: -------------------------------------------------------------------------------- 1 | /* getting FILE_IDENTITY to work here is a pain. The trick is to avoid including config.h at the wrong time. */ 2 | /* "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/cilk-cilk2c.h $ $LastChangedBy: bradley $ $Rev: 1389 $ $Date: 2004-06-22 10:46:28 -0400 (Tue, 22 Jun 2004) $"); */ 3 | 4 | /* 5 | * Copyright (c) 2000 Massachusetts Institute of Technology 6 | * Copyright (c) 2000 Matteo Frigo 7 | * 8 | * This library is free software; you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 21 | * USA. 22 | * 23 | */ 24 | 25 | #define Self _cilk_ws->self 26 | #define Cilk_user_work _cilk_ws->user_work 27 | #define Cilk_user_critical_path _cilk_ws->user_critical_path 28 | #define Cilk_alloca(size) Cilk_alloca_internal(_cilk_ws, size) 29 | 30 | #define CILK_OFFSETOF(type, mem) \ 31 | ((size_t) ((char *)&((type *) 0)->mem - (char *)((type *) 0))) 32 | 33 | /* add current frame to deque */ 34 | #define CILK2C_PUSH_FRAME(f) { \ 35 | Cilk_cilk2c_push_frame(_cilk_ws, &(f->header)); \ 36 | } 37 | 38 | #define CILK2C_INIT_FRAME(f,s,signat) { \ 39 | f = Cilk_cilk2c_init_frame(_cilk_ws, s, signat); \ 40 | } 41 | 42 | #define CILK2C_SYNC Cilk_sync(_cilk_ws) 43 | 44 | #define CILK2C_SYNCHED 0 45 | 46 | #define CILK2C_ABORT_STANDALONE() Cilk_abort_standalone(_cilk_ws) 47 | 48 | #define CILK2C_ABORT_SLOW() Cilk_abort_slow(_cilk_ws) 49 | 50 | #if 0 51 | /* This is now done directly by the compiler, to avoid the "typeof" non-ansi construction (Bug 125) */ 52 | #define CILK2C_SET_RESULT(x) { \ 53 | typeof(x) __tmp = x; \ 54 | Cilk_set_result(_cilk_ws, &__tmp, sizeof(__tmp)); \ 55 | } 56 | #endif 57 | 58 | #define CILK2C_SET_NORESULT() { \ 59 | Cilk_set_result(_cilk_ws, (void *)0, 0); \ 60 | } 61 | 62 | /* __tmp must be declared in the surrounding code. We used to do '{ typeof(result) __tmp = result; }", now we simply assume that __tmp is declared in the surrounding code. */ 63 | #define CILK2C_XPOP_FRAME_RESULT(f, r, result) \ 64 | { \ 65 | if (Cilk_cilk2c_pop_check(_cilk_ws)) { \ 66 | __tmp = result; \ 67 | if (Cilk_exception_handler(_cilk_ws, &__tmp, sizeof(__tmp))) { \ 68 | Cilk_cilk2c_pop(_cilk_ws); \ 69 | return r; \ 70 | } \ 71 | } \ 72 | } 73 | 74 | #define CILK2C_XPOP_FRAME_NORESULT(f, r) \ 75 | { \ 76 | if (Cilk_cilk2c_pop_check(_cilk_ws)) { \ 77 | if (Cilk_exception_handler(_cilk_ws, (void *)0, 0)) { \ 78 | Cilk_cilk2c_pop(_cilk_ws); \ 79 | return r; \ 80 | } \ 81 | } \ 82 | } 83 | 84 | #define CILK2C_BEFORE_SPAWN_FAST() \ 85 | Cilk_cilk2c_before_spawn_fast_cp(_cilk_ws, &(_cilk_frame->header)) 86 | 87 | #define CILK2C_BEFORE_SPAWN_SLOW() \ 88 | Cilk_cilk2c_before_spawn_slow_cp(_cilk_ws, &(_cilk_frame->header)) 89 | 90 | #define CILK2C_AT_THREAD_BOUNDARY_SLOW() { \ 91 | Cilk_cilk2c_at_thread_boundary_slow_cp( \ 92 | _cilk_ws, &(_cilk_frame->header)); \ 93 | Cilk_cilk2c_event_new_thread_maybe(_cilk_ws); \ 94 | } 95 | 96 | #define CILK2C_AFTER_SPAWN_FAST() { \ 97 | Cilk_cilk2c_after_spawn_fast_cp(_cilk_ws, &(_cilk_frame->header)); \ 98 | Cilk_cilk2c_event_new_thread_maybe(_cilk_ws); \ 99 | } 100 | 101 | #define CILK2C_AFTER_SPAWN_SLOW() \ 102 | Cilk_cilk2c_after_spawn_slow_cp(_cilk_ws, &(_cilk_frame->header)) 103 | 104 | #define CILK2C_START_THREAD_FAST() { \ 105 | Cilk_cilk2c_start_thread_fast_cp(_cilk_ws, &(_cilk_frame->header)); \ 106 | Cilk_cilk2c_event_new_thread_maybe(_cilk_ws); \ 107 | } 108 | 109 | #define CILK2C_START_THREAD_SLOW() { \ 110 | Cilk_cilk2c_start_thread_slow_cp(_cilk_ws, &(_cilk_frame->header)); \ 111 | Cilk_cilk2c_start_thread_slow(_cilk_ws, &(_cilk_frame->header)); \ 112 | } 113 | 114 | #define CILK2C_BEFORE_RETURN_FAST() { \ 115 | Cilk_cilk2c_before_return_fast_cp(_cilk_ws, &(_cilk_frame->header)); \ 116 | Cilk_cilk2c_before_return_fast( \ 117 | _cilk_ws, &(_cilk_frame->header), sizeof(*_cilk_frame)); \ 118 | } 119 | 120 | #define CILK2C_BEFORE_RETURN_SLOW() { \ 121 | Cilk_cilk2c_before_return_slow_cp(_cilk_ws, &(_cilk_frame->header)); \ 122 | Cilk_cilk2c_before_return_slow( \ 123 | _cilk_ws, &(_cilk_frame->header), sizeof(*_cilk_frame)); \ 124 | } 125 | 126 | #define CILK2C_BEFORE_RETURN_INLET() 127 | 128 | #define CILK2C_BEFORE_SYNC_SLOW() \ 129 | Cilk_cilk2c_before_sync_slow_cp(_cilk_ws, &(_cilk_frame->header)) 130 | 131 | #define CILK2C_AFTER_SYNC_SLOW() \ 132 | Cilk_cilk2c_after_sync_slow_cp(_cilk_ws, &(_cilk_frame->header)) 133 | 134 | #define CILK2C_AT_SYNC_FAST() { \ 135 | Cilk_cilk2c_at_sync_fast_cp(_cilk_ws, &(_cilk_frame->header)); \ 136 | Cilk_cilk2c_event_new_thread_maybe(_cilk_ws); \ 137 | } 138 | -------------------------------------------------------------------------------- /runtime/cilk-conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Massachusetts Institute of Technology 3 | * Copyright (c) 2000 Matteo Frigo 4 | * Copyright (c) 2002 Massachusetts Institute of Technology 5 | * Copyright (c) 2002 Bradley C. Kuszmaul 6 | * 7 | * This library is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or (at 10 | * your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 20 | * USA. 21 | * 22 | */ 23 | 24 | #ifndef _CILK_CONF_H 25 | #define _CILK_CONF_H 26 | 27 | FILE_IDENTITY(ident_cilk_conf_h, 28 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/cilk-conf.h $ $LastChangedBy: bradley $ $Rev: 1465 $ $Date: 2004-08-02 06:31:06 -0400 (Mon, 02 Aug 2004) $"); 29 | 30 | 31 | /* use the __cilksafe__ attribute if running through Cilk */ 32 | #ifdef __CILK__ 33 | #define __CILKSAFE__ __cilksafe__ 34 | #else 35 | #define __CILKSAFE__ 36 | #endif 37 | 38 | /* Cannot put this into the file because cilk-conf.h is included by cilk2c twice, once expanded, and once not expanded. 39 | * leave this here, commented out, so that at least the version number will be in the comments. 40 | * static const char *cilk_conf_h_ident __attribute__((__unused__)) 41 | = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/cilk-conf.h $ $LastChangedBy: bradley $ $Rev: 1465 $ $Date: 2004-08-02 06:31:06 -0400 (Mon, 02 Aug 2004) $"; 42 | */ 43 | /* 44 | * Keep track of various statistics 45 | */ 46 | #ifndef CILK_STATS 47 | #define CILK_STATS 0 48 | #endif 49 | 50 | /* 51 | * Keep track of execution time 52 | */ 53 | #ifndef CILK_TIMING 54 | #define CILK_TIMING 0 55 | #endif 56 | 57 | /* 58 | * Measure critical path. EXPENSIVE in terms of execution time 59 | */ 60 | #ifndef CILK_CRITICAL_PATH 61 | #define CILK_CRITICAL_PATH 0 62 | #endif 63 | 64 | /* 65 | * Provide the current work and critical path in 66 | * Cilk_user_work and Cilk_user_critical_path 67 | */ 68 | #define CILK_USER_TIMERS CILK_CRITICAL_PATH 69 | 70 | /* 71 | * Enable rts self-consistency checks. 72 | */ 73 | #ifndef CILK_DEBUG 74 | #define CILK_DEBUG 0 75 | #endif 76 | 77 | /* 78 | * enable support for alloca (slows down common case frame 79 | * allocation by 20%) 80 | */ 81 | #ifndef CILK_ALLOCA 82 | #define CILK_ALLOCA 1 83 | #endif 84 | 85 | /* 86 | * Default size of Cilk's stack 87 | */ 88 | #define CILK_DEFAULT_STACK_DEPTH 32768 89 | 90 | /* 91 | * there should be no need to hack below this line 92 | */ 93 | #if CILK_CRITICAL_PATH && (!CILK_TIMING) 94 | #warning Critical path measurements cannot be enabled because timing is not supported by the rts 95 | #undef CILK_CRITICAL_PATH 96 | #define CILK_CRITICAL_PATH 0 97 | #endif 98 | 99 | #define CILK_CHECK(cond, complaints) \ 100 | if (!(cond)) Cilk_die_internal complaints; 101 | 102 | #if CILK_DEBUG 103 | #define CILK_ASSERT(ws, ex) \ 104 | (void)((ex) || \ 105 | (Cilk_die_internal(ws->context, ws, USE_PARAMETER(assertion_failed_msg), \ 106 | #ex, __LINE__, __FILE__), 0)) 107 | #define WHEN_CILK_DEBUG(ex) ex 108 | #define CILK_COMPLAIN(cond, complaints) \ 109 | if (!(cond)) Cilk_die_internal complaints; 110 | #else 111 | #define CILK_ASSERT(ws, ex) 112 | #define WHEN_CILK_DEBUG(ex) 113 | #define CILK_COMPLAIN(cond, complaints) 114 | #endif 115 | 116 | #if CILK_ALLOCA 117 | #define WHEN_CILK_ALLOCA(a) a 118 | #else 119 | #define WHEN_CILK_ALLOCA(a) 120 | #endif 121 | 122 | #if CILK_STATS 123 | #define WHEN_CILK_STATS(a) a 124 | #else 125 | #define WHEN_CILK_STATS(a) 126 | #endif 127 | 128 | #if CILK_TIMING 129 | #define WHEN_CILK_TIMING(a) a 130 | #else 131 | #define WHEN_CILK_TIMING(a) 132 | #endif 133 | 134 | #if CILK_CRITICAL_PATH 135 | #define WHEN_CILK_CRITICAL_PATH(a) a 136 | #else 137 | #define WHEN_CILK_CRITICAL_PATH(a) 138 | #endif 139 | 140 | #if CILK_USER_TIMERS 141 | #define WHEN_CILK_USER_TIMERS(a) a 142 | #else 143 | #define WHEN_CILK_USER_TIMERS(a) 144 | #endif 145 | 146 | #define CILK_IM_FREE_MAGIC 0x132DEBFA 147 | #define CILK_CLOSURE_MAGIC 0xDEADBEEF 148 | #define CILK_STACKFRAME_MAGIC 0xBEEF1234 149 | 150 | #define CILK_MALLOC_NLISTS 32 151 | 152 | /* threshold above which we use slow malloc */ 153 | #define CILK_INTERNAL_MALLOC_THRESHOLD 4096 154 | #define CILK_INTERNAL_MALLOC_BUCKETS 9 155 | 156 | /* tell cilk2c not to emit code for linker segments */ 157 | #ifdef __CILK2C__ 158 | #pragma segments - 159 | #endif 160 | 161 | /* 162 | * ``parameters'' are set by the global process and they are only read 163 | * by workers. It would be nice to map these in a segment which is 164 | * actually read only. 165 | */ 166 | #define USE_PARAMETER(id) ws->context->Cilk_RO_params->id 167 | #define USE_PARAMETER1(id) context->Cilk_RO_params->id 168 | /* Ofra and Sivan, added USE_PARAMETER2, 19 June 2003 */ 169 | #define USE_PARAMETER2(id) _cilk_ws->context->Cilk_RO_params->id 170 | #define INIT_PARAMETER(id, value) USE_PARAMETER(id) = value 171 | #define INIT_PARAMETER1(id, value) USE_PARAMETER1(id) = value 172 | 173 | #define EXPORT(cilk_func) mt_##cilk_func 174 | 175 | /* 176 | * macros used to compile codes related to the Nondeterminator 177 | */ 178 | #ifdef CILK_ND 179 | #define WHEN_CILK_ND(a) a 180 | #else 181 | #define WHEN_CILK_ND(a) 182 | #endif 183 | #endif /* _CILK_CONF_H */ 184 | -------------------------------------------------------------------------------- /runtime/cilk-lib.cilkh: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C -*- */ 2 | /* 3 | * Copyright (c) 2000 Massachusetts Institute of Technology 4 | * Copyright (c) 2000 Matteo Frigo 5 | * 6 | * This library is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 19 | * USA. 20 | * 21 | */ 22 | 23 | #ifndef _CILK_LIB_H 24 | #define _CILK_LIB_H 25 | 26 | #include 27 | 28 | FILE_IDENTITY (ident_cilk_lib_h, 29 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/cilk-lib.cilkh $ $LastChangedBy: bradley $ $Rev: 1699 $ $Date: 2004-10-22 22:22:25 -0400 (Fri, 22 Oct 2004) $"); 30 | 31 | /***********************************************************\ 32 | * Memory allocator functions 33 | \***********************************************************/ 34 | 35 | extern void *Cilk_alloca_internal(CilkWorkerState *const ws, size_t size); 36 | extern __nooutput__ void *Cilk_alloca(size_t size); 37 | 38 | /***********************************************************\ 39 | * Cilk_exit 40 | \***********************************************************/ 41 | 42 | extern cilk void Cilk_really_exit(int retval); 43 | 44 | /* Cilk_exit */ 45 | #define Cilk_exit(ret) \ 46 | do { \ 47 | spawn Cilk_really_exit(ret); \ 48 | } while (0) 49 | 50 | /* Ofra and Sivan: Changed the definition, 19 June 2003 */ 51 | #define Cilk_die(fmt) Cilk_die_external(_cilk_ws->context,fmt); 52 | extern void Cilk_die_external(CilkContext *const context, const char *fmt,...); 53 | /* extern void Cilk_die(const char *fmt,...); */ 54 | 55 | /***********************************************************\ 56 | * locks 57 | \***********************************************************/ 58 | typedef volatile int Cilk_lockvar[1]; 59 | 60 | static inline void Cilk_lock_init(Cilk_lockvar v) 61 | { 62 | v[0] = 0; 63 | } 64 | 65 | static inline void Cilk_lock(Cilk_lockvar v) 66 | { 67 | while (Cilk_xchg((int *)v, 1) != 0) { 68 | while (v[0]); /* spin using only reads - reduces bus traffic */ 69 | } 70 | } 71 | 72 | static inline void Cilk_unlock(Cilk_lockvar v) 73 | { 74 | Cilk_membar_StoreStore(); 75 | v[0] = 0; 76 | } 77 | 78 | /***********************************************************\ 79 | * Debugging support 80 | \***********************************************************/ 81 | 82 | #ifdef NDEBUG 83 | #define Cilk_assert(ex) ((void)0) 84 | #else 85 | /* Ofra and Sivan 19 June 2003 */ 86 | /* (void)((ex) || (Cilk_die(NULL, USE_PARAMETER(assertion_failed_msg), \ */ 87 | #define Cilk_assert(ex) \ 88 | (void)((ex) || (Cilk_die_external(_cilk_ws->context, USE_PARAMETER2(assertion_failed_msg), \ 89 | #ex, __LINE__, __FILE__), 0)) 90 | #endif 91 | 92 | /***********************************************************\ 93 | * Real and pseudo variables 94 | \***********************************************************/ 95 | #define Cilk_active_size USE_PARAMETER2(active_size) 96 | 97 | #ifdef __CILK__ 98 | /* support for referencing part of the worker state */ 99 | extern __cilksafe__ __nooutput__ __cilkonly__ int Self; 100 | extern __cilksafe__ __nooutput__ __cilkonly__ Cilk_time Cilk_user_work; 101 | extern __cilksafe__ __nooutput__ __cilkonly__ Cilk_time Cilk_user_critical_path; 102 | /* Sivan and Ofra 19 June 2003 */ 103 | extern __cilksafe__ __nooutput__ __cilkonly__ CilkWorkerState *const _cilk_ws; 104 | #endif 105 | 106 | #endif /* _CILK_LIB_H */ 107 | -------------------------------------------------------------------------------- /runtime/cilk-lib.h: -------------------------------------------------------------------------------- 1 | #warning Including cilk-lib.h is deprecated. Include cilk-lib.cilkh instead. 2 | /* go into Cilk mode */ 3 | #pragma lang -c 4 | #include "cilk-lib.cilkh" 5 | #pragma lang +c 6 | -------------------------------------------------------------------------------- /runtime/cilkrt0.c: -------------------------------------------------------------------------------- 1 | /* 2 | * startup file to invoke Cilk. 3 | */ 4 | 5 | /* 6 | * This file is linked with Cilk programs, and it is not part 7 | * of libcilk.a. In this way, libcilk does not depend on the 8 | * user program and it can be compiled as a shared library. 9 | */ 10 | 11 | /* 12 | * Copyright (c) 2000 Massachusetts Institute of Technology 13 | * Copyright (c) 2000 Matteo Frigo 14 | * 15 | * This library is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU Lesser General Public License as published by 17 | * the Free Software Foundation; either version 2.1 of the License, or (at 18 | * your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the Free Software 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 28 | * USA. 29 | * 30 | */ 31 | 32 | #include 33 | 34 | FILE_IDENTITY(ident, 35 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/cilkrt0.c $ $LastChangedBy: bradley $ $Rev: 1875 $ $Date: 2005-02-15 09:57:07 -0500 (Tue, 15 Feb 2005) $"); 36 | 37 | #include 38 | 39 | #if HAVE_MALLOC_H 40 | #include 41 | #endif 42 | 43 | /* Sivan and Ofra 19 June 2003: 44 | the code in the #else block tries to generate a main that calls the user's 45 | cilk_main when there is no main() but there is a cilk_main(), and should not 46 | be used by the linker when the user supplies a main() earlier in the link command. 47 | 48 | For some reason, this does not work. The linker uses this main() even when the 49 | user supplies another. 50 | */ 51 | 52 | #define OFRA_MAIN_ATTEMPT 53 | 54 | #ifndef OFRA_MAIN_ATTEMPT 55 | int main(int argc, char *argv[]) 56 | { 57 | extern int Cilk_start(int (*main)(void *const ws, int argc, char *argv[]), 58 | int argc, char *argv[]); 59 | extern int cilk_main(void *const ws, int argc, char *argv[]); 60 | 61 | return Cilk_start(cilk_main, argc, argv); 62 | } 63 | #else 64 | #include 65 | #undef main 66 | extern int EXPORT(cilk_main)(CilkContext *const context, int argc, char *argv[]); 67 | 68 | /* This is the main that the OS calls, in cilkrt0 */ 69 | int main(int argc, char *argv[]) 70 | { 71 | 72 | CilkContext * context; 73 | 74 | context = Cilk_init(&argc, argv); 75 | 76 | /* null context also when using -help flag */ 77 | if(context == NULL) 78 | return 0; 79 | 80 | EXPORT(cilk_main)(context, argc, argv); 81 | 82 | Cilk_terminate(context); 83 | 84 | return 0; 85 | } 86 | #endif 87 | -------------------------------------------------------------------------------- /runtime/debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Massachusetts Institute of Technology 3 | * Copyright (c) 2000 Matteo Frigo 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 2.1 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | FILE_IDENTITY(ident, 29 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/debug.c $ $LastChangedBy: bradley $ $Rev: 1698 $ $Date: 2004-10-22 22:10:46 -0400 (Fri, 22 Oct 2004) $"); 30 | 31 | 32 | /***********************************************************\ 33 | * Debugging & tracing 34 | \***********************************************************/ 35 | 36 | void Cilk_dprintf(CilkWorkerState *const ws, const char *fmt,...) 37 | { 38 | va_list l; 39 | 40 | /* ensure nice interleaving of debugging messages */ 41 | Cilk_mutex_wait(ws->context, ws, &USE_SHARED(dprintf_lock)); 42 | 43 | if (ws != 0) 44 | fprintf(stderr, "%d: ", ws->self); 45 | else 46 | fprintf(stderr, "global: "); 47 | 48 | va_start(l, fmt); 49 | vfprintf(stderr, fmt, l); 50 | fflush(stderr); 51 | va_end(l); 52 | Cilk_mutex_signal(ws->context, &USE_SHARED(dprintf_lock)); 53 | } 54 | 55 | void Cilk_die_internal(CilkContext *const context, CilkWorkerState *const ws, const char *fmt,...) 56 | { 57 | va_list l; 58 | 59 | /* Use USE_SHARED1 not USE_SHARED because ws may be NULL */ 60 | Cilk_mutex_wait(context, ws, &USE_SHARED1(dprintf_lock)); 61 | 62 | if (ws) 63 | fprintf(stderr, "%d: fatal error: ", ws->self); 64 | else 65 | fprintf(stderr, "global: fatal error: "); 66 | 67 | va_start(l, fmt); 68 | vfprintf(stderr, fmt, l); 69 | va_end(l); 70 | Cilk_mutex_signal(context, &USE_SHARED1(dprintf_lock)); 71 | 72 | /* ensure only the first fatal error produces death of the program */ 73 | if (USE_PARAMETER(options->dump_core) && Cilk_mutex_try(context, &USE_SHARED1(die_lock))) 74 | abort(); /* dump core */ 75 | else 76 | exit(1); /* don't dump core */ 77 | } 78 | 79 | void Cilk_die_external(CilkContext *const context, const char *fmt,...) 80 | { 81 | va_list l; 82 | 83 | Cilk_mutex_wait(context, NULL, &USE_SHARED1(dprintf_lock)); 84 | 85 | fprintf(stderr, "fatal error: "); 86 | 87 | va_start(l, fmt); 88 | vfprintf(stderr, fmt, l); 89 | va_end(l); 90 | Cilk_mutex_signal(context, &USE_SHARED1(dprintf_lock)); 91 | 92 | /* ensure only the first fatal error produces death of the program */ 93 | if (USE_PARAMETER1(options->dump_core) && Cilk_mutex_try(context, &USE_SHARED1(die_lock))) 94 | abort(); /* dump core */ 95 | else 96 | exit(1); /* don't dump core */ 97 | } 98 | 99 | void Cilk_debug_init(CilkContext *const context) 100 | { 101 | Cilk_mutex_init(context, &USE_SHARED1(dprintf_lock)); 102 | Cilk_mutex_init(context, &USE_SHARED1(die_lock)); 103 | } 104 | 105 | void Cilk_debug_terminate(CilkContext *const context) 106 | { 107 | Cilk_mutex_destroy(context, &USE_SHARED1(dprintf_lock)); 108 | Cilk_mutex_destroy(context, &USE_SHARED1(die_lock)); 109 | } 110 | -------------------------------------------------------------------------------- /runtime/gcc-builtin.h: -------------------------------------------------------------------------------- 1 | /* Don't include file_identity here. It is too gruesome 2 | #include 3 | FILE_IDENTITY(ident_gcc_builtin_h, 4 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/gcc-builtin.h $ $LastChangedBy: bradley $ $Rev: 1631 $ $Date: 2004-09-21 16:43:48 -0400 (Tue, 21 Sep 2004) $"); 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2000 Massachusetts Institute of Technology 9 | * Copyright (c) 2000 Matteo Frigo 10 | * 11 | * This library is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU Lesser General Public License as published by 13 | * the Free Software Foundation; either version 2.1 of the License, or (at 14 | * your option) any later version. 15 | * 16 | * This library is distributed in the hope that it will be useful, but 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | * Lesser General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public 22 | * License along with this library; if not, write to the Free Software 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 24 | * USA. 25 | * 26 | */ 27 | 28 | /* 29 | * this file contains definitions of variables that are built 30 | * into gcc but not into cilk2c. 31 | */ 32 | 33 | #ifdef __GNUC__ 34 | 35 | __nooutput__ typedef void *__builtin_va_list; 36 | 37 | extern __nooutput__ void __builtin_stdarg_start (void *, void *); 38 | extern __nooutput__ void __builtin_va_end (void *); 39 | 40 | extern __nooutput__ const char *__FUNCTION__; 41 | extern __nooutput__ const char *__PRETTY_FUNCTION__; 42 | extern __nooutput__ const char *__func__; 43 | 44 | extern __nooutput__ int __builtin_constant_p(); 45 | extern __nooutput__ void *__builtin_alloca(); 46 | extern __nooutput__ int __builtin_abs(int); 47 | extern __nooutput__ float __builtin_fabsf(float); 48 | extern __nooutput__ long double __builtin_fabsl(long double); 49 | extern __nooutput__ double __builtin_fabs(double); 50 | extern __nooutput__ long __builtin_labs(long); 51 | extern __nooutput__ void *__builtin_saveregs(); 52 | extern __nooutput__ void *__builtin_memcpy(); 53 | extern __nooutput__ void *__builtin_memset(); 54 | extern __nooutput__ int __builtin_classify_type(); 55 | extern __nooutput__ void *__builtin_next_arg(); 56 | extern __nooutput__ int __builtin_args_info(); 57 | extern __nooutput__ void *__builtin_return_address(unsigned int); 58 | extern __nooutput__ long __builtin_expect(long,long); 59 | 60 | #else 61 | 62 | #ifdef sgi 63 | extern __nooutput__ void __synchronize(); 64 | extern __nooutput__ int __lock_test_and_set(); /* The correct signature for __lock_test_and_set depends on the context, but we only use it to return an int. This could cause a problem if a user were to call lock_test_and_set directly. */ 65 | extern __nooutput__ void *__builtin_alloca(); 66 | 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /runtime/hooks.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: debug.c,v 1.1.1.1 2000/06/22 08:04:48 matley Exp $ 3 | */ 4 | /* 5 | * Copyright (c) 2000 Massachusetts Institute of Technology 6 | * Copyright (c) 2000 Matteo Frigo 7 | * 8 | * This library is free software; you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 21 | * USA. 22 | * 23 | */ 24 | 25 | /* hook manager */ 26 | #include 27 | #include 28 | #include 29 | 30 | void Cilk_add_hook(HookList **listp, HookT fn) 31 | { 32 | HookList *new; 33 | 34 | new = (HookList *)malloc(sizeof (HookList)); 35 | 36 | new->fn = fn; 37 | new->next = NULL_HOOK; 38 | 39 | /* traverse the list */ 40 | while (*listp != NULL_HOOK) 41 | listp = &((*listp)->next); 42 | 43 | /* append at the end */ 44 | *listp = new; 45 | } 46 | 47 | void Cilk_run_hooks(HookList *list) 48 | { 49 | for ( ; list != NULL_HOOK ; list = list->next) 50 | list->fn(); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /runtime/malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Massachusetts Institute of Technology 3 | * Copyright (c) 2000 Matteo Frigo 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 2.1 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | * 20 | */ 21 | 22 | /* 23 | * This file used to contain a simple malloc()/free() for Cilk. 24 | * Now we use the standard implementation on top of posix threads. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | FILE_IDENTITY(ident, 31 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/malloc.c $ $LastChangedBy: bradley $ $Rev: 1698 $ $Date: 2004-10-22 22:10:46 -0400 (Fri, 22 Oct 2004) $"); 32 | 33 | #if HAVE_STRINGS_H 34 | #include 35 | #endif 36 | 37 | #if HAVE_STRING_H 38 | #include 39 | #endif 40 | 41 | #if HAVE_CONFIG_H 42 | #include 43 | #endif 44 | 45 | #if HAVE_STDLIB_H 46 | #include 47 | #endif 48 | 49 | #if HAVE_MALLOC_H 50 | #include 51 | #endif 52 | 53 | /* 54 | * use posix malloc() (assumed thread-safe) 55 | */ 56 | void *Cilk_malloc(size_t size) 57 | { 58 | void *x = malloc(size); 59 | /*printf("Cilk_malloc - size=%d p=%p\n", size, x);*/ 60 | return x; 61 | } 62 | 63 | void *Cilk_malloc_fixed(size_t size) 64 | { 65 | void *x = malloc(size); 66 | /*printf("Cilk_malloc_fixed - size=%d p=%p\n", size, x);*/ 67 | return x; 68 | } 69 | 70 | #if HAVE_MEMALIGN 71 | void *Cilk_memalign(size_t alignment, size_t size) 72 | { 73 | /*printf("memalign\n");*/ 74 | return memalign(alignment, size); 75 | } 76 | #endif 77 | 78 | void Cilk_free(void *s) 79 | { 80 | /*printf("Cilk_free - p=%p\n", s);*/ 81 | free(s); 82 | 83 | } 84 | 85 | void *Cilk_calloc(size_t nelem, size_t elsize) 86 | { 87 | /*printf("calloc\n");*/ 88 | return calloc(nelem, elsize); 89 | } 90 | 91 | void *Cilk_realloc(void *s, size_t size) 92 | { 93 | void* x = realloc(s, size); 94 | /*printf("Cilk_reaslloc newsize = %s p=%p newp= %p\n", size, s,x);*/ 95 | return x; 96 | } 97 | 98 | void *Cilk_valloc(size_t size) 99 | { 100 | /*printf("valloc\n");*/ 101 | return valloc(size); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /runtime/mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Massachusetts Institute of Technology 3 | * Copyright (c) 2000 Matteo Frigo 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 2.1 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #if HAVE_PTHREAD_H 28 | #include 29 | #endif 30 | 31 | FILE_IDENTITY(ident, 32 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/mutex.c $ $LastChangedBy: bradley $ $Rev: 1698 $ $Date: 2004-10-22 22:10:46 -0400 (Fri, 22 Oct 2004) $"); 33 | 34 | 35 | /***********************************************************\ 36 | * Support for mutexen 37 | \***********************************************************/ 38 | 39 | /* implementation over shared memory */ 40 | #define ACQUIRE(lock) Cilk_xchg(lock, 1) 41 | #define RELEASE(lock) *(lock) = 0 42 | 43 | /* initialize lock */ 44 | static inline void Cilk_mutex_init_memory(Cilk_mutex *lock) 45 | { 46 | RELEASE(&(lock->memory)); 47 | } 48 | 49 | /* destroy mutex - not sure about the implementation... */ 50 | static inline void Cilk_mutex_destroy_memory(Cilk_mutex *lock) 51 | { 52 | RELEASE(&(lock->memory)); 53 | } 54 | /* 55 | * Obtain lock . Waits until lock is available. 56 | */ 57 | static inline void Cilk_mutex_wait_memory(CilkWorkerState *const UNUSED(ws), 58 | Cilk_mutex *lock) 59 | { 60 | if (ACQUIRE(&(lock->memory)) == 0) /* fast case */ 61 | return; 62 | 63 | Cilk_enter_state(ws, STATE_WAITING_FOR_LOCK); 64 | 65 | CILK_WMB(); 66 | 67 | /* 68 | * This hackery should reduce bus traffic, if the 69 | * cache is snooped correctly. 70 | */ 71 | do { 72 | while (*&(lock->memory) != 0); 73 | } while (ACQUIRE(&(lock->memory)) != 0); 74 | 75 | CILK_RMB(); 76 | 77 | Cilk_exit_state(ws, STATE_WAITING_FOR_LOCK); 78 | } 79 | 80 | /* 81 | * Try to obtain lock . Returns 1 upon success and 0 upon failure. 82 | * Do not wait. 83 | */ 84 | static inline int Cilk_mutex_try_memory(Cilk_mutex *lock) 85 | { 86 | CILK_WMB(); 87 | if (ACQUIRE(&(lock->memory)) == 0) { 88 | CILK_RMB(); 89 | return 1; 90 | } else 91 | return 0; 92 | } 93 | 94 | /* 95 | * Give up lock . 96 | */ 97 | static inline void Cilk_mutex_signal_memory(Cilk_mutex *lock) 98 | { 99 | CILK_WMB(); 100 | RELEASE(&(lock->memory)); 101 | } 102 | 103 | 104 | /******************************* 105 | * Posix-threads locks 106 | *******************************/ 107 | /* 108 | * Initialize lock 109 | */ 110 | static inline void Cilk_mutex_init_posix(Cilk_mutex *lock) 111 | { 112 | pthread_mutex_init(&lock->posix, NULL); 113 | } 114 | 115 | /* 116 | * Obtain lock . Waits until lock is available. 117 | */ 118 | static inline void Cilk_mutex_wait_posix(CilkContext *const UNUSED(context), 119 | CilkWorkerState *const UNUSED(ws), 120 | Cilk_mutex *lock) 121 | { 122 | Cilk_enter_state(ws, STATE_WAITING_FOR_LOCK); 123 | 124 | pthread_mutex_lock(&lock->posix); 125 | 126 | Cilk_exit_state(ws, STATE_WAITING_FOR_LOCK); 127 | } 128 | 129 | /* 130 | * Give up lock . 131 | */ 132 | static inline void Cilk_mutex_signal_posix(Cilk_mutex *lock) 133 | { 134 | pthread_mutex_unlock(&lock->posix); 135 | } 136 | 137 | /* 138 | * Try to obtain lock . Returns 1 if it succeeds and 0 if it fails. 139 | * Does not wait. 140 | */ 141 | static inline int Cilk_mutex_try_posix(Cilk_mutex *lock) 142 | { 143 | if (pthread_mutex_trylock(&lock->posix) == 0) { 144 | return 1; 145 | } else { 146 | return 0; 147 | } 148 | } 149 | 150 | /* 151 | * Destroy the mutex 152 | */ 153 | static inline void Cilk_mutex_destroy_posix(Cilk_mutex* lock) 154 | { 155 | pthread_mutex_destroy(&lock->posix); 156 | } 157 | 158 | /********************* 159 | * Lock glue 160 | *********************/ 161 | void Cilk_mutex_init(CilkContext *const context, 162 | Cilk_mutex *lock) 163 | { 164 | if (USE_PARAMETER1(options->memory_locks)) { 165 | Cilk_mutex_init_memory(lock); 166 | } else { 167 | Cilk_mutex_init_posix(lock); 168 | } 169 | } 170 | 171 | void Cilk_mutex_wait(CilkContext *const context, 172 | CilkWorkerState *const ws, 173 | Cilk_mutex *lock) 174 | { 175 | if (USE_PARAMETER1(options->memory_locks)) { 176 | Cilk_mutex_wait_memory(ws, lock); 177 | } else { 178 | Cilk_mutex_wait_posix(context, ws, lock); 179 | } 180 | } 181 | 182 | void Cilk_mutex_signal(CilkContext *const context, 183 | Cilk_mutex *lock) 184 | { 185 | if (USE_PARAMETER1(options->memory_locks)) { 186 | Cilk_mutex_signal_memory(lock); 187 | } else { 188 | Cilk_mutex_signal_posix(lock); 189 | } 190 | } 191 | 192 | 193 | int Cilk_mutex_try(CilkContext *const context, 194 | Cilk_mutex *lock) 195 | { 196 | if (USE_PARAMETER1(options->memory_locks)) { 197 | return Cilk_mutex_try_memory(lock); 198 | } else { 199 | return Cilk_mutex_try_posix(lock); 200 | } 201 | } 202 | 203 | void Cilk_mutex_destroy(CilkContext *const context, 204 | Cilk_mutex *lock) 205 | { 206 | if(USE_PARAMETER1(options->memory_locks)) { 207 | Cilk_mutex_destroy_memory(lock); 208 | } else { 209 | Cilk_mutex_destroy_posix(lock); 210 | } 211 | } 212 | 213 | 214 | -------------------------------------------------------------------------------- /runtime/sysdep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Massachusetts Institute of Technology 3 | * Copyright (c) 2000 Matteo Frigo 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 2.1 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef HAVE_SYS_TIME_H 32 | #include 33 | #endif 34 | 35 | #if HAVE_SCHED_H 36 | #include 37 | #endif 38 | 39 | #if HAVE_MALLOC_H 40 | #include 41 | #endif 42 | 43 | #if HAVE_SYS_PROCFS_H 44 | #include 45 | #endif 46 | 47 | FILE_IDENTITY(ident, 48 | "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/runtime/sysdep.c $ $LastChangedBy: bradley $ $Rev: 1698 $ $Date: 2004-10-22 22:10:46 -0400 (Fri, 22 Oct 2004) $"); 49 | 50 | /***********************************************************\ 51 | * Architecture-specific options 52 | \***********************************************************/ 53 | 54 | /* 55 | * Parse any architecture-specific command-line options. 56 | * and are the original arguments passed on the command line, 57 | * and is the index of the first architecture-specific option (if any). 58 | * This function returns the index of the first user option, or if 59 | * there aren't any. 60 | */ 61 | int Cilk_arch_specific_options(int i, int UNUSED(argc), char UNUSED(*argv[])) 62 | { 63 | return i; 64 | } 65 | 66 | /********************************************************** 67 | * Priority control 68 | **********************************************************/ 69 | 70 | void Cilk_lower_priority(CilkWorkerState *const ws) 71 | { 72 | #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(PRI_OTHER_MIN) 73 | { 74 | struct sched_param param; 75 | param.sched_priority = PRI_OTHER_MIN; 76 | pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m); 77 | } 78 | #endif 79 | Cilk_yield(ws); 80 | } 81 | 82 | void Cilk_raise_priority(CilkWorkerState *const UNUSED(ws)) 83 | { 84 | #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(PRI_OTHER_MAX) 85 | { 86 | struct sched_param param; 87 | param.sched_priority = PRI_OTHER_MAX; 88 | pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m); 89 | } 90 | #endif 91 | } 92 | 93 | void Cilk_yield(CilkWorkerState *const UNUSED(ws)) 94 | { 95 | usleep(1); /* This seems simpler and better than all the code below. 96 | * The problem is that even with sched_yield() I can incur a significant 97 | * slowdown on serial code with lots of spawns. E.g., if you writen 98 | * for (i=0; i<10; i++) {spawn f(x); sync;} 99 | * why would you want to do that? If f is a cilk procedure, you cannot call 100 | * f without using spawn. Canary runs into this. 101 | */ 102 | return; 103 | #if 0 104 | #if CILK_WITH_POSIX_THREADS 105 | # if HAVE_SCHED_YIELD 106 | sched_yield(); 107 | # elif HAVE_SGINAP 108 | sginap(1); 109 | # endif 110 | #else 111 | # if HAVE_SCHED_YIELD 112 | sched_yield(); 113 | # elif HAVE_YIELD 114 | yield(); 115 | # endif 116 | #endif 117 | #endif 118 | } 119 | 120 | /***********************************************************\ 121 | * Machine size 122 | \***********************************************************/ 123 | int Cilk_partition_size(void) 124 | { 125 | #ifdef _SC_NPROCESSORS_ONLN 126 | /* 127 | * This is only really right for an unloaded machine. 128 | */ 129 | return sysconf(_SC_NPROCESSORS_ONLN); 130 | #else 131 | return 1; 132 | #endif 133 | } 134 | 135 | /*************************************************** 136 | * Timer control 137 | ***************************************************/ 138 | #if defined(PIOCSET) && defined(PR_MSACCT) /* true on solaris */ 139 | static int openslashproc(int pid) 140 | { 141 | char buf[64]; 142 | int fd; 143 | 144 | sprintf(buf, "/proc/%d", pid); 145 | if ( (fd = open(buf, 2)) < 0 ) 146 | perror("open /proc"); 147 | 148 | return fd; 149 | } 150 | 151 | static void start_microaccounting(void) 152 | { 153 | int fd, flags; 154 | 155 | fd = openslashproc(getpid()); 156 | 157 | flags = PR_MSACCT; 158 | if (ioctl(fd, PIOCSET, &flags, sizeof (flags)) < 0) { 159 | perror("ioctl set microstate acct"); 160 | } 161 | } 162 | #else 163 | static void start_microaccounting(void) 164 | { 165 | } 166 | #endif 167 | 168 | /********************************************************** 169 | * Initialization of this module 170 | **********************************************************/ 171 | 172 | void Cilk_arch_specific_init(void) 173 | { 174 | start_microaccounting(); 175 | } 176 | 177 | void Cilk_arch_specific_per_worker_init(void) 178 | { 179 | start_microaccounting(); 180 | } 181 | 182 | -------------------------------------------------------------------------------- /support/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | 3 | pkgdatadir = $(pkglibdir) 4 | noinst_PROGRAMS = cilkclocal 5 | bin_PROGRAMS = cilkc 6 | PTHREAD_LIBS=@PTHREAD_LIBS@ 7 | RPATH=@HAVE_RPATH@ 8 | 9 | cilkclocal_SOURCES = cilkc.c make-temp-file.c make-temp-file.h 10 | cilkclocal_CPPFLAGS=\ 11 | -DCILKHEADER_DIR="\"`(cd $(top_srcdir); pwd)`/runtime\"" \ 12 | -DCILK_RTSBUILD_DIR="\"`(cd $(top_builddir); pwd)`/runtime\"" \ 13 | -DCILK2C_DIR="\"`(cd $(top_builddir); pwd)`/cilk2c\"" \ 14 | -DLIBS_DIR="\"`(cd $(top_builddir); pwd)`/runtime/.libs\"" \ 15 | -DLIBS2_DIR="\"`(cd $(top_builddir); pwd)`/runtime\"" 16 | 17 | cilkc_SOURCES = cilkc.c make-temp-file.c make-temp-file.h 18 | cilkc_CPPFLAGS=-DCILKHEADER_DIR="\"$(prefix)/include/cilk\"" \ 19 | -DCILK2C_DIR="\"$(pkglibdir)\"" -DLIBS_DIR="\"$(libdir)\"" \ 20 | -DLIBS2_DIR="\"$(libdir)/cilk\"" 21 | 22 | EXTRA_DIST = cilk.m4 automake-cilk dotemacs.el 23 | 24 | DISTCLEANFILES = *~ 25 | MAINTAINERCLEANFILES = Makefile.in 26 | -------------------------------------------------------------------------------- /support/cilk.m4: -------------------------------------------------------------------------------- 1 | dnl This file contains autoconf macros for use with Cilk 2 | dnl 3 | dnl ### Selecting which language to use for testing 4 | dnl AC_LANG_CILK() 5 | AC_DEFUN([AC_LANG_CILK], 6 | [define([AC_LANG], [CILK])dnl 7 | ac_ext=cilk 8 | # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. 9 | ac_cpp='$CPP $CPPFLAGS' 10 | ac_compile='${CILK-ilk} -c $CILKFLAGS $CPPFLAGS conftest.$ac_ext 1>&AC_FD_CC' 11 | ac_link='${CILK-cilk} -o conftest${ac_exeext} $CILKFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AC_FD_CC' 12 | cross_compiling=$ac_cv_prog_cilk_cross 13 | ]) 14 | dnl AC_PROG_CILK_WORKS 15 | AC_DEFUN([AC_PROG_CILK_WORKS], 16 | [AC_MSG_CHECKING([whether the cilk compiler ($CILK $CFLAGS $LDFLAGS) works]) 17 | AC_LANG_SAVE 18 | AC_LANG_CILK 19 | AC_TRY_COMPILER([cilk int main(int argc, char *argv[]){sync; return(0);}], ac_cv_prog_cilk_works, ac_cv_prog_cilk_cross) 20 | AC_LANG_RESTORE 21 | AC_MSG_RESULT($ac_cv_prog_cilk_works) 22 | if test $ac_cv_prog_cilk_works = no; then 23 | AC_MSG_ERROR([installation or configuration problem: cilk compiler cannot create executables.]) 24 | fi 25 | AC_MSG_CHECKING([whether the C compiler ($CILK $CFLAGS $LDFLAGS) is a cross-compiler]) 26 | AC_MSG_RESULT($ac_cv_prog_cilk_cross) 27 | cross_compiling=$ac_cv_prog_cilk_cross 28 | ]) 29 | dnl AC_PROG_CILK_G, 30 | AC_DEFUN([AC_PROG_CILK_G], 31 | [AC_CACHE_CHECK(whether ${CILK-cilk} accepts -g, ac_cv_prog_cilk_g, 32 | [echo 'cilk void f(void){}' > conftest.cilk 33 | if test -z "`${CILK-cilk} -g -c conftest.cilk 2>&1`"; then 34 | ac_cv_prog_cilk_g=yes 35 | else 36 | ac_cv_prog_cilk_g=no 37 | fi 38 | rm -f conftest* 39 | ])]) 40 | dnl AC_PROG_CILK 41 | AC_DEFUN([AC_PROG_CILK], 42 | [AC_BEFORE([$0], [AC_PROG_CILKCPP])dnl 43 | AC_CHECK_PROGS(CILK, $CILK cilk, cilk) 44 | 45 | AC_PROG_CILK_WORKS 46 | AC_PROG_CILK_G 47 | 48 | dnl Check whether -g works, even if CILKFLAGS is set, in case the package 49 | dnl plays around with CILKFLAGS (such as to build both debugging and 50 | dnl normal versions of a library), tasteless as that idea is. 51 | ac_test_CILKFLAGS="${CILKFLAGS+set}" 52 | ac_save_CILKFLAGS="$CILKFLAGS" 53 | CILKFLAGS= 54 | if test "$ac_test_CILKFLAGS" = set; then 55 | CILKFLAGS="$ac_save_CILKFLAGS" 56 | elif test $ac_cv_prog_cilk_g = yes; then 57 | CILKFLAGS="-g -O2" 58 | else 59 | CILKFLAGS="-O2" 60 | fi 61 | ]) 62 | AC_SUBST(CILKFLAGS)dnl 63 | -------------------------------------------------------------------------------- /support/dotemacs.el: -------------------------------------------------------------------------------- 1 | ;; Enable c-mode for .cilk files 2 | (or (assoc "\\.cilk\\'" auto-mode-alist) 3 | (setq auto-mode-alist (cons '("\\.cilk\\'" . c-mode) 4 | auto-mode-alist))) 5 | -------------------------------------------------------------------------------- /support/make-temp-file.h: -------------------------------------------------------------------------------- 1 | /* Function declarations for libiberty (cut down to just use make_temp_file) 2 | 3 | Copyright 2001, 2002 Free Software Foundation, Inc. 4 | 5 | Note - certain prototypes declared in this header file are for 6 | functions whoes implementation copyright does not belong to the 7 | FSF. Those prototypes are present in this file for reference 8 | purposes only and their presence in this file should not construed 9 | as an indication of ownership by the FSF of the implementation of 10 | those functions in any way or form whatsoever. 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2, or (at your option) 15 | any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place - Suite 330, 25 | Boston, MA 02111-1307, USA. 26 | 27 | Written by Cygnus Support, 1994. 28 | 29 | The libiberty library provides a number of functions which are 30 | missing on some operating systems. We do not declare those here, 31 | to avoid conflicts with the system header files on operating 32 | systems that do support those functions. In this file we only 33 | declare those functions which are specific to libiberty. */ 34 | 35 | extern char *make_temp_file (const char *); 36 | --------------------------------------------------------------------------------