Skip to content

Commit

Permalink
cilk implementation and makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
truncs committed Apr 30, 2012
1 parent b35f4bd commit 83ef7fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions hw3/task1/c/Makefile
@@ -0,0 +1,12 @@
CILKPP = cilk++
LIBARG = -O1 -g -lcilkutil
TARGET = cilk_qsort
SRC = par_randomized_looping_qsort.cilk

all: $(TARGET)

$(TARGET): $(SRC)
$(CILKPP) $(SRC) $(LIBARG) -o $@

clean:
rm -f $(TARGET)~
14 changes: 7 additions & 7 deletions hw3/task1/c/par_randomized_looping_qsort.cilk
Expand Up @@ -18,13 +18,13 @@ void prefix_sum(vector<long> & x, vector<long>& s) {
s[0] = x[0];

else {
for (long i = 0; i < n/2; ++i)
cilk_for (long i = 0; i < n/2; ++i)
{
y[i] = x[2*i] + x[2*i + 1];
}
vector<long> z(n/2);
prefix_sum(y, z);
for (long i = 0; i < n; ++i)
cilk_for (long i = 0; i < n; ++i)
{
if (i == 0)
s[0] = x[0];
Expand All @@ -47,7 +47,7 @@ long par_partition(vector<long>& A, long q, long r, long x) {
return q;

vector<long> B(n), lt(n), gt(n);
for (long i = 0; i < n; ++i)
cilk_for (long i = 0; i < n; ++i)
{
B[i] = A[q + i];
if (B[i] < x)
Expand All @@ -72,7 +72,7 @@ long par_partition(vector<long>& A, long q, long r, long x) {
long k = q + new_lt[n - 1];
A[k] = x;

for (long i = 0; i < n; ++i)
cilk_for (long i = 0; i < n; ++i)
{
if (B[i] < x)
A[q + new_lt[i] - 1] = B[i];
Expand Down Expand Up @@ -123,17 +123,17 @@ void par_randomized_qsort(vector<long>& A, int q, int r) {
// cout<<"-----------"<<endl;
}
//cout<<"Found a good pivot"<<A[k]<<endl;
par_randomized_qsort(A, q, k - 1);
cilk_spawn par_randomized_qsort(A, q, k - 1);
par_randomized_qsort(A, k + 1, r);

sync;

}



}

int main(int argc, char *argv[]) {
int cilk_main(int argc, char *argv[]) {

ifstream myfile (argv[1]);
long n = 0;
Expand Down

0 comments on commit 83ef7fd

Please sign in to comment.