Consider the following segment taken from a C program: for ( j = 1; j <= 12; j++
ID: 3758168 • Letter: C
Question
Consider the following segment taken from a C program:
for ( j = 1; j <= 12; j++);
{
printf (“ nEnter an integer value: ”) ;
scanf (“%d”, &x) ;
if (x == 0)
y ( j ) = 0;
if (x != 0)
y ( j ) = 10 ;
}
Recode it so it will run more efficiently in a single-processor system.
Given that a multiprocessing environment with four symmetrical processors is available, recode the segment as an efficient concurrent program that performs the same function as the original C program.
Given that all processors have identical capabilities, compare the execution times of the original C segment with the execution times of your segments for parts (a) and (b).
Explanation / Answer
DO I = 1, 12
READ *,
X IF (X .EQ. 0)
THEN Y (I) = 0
ELSE Y(I) = 10
END IF
END DO
B)I = 1
DO J = 1, 3
READ *,
X(I),
X(I+1),
X(I+2),
X(I+3)
COBEGIN IF (X(I) .EQ. 0)
THEN Y(I) = 0
ELSE Y(I) = 10
END
IF IF (X(I+1) .EQ. 0)
THEN Y(I+1) = 0
ELSE Y(I+1) = 10
END
IF IF (X(I+2) .EQ. 0)
THEN Y(I+2) = 0
ELSE Y(I+2) = 10
END
IF IF (X(I+3) .EQ
THEN Y(I+3) = 0
ELSE Y(I+3) = 10
END