Prevention of a data race in a parallelised program, Operating System

Present your own fully documented and tested programming example illustrating the prevention of a data race in a parallelised program.

This is an example where total number of prime number between 2 and 10000 is being calculated. The order of memory accesses is prevented from being non-deterministic and from the code data race is avoided by making it parallelized with OpenMP directives.  The inconsistency can be seen by running the program consecutively for 3 or more times.





#define MyThreads 4

#define num 10000


   int primeNum[num];

   int primeF[num];


   int is_prime(int v)


    int i;

    int lim = floor(sqrt(v)) + 1;


    for (i = 2; i < lim; i++) {

           /* no need to check against known composites */

           if (!primeF[i])


           if (v % i == 0) {

               primeF[v] = 0;

               return 0;



       return (v > 1);



   int main(int argn, char **argv)


       int i;

       int total = 0;

            printf("Enter a number greater than 2");

            scanf("%d", &num)

   #ifdef _OPEnumMP





       for (i = 0; i < num; i++) {

           primeF[i] = 1;



       #pragma omp parallel for

       for (i = 2; i < num; i++) {

           if ( is_prime(i) ) {

               primeNum[total] = i;




        printf("total prime numbers that lie between 2 and %d: %d\n",

              num, total);

       return 0;


Posted Date: 6/29/2012 2:13:59 AM | Location : United States

Related Discussions:- Prevention of a data race in a parallelised program, Assignment Help, Ask Question on Prevention of a data race in a parallelised program, Get Answer, Expert's Help, Prevention of a data race in a parallelised program Discussions

Write discussion on Prevention of a data race in a parallelised program
Your posts are moderated
Related Questions
How many disk operations are needed to fetch the i-node for the file /usr/ast/courses/os/handout.t? Assume that the i-node for the root directory is in memory, but nothing else alo

In a table format, discuss the differences between the fixed partition and the variable partition memory organization in terms of the basic idea, memory structure, advantages

p0A B C D A B C D A B C D 2 0 12 2012 1000 1354 0632 0014

Gang Scheduling : A set of related process is scheduled to execute on a set of processors at the similar time, on a 1-to-1 basis. Closely related processes or threads may be sched

Operating Systems 1. Explain Micro-kernel? Specify the benefits of Micro-kernel? 2. Describe seven state process models used for OS with necessary diagram. Differentiate bet

Develop a utility in C language which will run in Linux operating systems to display following properties of the system: ? Processor speed ? Ram size ? Computer name ? System time

What is graceful degradation? In multiprocessor systems, failure of single processor will not halt the system, but only slow it down by sharing the work of failure system by ot

Give an overview of UNIX based file systems. UNIX and UNIX-like operating systems allocate a device name to each device, other than this isn't how the files on that device are

How is memory management done using bit maps? A bit map is here in this we signify the bit value as 0 or 1. 1-hole 0-process In this we are able to represent the proce