Вы находитесь на странице: 1из 18

Parallel Computing Lab

How to Create New Project?


Using MS Visual Studio 2008

1
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

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

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

4
Step4

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

• Then you can write the code at IDE

6
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.

7
Step 7:

Right click on Solution Explorer C++ icon and


choose properties

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

9
Step 9
In the properties page choose configuration properties > c/c++ >
Code Generation change properties as shown below.

10
HOW TO COMPLIE & 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.

11
• 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");
}
}

12
Sample Code:
#include <stdio.h>
#include <omp.h>
int main()
{
#pragma omp parallel
{
printf("E is the second vowel\n");
}
}
13
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
14
#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

15
/* 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();

16
#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);

17
/* 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
18

Вам также может понравиться