Using library methods returns number of threads, Computer Engineering

Assignment Help:

Q. Using Library methods returns number of threads?

#include < omp.h >

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 illustration we used two library methods : omp_get_num_threads() and omp_get_thread_num().

omp_get_num_threads() returns number of threads which 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 master thread).


Related Discussions:- Using library methods returns number of threads

What are different adder circuits you studied, Half Adder (for addition of ...

Half Adder (for addition of two bits) Full Adder (for addition of three bits) Carry look ahead adder Carry save adder Carry propagate adder

Flowchart, draw the flowchart for operator overloading in c++

draw the flowchart for operator overloading in c++

What is the difference between dpi and ppi, Question : (a) "Resolution ...

Question : (a) "Resolution refers to the sharpness and clarity of an image" (i) Explain what you understand by the above statement. (ii) What is the difference between D

Where the trunks lines are run, Trunks are the lines that run between? ...

Trunks are the lines that run between? Trunks are the lines which run in between switching stations.

Automatic stock control system in a supermarket, Automatic Stock Control Sy...

Automatic Stock Control System in a Supermarket -  Bar codes are associated to all goods/items sold by the supermarket as a means of identification -  Every bar code is asso

Describe jmx concepts and architecture, MX is conceptually easy, yet bears ...

MX is conceptually easy, yet bears the fruit of years of domain experience and research. In a nutshell, JMX describes a standard means for applications to expose management functio

Determine if the product of two integers are even, If the product of two in...

If the product of two integers a and b is even after that prove that either a is even or b is even. Answer: It is illustrated that product of a and b is even so let a * b = 2n.

State and describe the iros subsystems, Question: (a) iRoom was constru...

Question: (a) iRoom was constructed based on the guiding principles listed below, discuss on each one of those principles with respect to why the specific principle was adopted

Hubs are present in the network, Hubs are present in the network To inte...

Hubs are present in the network To interconnect the LAN with WANs.

State the benefits of encapsulation, State The Benefits of Encapsulation ...

State The Benefits of Encapsulation To hide the details of a class, you can declare that data or implementation in the private part of class so that other class clients will n

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