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

Write the factors considered in designing an i/o subsystem, Write the facto...

Write the factors considered in designing an I/O subsystem? 1.  Data Location: Device selection, address of data within device ( track, sector etc) 2.  Data transfer: Amount

Determine by which final selector is connected, The final selector is conne...

The final selector is connected to the (A) calling subscriber.                     (B) switching network. (C) called subscriber.                      (D) li

Advantage and disadvantage of threaded binary trees, Advantage  1.     ...

Advantage  1.       By doing threading we neglect the recursive method of traversing a Tree , which makes use of stack and consumes many memory and time . 2.       The node

BCD ADDER, create a BCD adder combinational ckt. that adds 2 digit BCD inpu...

create a BCD adder combinational ckt. that adds 2 digit BCD inputs

Security, We now consider the relation between passwords and key size. For ...

We now consider the relation between passwords and key size. For this purpose consider a cryptosystem where the user enters a key in the form of a password. Assume a password consi

Calculate grade of service in a particular excahange, In a particular excha...

In a particular exchange during busy hour 1200 calls were offered to a group of trunks, during this time 6 calls were lost. The average call duration being 3 minutes Calculate

Direct mapped cache - computer architecture, Direct Mapping: In this p...

Direct Mapping: In this particular technique, block j of the primary memory maps onto block j modulo 128 of the cache. The primary memory blocks 0,128,256,...is loaded

Deductive inferences - artificial intelligence, Deductive Inferences - Arti...

Deductive Inferences - Artificial intelligence: We have described how knowledge can be represented in first-order logic, and how in logic rule-based expert systems expressed ca

How does tcp achieve reliability, How does TCP achieve reliability? One...

How does TCP achieve reliability? One of the most significant technologies is retransmission. While TCP stands data the sender compensates for packet loss through implementing

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