Runtime Library Routines

FIND A SOLUTION AT Academic Writers Bay

Open MPRuntime Library RoutinesRuntime Library Routines• The OpenMP standard defines an API for library calls that perform a variety offunctions:•• Query the number of threads/processors, set number of threads to use• General purpose locking routines (semaphores)• Portable wall clock timing routines• Set execution environment functions: nested parallelism, dynamic adjustment of threads• It will be necessary to specify the include file “omp.h“• We will look at some of the more commonly used routinesomp_get_wtimePurpose:• Provides a portable wall clock timing routine• Returns a double-precision floating point value equal to the number of elapsed seconds since some point in the past• Used in “pairs” with the value of the first call subtracted from the value of the second call to obtain the elapsed time• Designed to be “per thread” times, and therefore may not be globally consistent across all threads in a team – depends uponwhat a thread is doing compared to other threadsFormat:Notes & Restrictions:• Requires OpenMP version 2.0 support#include <omp.h>double omp_get_wtime (void)omp_set_num_threadsPurpose:• Sets the number of threads that will beused in the next parallel region• Must be a positive integerFormat:Notes & Restrictions:• The dynamic threads mechanismmodifies the effect of this routine in one oftwo ways:• Enabled: specifies the maximum number ofthreads that can be used for any parallelregion by the dynamic threads mechanism• Disabled: specifies exact number of threadsto use until next call to this routine• This routine can only be called from theserial portions of the code#include <omp.h>void omp_set_num_threads(int num_threads)omp_get_num_threadsPurpose:• Returns the number of threads that are currently in the team executing the parallel regionfrom which it is calledFormat:Notes & Restrictions:• If this call is made from a serial portion of the program, or a nested parallel region that isserialized, it will return 1• The default number of threads is implementation dependent#include <omp.h>int omp_get_num_threads(void)omp_get_thread_numPurpose:• Returns the thread number of the thread, within the team, making this call• This number is between 0 and omp_get_num_threads()-1• The master thread of the team is thread 0Format:Notes & Restrictions:• If called from a nested parallel region, or a serial region, this function will return 0#include <omp.h>int omp_get_thread_num (void)omp_get_thread_num ExampleThis example illustrates the use of the omp_get_thread_num routine…• Without specifying tid as private this would result in incorrect execution – how?• What if line 8 was inserted in line 5 instead?1 #include <omp.h>2 3
main ()int
tid;
4 5 6#pragma omp parallel private(tid)78 tid=omp_get_thread_num();9 printf(“Hello world from thread %dn”,tid);1011omp_set_dynamicPurpose:• Enables or disables dynamic adjustment (by the run time system) of the number of threads availablefor execution of parallel regions•Format:Notes & Restrictions:• If dynamic_threads evaluates to non-zero, then the mechanism is enabled, otherwise it is disabled• The omp_set_dynamic routine has precedence over the omp_dynamic environment variable• The default setting is implementation dependent• Must be called from a serial section of the program#include <omp.h>void omp_set_dynamic (int dynamic_threads)omp_get_dynamicPurpose:• Used to determine if dynamic thread adjustment is enabled or disabledFormat:Notes & Restrictions:• non-zero will be returned if dynamic thread adjustment is enabled, and zero otherwise#include <omp.h>int omp_get_dynamic (void)

Order from Academic Writers Bay
Best Custom Essay Writing Services

QUALITY: 100% ORIGINAL PAPERNO PLAGIARISM – CUSTOM PAPER