Intel Multi Core Programming

Embed Size (px)

DESCRIPTION

Basic multi core parallel programs, developed in Intel C++ compiler

Text of Intel Multi Core Programming

VIT UNIVERSITY VELLORE, KATPADI, TAMIL NADU PIN-632014

Multi Core Programming LabLAB PROGRAMS

Sujesh P Lal 08MCS0544/4/2009

1. Write a Parallel program to print hello World using open MP#include #include int main() { #pragma omp parallel { printf("\n\t hello world"); } printf("\n"); return 0; }

Result

2

2. Write a program to print following details using OpenMP a. Number of threads currently running using main thread. b. Number of processors c. Max. Number of threads d. Thread identification number Code#include #include int main() { int a,b,c,d; #pragma omp parallel { a=omp_get_num_threads(); b=omp_get_max_threads(); c=omp_get_num_procs(); d=omp_get_thread_num(); } printf("\n\t number of threads identified in this system=%d",a); printf("\n\t maximum number of threads identified in this system=%d",b); printf("\n\t to find number of processes running in your system in this system =%d",c); printf("\n\t to find thread identification number in your system in this system=%d",d); printf("\n"); return 0; } Result:

3

3. Write a code to find the biggest and the smallest number from given three Numbers. Make sure that biggest number is computing by one core and smallest number is computing by another core in parallel. Code:#include #include int main() { int a,b,c; printf("\n\t enter values of a,b and scanf("%d %d %d",&a,&b,&c); #pragma omp parallel { if(omp_get_thread_num()) { if(a>b&&a>c) printf("\n\t %d is else if(b>a&&b>c) printf("\n\t %d is else printf("\n\t %d is } else { if(a