/*NOTES: // means single line comment in c/C++ $ means right after it the command line starts # to warn the compiler for adding aditional files or special events What is this program: This is a simple program written in c, and using OpenMP to parallelize a part of the code. This code shows how to do conditional parallelization. If the condition is true, then the block of code right after the pragma. This program also shows how a for loop could be parallelized so that the number of itterations are devided among the threads. How to Compile: $ gcc -fopenmp omp_if_parallel_for.c -o omp_if_parallel_for How Setup Runtime Environment: $ export OMP_NUM_THREADS=32 How to Run this program: $ ./omp_if_parallel_for Output: Run the program for multipel times, and each time change the value being asked. What difference do you observe? */ #include #include #include int main(){ int nitt; // number of itterations that user supplied int limit; // limit on when to start the parallel region int nthreads; // how many threads are taking part in running this program int thread_id; // what is the id of each thread printf("please enter an integer value for when to start paralllel region:\n" ); scanf("%d", &limit); printf("please enter an integer value for number of itterations: \n" ); scanf("%d", &nitt); //next line pragma will chekc the if condition. If the number of itterations are // bigger than the limit. It will fork the number of threads that were specified // in the environment variable, and divide the number of itterations among them. #pragma omp parallel if(nitt > limit) { //Each thread will recive a copy of the variable thread_id. And each thread's // thread_id variables will hold a unique integer value that is different from // every other thread thread_id = omp_get_thread_num(); int i; //below pragma tells the compiler to run the for loop in parallel. by deviding the // number of itterations to different threads. Example: if 100 itterations #pragma omp for for(i =0; i