-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from LChenGit/delaware
delaware dataset part3
- Loading branch information
Showing
22 changed files
with
620 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* no race, but it needs to mention that u1 and u2 are not aliased | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
double *u1, *u2, c = 0.2; | ||
int n = 10, nsteps = 10; | ||
|
||
int main() | ||
{ | ||
u1 = malloc(n * sizeof(double)); | ||
u2 = malloc(n * sizeof(double)); | ||
for (int i = 1; i < n - 1; i++) | ||
u2[i] = u1[i] = 1.0 * rand() / RAND_MAX; | ||
u1[0] = u1[n - 1] = u2[0] = u2[n - 1] = 0.5; | ||
for (int t = 0; t < nsteps; t++) | ||
{ | ||
#pragma omp parallel for | ||
for (int i = 1; i < n - 1; i++) | ||
{ | ||
u2[i] = u1[i] + c * (u1[i - 1] + u1[i + 1] - 2 * u1[i]); | ||
} | ||
double *tmp = u1; | ||
u1 = u2; | ||
u2 = tmp; | ||
} | ||
for (int i = 0; i < n; i++) | ||
printf("%1.2lf ", u1[i]); | ||
printf("\n"); | ||
free(u1); | ||
free(u2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* Race due to u1 and u2 are aliased. | ||
* Data race pairs: u2[i]@39:7:W vs. u1[i]@39:15:R | ||
* u2[i]@39:7:W vs. u1[i - 1]@39:28:R | ||
* u2[i]@39:7:W vs. u1[i + 1]@39:40:R | ||
* u2[i]@39:7:W vs. u1[i]@39:56:R | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
double *u1, *u2, c = 0.2; | ||
int n = 10, nsteps = 10; | ||
|
||
int main() | ||
{ | ||
u1 = malloc(n * sizeof(double)); | ||
u2 = malloc(n * sizeof(double)); | ||
for (int i = 1; i < n - 1; i++) | ||
u2[i] = u1[i] = 1.0 * rand() / RAND_MAX; | ||
u1[0] = u1[n - 1] = u2[0] = u2[n - 1] = 0.5; | ||
for (int t = 0; t < nsteps; t++) | ||
{ | ||
#pragma omp parallel for | ||
for (int i = 1; i < n - 1; i++) | ||
{ | ||
u2[i] = u1[i] + c * (u1[i - 1] + u1[i + 1] - 2 * u1[i]); | ||
} | ||
double *tmp = u1; | ||
u1 = u2; // u2 = tmp; | ||
} | ||
for (int i = 0; i < n; i++) | ||
printf("%1.2lf ", u1[i]); | ||
printf("\n"); | ||
free(u1); | ||
free(u2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* No race. The array b is divided into two non-overlapping halves that are referenced by u[0] and u[1]. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
double c = 0.2; | ||
int n = 20, nsteps = 100; | ||
|
||
int main() | ||
{ | ||
double *b = malloc(2 * n * sizeof(double)); | ||
double *u[2] = {&b[0], &b[n]}; | ||
for (int i = 1; i < n - 1; i++) | ||
u[0][i] = u[1][i] = 1.0 * rand() / RAND_MAX; | ||
u[0][0] = u[0][n - 1] = u[1][0] = u[1][n - 1] = 0.5; | ||
int p = 0; | ||
for (int t = 0; t < nsteps; t++) | ||
{ | ||
#pragma omp parallel for | ||
for (int i = 1; i < n - 1; i++) | ||
{ | ||
u[1 - p][i] = u[p][i] + c * (u[p][i - 1] + u[p][i + 1] - 2 * u[p][i]); | ||
} | ||
p = 1 - p; | ||
} | ||
for (int i = 0; i < n; i++) | ||
printf("%1.2lf ", u[p][i]); | ||
printf("\n"); | ||
free(b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* Overlap of the two ranges u[0] and u[1] when u[1][i] is accessed. | ||
* Data race pairs: u[1 - p][i]@38:7:W vs. u[p][i - 1]@38:15:R | ||
* u[1 - p][i]@38:7:W vs. u[p][i + 1]@38:50:R | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
double c = 0.2; | ||
int n = 20, nsteps = 100; | ||
|
||
int main() | ||
{ | ||
double *b = malloc(2 * n * sizeof(double)); | ||
double *u[2] = {&b[0], &b[n - 2]}; // oops, should be b[n] | ||
for (int i = 1; i < n - 1; i++) | ||
u[0][i] = u[1][i] = 1.0 * rand() / RAND_MAX; | ||
u[0][0] = u[0][n - 1] = u[1][0] = u[1][n - 1] = 0.5; | ||
int p = 0; | ||
for (int t = 0; t < nsteps; t++) | ||
{ | ||
#pragma omp parallel for | ||
for (int i = 1; i < n - 1; i++) | ||
{ | ||
u[1 - p][i] = u[p][i] + c * (u[p][i - 1] + u[p][i + 1] - 2 * u[p][i]); | ||
} | ||
p = 1 - p; | ||
} | ||
for (int i = 0; i < n; i++) | ||
printf("%1.2lf ", u[p][i]); | ||
printf("\n"); | ||
free(b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* no race | ||
*/ | ||
|
||
#include <stdio.h> | ||
int nprod = 4, ncons = 4; | ||
int cap = 5, size = 0; | ||
int main() | ||
{ | ||
int nthread = nprod + ncons; | ||
#pragma omp parallel for shared(size, cap, nprod, ncons, nthread) num_threads(nthread) | ||
for (int i = 0; i < nthread; i++) | ||
{ | ||
if (i < nprod) | ||
while (1) | ||
{ // I am a producer | ||
#pragma omp critical | ||
if (size < cap) | ||
{ | ||
size++; // produce | ||
printf("Producer %d produced! size=%d\n", i, size); | ||
fflush(stdout); | ||
} | ||
} | ||
else | ||
while (1) | ||
{ // I am a consumer | ||
#pragma omp critical | ||
if (size > 0) | ||
{ | ||
size--; // consume | ||
printf("Consumer %d consumed! size=%d\n", i - nprod, size); | ||
fflush(stdout); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* race introduced because critical sections have different names for producer and consumer. | ||
* Data race pair: size@34:11:W vs. size@45:11:W | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdio.h> | ||
int nprod = 4, ncons = 4; | ||
int cap = 5, size = 0; | ||
int main() | ||
{ | ||
int nthread = nprod + ncons; | ||
#pragma omp parallel for shared(size, cap, nprod, ncons, nthread) num_threads(nthread) | ||
for (int i = 0; i < nthread; i++) | ||
{ | ||
if (i < nprod) | ||
while (1) | ||
{ // I am a producer | ||
#pragma omp critical(A) | ||
if (size < cap) | ||
{ | ||
size++; // produce | ||
printf("Producer %d produced! size=%d\n", i, size); | ||
fflush(stdout); | ||
} | ||
} | ||
else | ||
while (1) | ||
{ // I am a consumer | ||
#pragma omp critical(B) | ||
if (size > 0) | ||
{ | ||
size--; // consume | ||
printf("Consumer %d consumed! size=%d\n", i - nprod, size); | ||
fflush(stdout); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC | ||
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details. | ||
!!! | ||
!!! SPDX-License-Identifier: (BSD-3-Clause) | ||
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! | ||
*/ | ||
|
||
/* | ||
* This is a program based on a dataset contributed by | ||
* Wenhao Wu and Stephen F. Siegel @Univ. of Delaware. | ||
* Two threads sync using one lock. No race. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <omp.h> | ||
#include <assert.h> | ||
|
||
omp_lock_t l; | ||
int x = 1; | ||
|
||
int main() | ||
{ | ||
omp_init_lock(&l); | ||
#pragma omp parallel num_threads(2) | ||
{ | ||
int tid = omp_get_thread_num(); | ||
if (tid == 0) | ||
omp_set_lock(&l); | ||
#pragma omp barrier | ||
if (tid == 0) | ||
{ | ||
x = 0; | ||
omp_unset_lock(&l); | ||
} | ||
else if (tid == 1) | ||
{ | ||
omp_set_lock(&l); | ||
omp_unset_lock(&l); | ||
x = 1; | ||
} | ||
#pragma omp barrier | ||
} // end of parallel construct | ||
omp_destroy_lock(&l); | ||
printf("Done: x=%d\n", x); | ||
} |
Oops, something went wrong.