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

What is an i/o interface, What is an I/O Interface? Input-output interf...

What is an I/O Interface? Input-output interface provides a method for transferring binary information among internal storage, like memory and CPU registers, and external I/O d

Mac and llc, how can we improve the way LLC and MAC are used for LAN operat...

how can we improve the way LLC and MAC are used for LAN operation.?

Determine the nand gate, Find out the two inputs when the NAND gate output ...

Find out the two inputs when the NAND gate output will be low. Ans. The output of NAND gate will be low if the two inputs are 11. The Truth Table of NAND gate is shown

What is event-based simulator, Event-based Simulator Digital  Logic  S...

Event-based Simulator Digital  Logic  Simulation  method  sacrifices  performance  for  rich  functionality:  each active signal  is  calculated  for  every  device  it  propa

Differentiate between public key and secret key encryption, What are the di...

What are the different between Public Key Encryption and Secret Key Encryption? Differentiate between Public Key Encryption and Secret Key Encryption: A cryptographic sys

#title.sequential circuit, design modulo 12 up synchronous counter using t ...

design modulo 12 up synchronous counter using t flip flop

Electrochemistry and batteries, differentiate between concentration cells a...

differentiate between concentration cells and electrolytic cells with suitable examples?

Pros and cons of assembly language, Pros and Cons of Assembly Language ...

Pros and Cons of Assembly Language The following are a number of advantages / disadvantages of employing assembly language: Assembly Language offers more control over ha

Explain the term - strong typing and weak typing, Explain the term - Strong...

Explain the term - Strong Typing and  Weak Typing Strong Typing : When any operation upon an object can be checked during compile time, when type is confirmed forcefully.

Direct or random access of elements, Direct or random access of elements is...

Direct or random access of elements is not possible in:- In Linked list direct or random access of elements is not possible

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