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

Identify the number of control lines for 16 to 1 multiplexer, The number of...

The number of control lines for 16 to 1 multiplexer is ? Ans. We have 16 = 2 4 , 4 Select lines are needed.

.bus, clasification of bus

clasification of bus

Comparator, 6 bit magnitude comparator

6 bit magnitude comparator

What is independent process, What is independent process? A process is ...

What is independent process? A process is independent it cannot affect or be affected by the other processes implementing in the system. Any process does not share data with ot

Define bcd, Define BCD. A binary code that distinguishes between 10 ele...

Define BCD. A binary code that distinguishes between 10 elements must contain at least 4 bits, but 6 combinations will remain unassigned. Numerous dissimilar codes can be obtai

Explain vector-vector instructions, Vector-Vector Instructions In this...

Vector-Vector Instructions In this category, vector operands are fetched from vector register and accumulated in another vector register. These instructions are indicated with

Analysts in computer operations, Q. Analysts in Computer Operations? Co...

Q. Analysts in Computer Operations? Computer Operations: All of the shared computers comprising mainframes, minicomputers and other computers are put to operation and same is c

What do you mean by numbering and addressing, What do you mean by numbering...

What do you mean by numbering and addressing? Numbering and Addressing: In data networks and telephone, the end equipments are more frequently single units than multiple dev

What is serialization, What is serialization, how it works in .NET? Ser...

What is serialization, how it works in .NET? Serialization is when you persist the state of an object to a storage medium so an exact copy can be re-created at a later stage. S

By which digits are represented, In a DTMF phone, digits are represented by...

In a DTMF phone, digits are represented by: (A)  Orthogonal frequencies. (B)  Orthogonal Phases. (C)  Orthogonal codes. (D)  Orthogonal pulses. Ans: Di

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