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

Learning abilities of perceptrons, Learning Abilities of Perceptrons: ...

Learning Abilities of Perceptrons: Conversely computational learning theory is the study of what concepts particular learning schemes as representation and method detail as a

What are interrupts, What are interrupts?  Interrupt: An interrupt i...

What are interrupts?  Interrupt: An interrupt is a hardware mechanism which enables an external device, classically input/output devices, to send a signal to the CPU. An int

Telematics, How are switching system classified

How are switching system classified

What are the types of assemblies, What are the Types of Assemblies? One...

What are the Types of Assemblies? One of the drawback of using Visual Studio.NET and the .NET framework to develop applications has been the lack of cross-platform support. As

Determine reduced boolean equation and the karnaugh map, Determine reduced ...

Determine reduced Boolean equation and the Karnaugh Map? Illustration : Determine reduced Boolean equation and the Karnaugh Map for the truth table shown below:

Graph to display the variable, We will be using data from the 2008 Canadian...

We will be using data from the 2008 Canadian General Election Study.1 The data can be found on the course page. As well, there are three other documents (loosely called "codebooks"

What do you mean by perfect shuffle permutation, Q. What do you mean by Per...

Q. What do you mean by Perfect Shuffle Permutation? Perfect Shuffle Permutation: It was proposed by Harold Stone (1971). Consider N objects each is represented by n bit number

Oo modelling, We might model such a scenario using three types of object: o...

We might model such a scenario using three types of object: one for Customers, one for BankAccounts and another for Transactions. In terms of data required, for Customers assume we

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