0% found this document useful (0 votes)
31 views

WINSEM2022-23 CSE4001 ELA VL2022230504176 Reference Material I 16-12-2022 How To Create New Project - Sample OpenMP Code

This document provides instructions for performing parallel and distributed computing using various tools and platforms: 1) It describes how to create, compile, and run a simple C program in Linux using commands like gcc and gedit. 2) It outlines the steps to create a new project in Microsoft Visual Studio 2008, including choosing project types and settings. 3) It includes sample C code using OpenMP directives to print messages in parallel and shares variables between threads. 4) It shows how to compile and run code in Visual Studio 2008 using commands like Build Solution and Start Without Debugging.

Uploaded by

keerthana rajeev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

WINSEM2022-23 CSE4001 ELA VL2022230504176 Reference Material I 16-12-2022 How To Create New Project - Sample OpenMP Code

This document provides instructions for performing parallel and distributed computing using various tools and platforms: 1) It describes how to create, compile, and run a simple C program in Linux using commands like gcc and gedit. 2) It outlines the steps to create a new project in Microsoft Visual Studio 2008, including choosing project types and settings. 3) It includes sample C code using OpenMP directives to print messages in parallel and shares variables between threads. 4) It shows how to compile and run code in Visual Studio 2008 using commands like Build Solution and Start Without Debugging.

Uploaded by

keerthana rajeev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Parallel and Distributed Computing Lab

1
To perform in Linux Command prompt

2
• How to create ,compile and run

• $gedit welcome.c
• To compile
– $gcc –o welcome fopenmp welcome.c

Or

– $ gcc welcome.c -fopenmp –o welcome

• To run :
– $./welcome
3
telnet 10.10.5.21

4
Parallel and Distributed Computing Lab
How to Create New Project?
Using MS Visual Studio 2008

5
Steps1

1. open Microsoft Visual Studio 2008(start > all


programs > Microsoft Visual Studio 2008 >Microsoft
Visual Studio 2008 IDE)
• File > New > Project, Keyboard shortcut: Ctrl+shift+N

6
Step2

• Win32 > Win32 console application > enter the project name
in name column > Click OK as shown below.

7
Step3

• Click Next > Choose Empty Project > finish then IDE
shows solution Explorer

8
Step4

9
Step 5
• In the Solution Explorer choose Source File> Add> New Item
as shown below

• Then you can write the code at IDE


10
HOW TO CHAGE PROPERTIES OF MICROSOFT VISUAL Step 6
STUDIO 2008 TO ENABLE INTEL C++ COMPILER ?
• Choose Project > use Intel (R) C++ and Click Yes on
confirmation, as shown below.

11
Step 7:

Right click on Solution Explorer C++ icon and


choose properties

12
Step 8
In the properties page choose configuration properties > c/c++ >
optimization change properties as shown below.

13
HOW TO COMPILE & RUN CODE?
Compiling:
• In Microsoft Visual Studio 2008 IDE choose Project > Build
solution.
• Keyboard shortcut: F7
• If it is already compiled once then choose Project > Rebuild
solution.
• Keyboard shortcut: ctrl+alt+F7

Run:
In MICROSOFT VISUAL STUDIO choose Debug> Start Without
Debugging, Keyboard shortcut: ctrl+F5.

14
To perform Open MP Programming in
Code Blocks
https://www.youtube.com/watch?v=p0woqF2X
Ceg

15
• Sample C program to print a messege.
#include<stdio.h>
int main()
{
printf(" welcome to PDC Lab\n");
return 0;
}
• C program to print a messege with OpenMP directives.
#include<stdio.h>
#include<omp.h>
int main()
{
#pragma omp parallel
{
printf(" welcome to PDC Lab\n");
}
getch();
return 0;
}
16
Sample Code:
#include <stdio.h>
#include <omp.h>
int main()
{
#pragma omp parallel
{
printf("E is the second vowel\n");
} getch();
return 0;
}
17
Sample code:
##include <stdio.h>
#include <omp.h>
int main()
{
int i=5;
#pragma omp parallel
{
printf("E is equal to %d\n",i);
}
getch();
return 0;
}
OUTPUT:
E is equal to 5
E is equal to 5
18
#include <stdio.h>
#include <omp.h>
int main() {
int i= 256; // a shared variable
#pragma omp parallel
{ int x; // a variable local or private to each thread
x = omp_get_thread_num();
printf("x = %d, i = %d\n",x,i);
} getch();
return 0;
}
Output:
x = 0, i = 256
x = 1, i = 256
Included is a call to a function called omp_get_thread_num().
This integer function is part of the OpenMP runtime library.
It returns an integer unique to each thread that ranges from zero
19
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main (int argc, char *argv[])
{
int nthreads, tid, procs, maxt, inpar, dynamic, nested;
/* Start parallel region */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num(); /* Only master thread does this */
if (tid == 0)
{
printf("Thread %d getting environment info...\n", tid);
20
/* Get environment information */
procs = omp_get_num_procs();
nthreads = omp_get_num_threads();
maxt = omp_get_max_threads();
inpar = omp_in_parallel();
dynamic = omp_get_dynamic();
nested = omp_get_nested();

21
/* Print environment information */
printf("Number of processors = %d\n", procs);
printf("Number of threads = %d\n", nthreads);
printf("Max threads = %d\n", maxt);
printf("In parallel? = %d\n", inpar);
printf("Dynamic threads enabled? = %d\n", dynamic);
printf("Nested parallelism supported? = %d\n", nested);
}
}
getch();
return 0;
}

OUTPUT:-
Thread 0 getting environment info...
Number of processors = 2
Number of threads = 2
Max threads = 2
In parallel? = 1
Dynamic threads enabled? = 0
Nested parallelism supported? = 0
22

You might also like