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 layers are covered under end to end layer connectivity, What layers ar...

What layers are covered under end to end layer connectivity? The layers 4 to 7 of ISO-OSI reference model communicate along with peer entities into the end systems. There is n

Characteristics of decision support system, Q. Characteristics of decision ...

Q. Characteristics of decision support system? Characteristics of DSS- The qualities of the DSS are as follows: - 1. DSS focus on towards providing assistance in analyzing s

What is pure virtual function, A class is made abstract by declaring one or...

A class is made abstract by declaring one or more of its virtual functions to be pure. A pure virtual function is one with an initializer of = 0 in its declaration

Explain instruction cycle and execution cycle, Q Explain Instruction cycle ...

Q Explain Instruction cycle and Execution cycle. and also explain Instruction Counter, Memory Address Register and Memory Buffer Register.

Explain the term- tracker ball and braille printers, Explain the term- Trac...

Explain the term- Tracker ball and Braille printers Tracker ball Easier to use than a mouse if people have problems using their arms and hands or if they have a coordinati

What is macro, A series of keystrokes and mouse clicks that can be abbrevia...

A series of keystrokes and mouse clicks that can be abbreviated into a one keystroke or mouse click.

Determine frame time and propagation time in a lan, Maximum channel utiliza...

Maximum channel utilization in a LAN is defined by frame time (t f ) and propagation time (t p ). It is defined by (A) t p /t f (B) t f /t p  (C) 1 + (t f /t p )

What is downcasting in programming, Downcasting concept is the casting from...

Downcasting concept is the casting from a general to a more particular type, i.e. casting down the hierarchy in programming

Secondary memory and characteristics, It is desirable that operating speed ...

It is desirable that operating speed of primary storage of a computer system be as fast as possible since most of the data transfer to and from processing unit is via main memory.

Drawbacks to having call centres overseas, Drawbacks to having call centres...

Drawbacks to having call centres overseas -  Culture and language problems -  Animosity to overseas call centres (resulting in loss of customers) -  need for extensive r

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