Program for two library methods with thread , Computer Networking

Assignment Help:

#include

void subdomain(float x[ ], int istart, int ipoints)

{

int i;

for (i = 0; i < ipoints; i++)

x[istart+i] = 123.456;

}

void sub(float x[ 10000], int npoints)

{

int t_num, num_t, ipoints, istart;

#pragma omp parallel default(shared) private(t_num , num_t, ipoints, istart)

{

t_num = omp_get_thread_num(); //thread number of current thread num_t = omp_get_num_threads(); //number of threads

ipoints = npoints / num_t; /* size of partition */

istart = t_num * ipoints; /* starting array index */

if (t_num == num_t-1) /* last thread may do more */

ipoints = npoints - istart;

subdomain(x, istart, ipoints);

}

}

int main()

{

float array[10000];

sub(array, 10000);

 return 0;

}

In this example we used two library methods : omp_get_num_threads() and

omp_get_thread_num().

omp_get_num_threads() returns number of threads that are currently being used in parallel directive.

omp_get_thread_num() returns thread number (an integer from 0 to omp_get_num_threads() - 1 where thread 0 is the master thread).


Related Discussions:- Program for two library methods with thread

Define the term socks- network security, Define the term Socks- Network sec...

Define the term Socks- Network security As it is well known, each type of network security protects data at a different layer of the OSI model. Built-in at each layer lies the

Objective of parallel algorithms, After studying this part the students wil...

After studying this part the students will be able to understand about the following: Analysis of Parallel Algorithms; Different Models of Computation; o   Interco

Error detection-general, Q. Error Detection-General? Sender transmi...

Q. Error Detection-General? Sender transmits every data unit twice Receiver performs bit-by-bit comparison between those two versions of data. Any mismatch would

Explain the different signal propagation behaviours, Question : (a) Lis...

Question : (a) List down and explain the different signal propagation behaviours that radio waves exhibit. (b) Explain the term Delay Spread with reference to signal propaga

Print Servers, Which of the following commands will display the current pri...

Which of the following commands will display the current print jobs on a printer named Office Printer 01?

Private networks, Private  Networks The information routes from one ne...

Private  Networks The information routes from one networks  to another  network through  a leased line. If an  organization needs privacy  can use a private networks  or networ

Parallel random access machines, PRAM is one of the models used for designi...

PRAM is one of the models used for designing the parallel algorithm as given in Figure. The PRAM models have the following components: A set of identical type of processors

Illustrate the products based on socks protocol, Illustrate the products ba...

Illustrate the products based on Socks protocol There are a number of products based on SOCKS specifications such as Auto SOCKS available in the market. The latest version is S

Thread libraries, The most difficult representatives of shared memory progr...

The most difficult representatives of shared memory programming models are thread libraries present in mainly of the modern operating systems. Some examples for thread libraries ar

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd