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 is the significance timescale directive, What is the significance Time...

What is the significance Timescale directive? Defines time units and simulation precision (smallest increment). Syntax 'timescale TimeUnit / PrecisionUnit TimeUnit =

Define the internal users of system, Q. Define the Internal Users of system...

Q. Define the Internal Users of system? Internal Users are employees of business for that an information system is built. Illustration are clerical and service staff, technic

Hardware implementation for signed-magnitude data, Hardware Implementation ...

Hardware Implementation for signed-magnitude data When multiplication  is  implemented  in  digital  computer,  we  change  process lightly. Here, in place of providing registe

Example of calculate maximum access time & cost of switch, Calculate the ma...

Calculate the maximum access time that can be permitted for the data and control memories in a TSI switch with a single input and single output trunk multiplexing 2500 channels. Al

Simplify following using k-map, Q. Explain XNOR gate with three input varia...

Q. Explain XNOR gate with three input variable and draw necessary circuits. Q. Simplify FOLLOWING Using K-Map 1. m0 + m1 + m6 + m7 + m12 + m13 + m8 + m9 2. m0 + m2 + m4 +

NETWORK ADMIN, Ask qDiscuss the risks of having a single root user and how ...

Ask qDiscuss the risks of having a single root user and how more limited management abilities can be given to others users on Linux/UNIX systems.uestion #Minimum 100 words accepted

Write a menu driven program to perform addition, Q. Write a menu driven pr...

Q. Write a menu driven program to perform addition and subtraction in base 5. Check that entered numbers are in base 5 or not else error message should be displayed.

Loop statement in both the pbo and pai events, Why do we need to code a LOO...

Why do we need to code a LOOP statement in both the PBO and PAI events for each table in the screen? We require coding a LOOP statement in both PBO and PAI events for every ta

Luminous Jewels - The Polishing Game, Byteland county is very famous for lu...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

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