Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please as fast as you can. Under 30minutes The application to implement a parallel program based on the search algorithm for a number J to

Please as fast as you can. Under 30minutes

The application to implement a parallel program based on the search algorithm for a number J to be valid the relation F(J) = C within an interval [A,B]. Calculate all J numbers in the interval [50000,550000], print them and also print their sum. To implement the use of MPI and OMP. Assume you have 20 computers available, each computer having 4 processor cores.

# include # include # include

int main ( ); int search ( int a, int b, int c ); int f ( int i ); void timestamp ( void ); double cpu_time ( void );

int main ( ) { int a; int b; int c; int fj; int i4_huge = 2147483647; int j; double wtime;

a = 1; b = i4_huge; c = 45;

timestamp ( ); printf ( " " ); printf ( "SEARCH_SERIAL: " ); printf ( " C version " ); printf ( " Search the integers from A to B " ); printf ( " for a value J such that F(J) = C. " ); printf ( " " ); printf ( " A = %d ", a ); printf ( " B = %d ", b ); printf ( " C = %d ", c );

wtime = cpu_time ( );

j = search ( a, b, c );

wtime = cpu_time ( ) - wtime;

if ( j == -1 ) { printf ( " " ); printf ( " No solution was found. " ); } else { printf ( " " ); printf ( " Found J = %d ", j ); printf ( " Verify F(J) = %d ", f ( j ) ); }

printf ( " Elapsed CPU time is %g ", wtime ); /* Terminate. */ printf ( " " ); printf ( "SEARCH_SERIAL: " ); printf ( " Normal end of execution. " ); printf ( " " ); timestamp ( );

return 0; } /******************************************************************************/

int search ( int a, int b, int c )

/******************************************************************************/ /* Purpose:

SEARCH searches integers in [A,B] for a J so that F(J) = C.

Parameters:

Input, int A, B, the search range.

Input, int C, the desired function value.

Output, int SEARCH, the computed solution, or -1 if no solution was found. */ { int fi; int i; int j;

j = -1;

for ( i = a; i <= b; i++ ) { fi = f ( i );

if ( fi == c ) { j = i; break; } }

return j; } /******************************************************************************/

int f ( int i )

/******************************************************************************/ /* Purpose:

F is the function we are analyzing.

Parameters:

Input, int I, the argument.

Input, int F, the value. */ { int i4_huge = 2147483647; int j; int k; int value;

value = i;

for ( j = 1; j <= 5; j++ ) { k = value / 127773;

value = 16807 * ( value - k * 127773 ) - k * 2836;

if ( value <= 0 ) { value = value + i4_huge; } }

return value; } /******************************************************************************/

void timestamp ( void )

/******************************************************************************/ /* Purpose:

TIMESTAMP prints the current YMDHMS date as a time stamp.

Example:

31 May 2001 09:45:54 AM

Parameters:

None */ { # define TIME_SIZE 40

static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now;

now = time ( NULL ); tm = localtime ( &now );

strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm );

printf ( "%s ", time_buffer );

return; # undef TIME_SIZE } /******************************************************************************/

double cpu_time ( void )

/******************************************************************************/ /* Purpose:

CPU_TIME returns the current reading on the CPU clock.

Discussion:

The CPU time measurements available through this routine are often not very accurate. In some cases, the accuracy is no better than a hundredth of a second.

Parameters:

Output, double CPU_TIME, the current reading of the CPU clock, in seconds. */ { double value;

value = ( double ) clock ( ) / ( double ) CLOCKS_PER_SEC;

return value; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions