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

Universal elimination, Universal Elimination: Here for any sentence, t...

Universal Elimination: Here for any sentence, there is A, containing a universally quantified variable, v, just for any ground term, g, so we can substitute g for v in A. Thus

Describe the vertical frequency or cycle, Q. Describe the Vertical Frequenc...

Q. Describe the Vertical Frequency or cycle? Like a Fluorescent lamp, the screen has to repeat same image many times per second to display an image to user. The frequency of th

Mapping design principle, The following definition of mapping is adapted fr...

The following definition of mapping is adapted from the first edition of the Set Book: Mapping concerns the relationship between controls and their effects in the world. Nearly al

Fundamental differences between risc and cisc architecture, Q. Fundamental ...

Q. Fundamental differences between RISC and CISC architecture? Fundamental differences between RISC and CISC architecture. The following table lists following differences:

How to fix an asic-based design from easiest to most extreme, How to fix an...

How to fix an ASIC-based design from easiest to most extreme? There are different ways to fix an ASIC-based design as given below: Initially, assume some reviews fundamentally.

Example on hamming error correcting code, Q. Example on hamming error corre...

Q. Example on hamming error correcting code? For illustration a 4-bit matching word can stand for 2 4 =16 values that range from 0 to 15 as: 0000, 0001, 0010, 0011, 0100, 01

VLSI implementation of control unit, Q. VLSI Implementation of Control Unit...

Q. VLSI Implementation of Control Unit? A main potential advantage of RISC is VLSI implementation of microprocessor. VLSI Technology has decreased the delays of transfer of inf

Write short notes on proton – proton fusion in sun, Q. Write short notes on...

Q. Write short notes on proton - proton fusion in sun. Proton - Proton cycle 1 H 1 + 1 H 1 → 1 H 2 + 1 e 0 + ν (emission of positron as well as neutrino) 1

What are the features of abap/4 dictionary, What are the features of ABAP/4...

What are the features of ABAP/4 Dictionary? The most significant features are: Integrated to aABAP/4 Development Workbench. Active in the runtime environment.

Illustrate cache dram, Q. Illustrate Cache DRAM? Cache DRAM (CDRAM) wh...

Q. Illustrate Cache DRAM? Cache DRAM (CDRAM) which is developed by Mitsubishi integrates a tiny SRAM cache (16Kb) on a generic DRAM chip. SRAM on the CDRAM can be used in two

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