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

Explain about the passive graphics device, Explain about the passive graphi...

Explain about the passive graphics device A passive graphics device simply draws pictures under computer control; i.e. it allows the computer to communicate graphically with th

Write an algorithm for deadlock detection, Write an algorithm for deadlock ...

Write an algorithm for deadlock detection. An algorithm for deadlock detection: 1. Assume that Work and Finish be vectors of length m and n, correspondingly. Initialize:

Define edge triggered d flip flop, Define Edge Triggered D flip-flop? D...

Define Edge Triggered D flip-flop? D latch has only two inputs C(control) and D(data). The operation of a D flip-flop is a lot simpler and it has only one input addition to the

Instruction queue in bus interface unit, Q. Instruction Queue in Bus Interf...

Q. Instruction Queue in Bus Interface Unit? Instruction queue is employed to store the instruction ‘bytes' fetched. Please conceren two points here: that it's (1) A Byte (2) Qu

Queue, write a program insert and remove value in queue.

write a program insert and remove value in queue.

Show data representation for computation, Binary codes exist for any fundam...

Binary codes exist for any fundamental representation. Binary codes can be created for any set of discrete elements for example colors, spectrum, musical notes, chessboard position

What is busy hour traffic, Busy hour traffic is the (A)  maximum avera...

Busy hour traffic is the (A)  maximum average simultaneous traffic. (B)  traffic during peak hour. (C)  traffic when all subscribers are engaged. (D)  the durat

Hiring problem algorithm, Consider the Hire Assistant problem. We interview...

Consider the Hire Assistant problem. We interview n candidates and always hire the best qualified so far. Let n = 5 for our example. Find the probabilities that we hire exactly 1 t

Limitation identified in amdahls law, Q. Limitation identified in Amdahls l...

Q. Limitation identified in Amdahls law? There is one main limitation identified in Amdahl's law. As said by Amdahl's law workload or problem size is forever fixed as well as n

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