Determine what part of global array to work on thread number, Computer Engineering

Assignment Help:

Q. Determine what part of global array to work on thread number?

#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:- Determine what part of global array to work on thread number

Compare single bus structure and multiple bus structure, Compare single bus...

Compare single bus structure and multiple bus structure? A system that having only one bus(i.e only one transfer at a time) is known as a single bus structure. A system is know

Internet application development, As an employee of an up and coming web De...

As an employee of an up and coming web Design Company, you have been approached by a small local cinema, called Valley Viewing who are looking to revamp their existing HTML website

#title., REPRESENTATION OF POYNOMIAL OF 2 OR MORE VARIABLES USING ARRAY

REPRESENTATION OF POYNOMIAL OF 2 OR MORE VARIABLES USING ARRAY

Identify specific weaknesses in the design, Identify three specific weaknes...

Identify three specific weaknesses in the design of the websites, derived from your analyses within Questions Part (c) and/or Question Part (a). There should be at least one weakne

Dynamic programming problem, KK manufacturing company is faced with demand ...

KK manufacturing company is faced with demand for its product in each of the next four periods as shown in Table 1.  It must decide upon a production schedule to meet these demands

Cookies for one page in your site, How do you turn off cookies for single p...

How do you turn off cookies for single page in your site? We can turn off the cookies for one page:- By setting the Cookie. Discard property false.

What is a PCI bus and discuss its aspects and usage, What is a PCI bus? Dis...

What is a PCI bus? Discuss its aspects and usage. Peripheral Component Interconnect (PCI): This bus was developed by Intel and introduced in 1993. It is geared specifically to

What is telnet, Telnet It is a terminal emulation program for TCP/IP ne...

Telnet It is a terminal emulation program for TCP/IP networks like as the Internet. The Telnet program runs on your computer and attaches your PC to a server on the network. On

Difference between shadow and override in programming, Overriding tell us o...

Overriding tell us only the methods, but shadowing tells us the entire element.

Explain the term internet, Explain the term Internet. Internet: ...

Explain the term Internet. Internet: The Internet, an umbrella term covering countless network and services that comprise a super-network, is a global network of compute

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