Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. For the following program we always get the same output. #include sequent.h #include int *x; void f() { x[0] += 2; printf(x = %d

1. For the following program we always get the same output.

#include "sequent.h"

#include

int *x;

void f()

{

x[0] += 2;

printf("x = %d ", x[0]);

}

int main()

{

initialize();

x = (int *)shmalloc(sizeof(int));

x[0] = 0;

m_set_procs(3);

m_fork(f);

m_kill_procs();

clean();

return 0;

}

Question 1 options:

True
False

2.

In the following program, if we change strlen(greeting)+1 to strlen(greeting)+2 do we always get the same output?

//File name: a.c

#include

#include

#include

const int MAX_STRING = 100;

int main(void)

{

char greeting[MAX_STRING];

int comm_sz;

int my_rank;

int q;

MPI_Init(NULL, NULL);

MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);

MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

if (my_rank != 0)

{

sprintf (greeting, "Greetings from process %d of %d!", my_rank, comm_sz);

MPI_Send(greeting, strlen(greeting)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);

}

else

{

printf("From myself: Greetings process %d of %d! ", my_rank, comm_sz);

for (q = 1; q < comm_sz; q++)

{

MPI_Recv(greeting, MAX_STRING, MPI_CHAR, q, 0,MPI_COMM_WORLD, MPI_STATUS_IGNORE);

printf("Receiving from others: %s ", greeting);

}

}

MPI_Finalize();

return 0;

}

Question 2 options:

True
False

3.

Consider the following program:

#include #include int main(void) { int comm_sz, my_rank, index = 0; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); index++; printf("index = %d ", index); MPI_Finalize(); return 0; }

When we run this program with:

mpiexec -n 3 ./a.out

Its output always is:

index = 1 index = 1 index = 1

Question 3 options:

True
False

4.

For the following program we need to guard: x[i] += 2 with m_lock() and m_unlock().

#include "sequent.h"

#include

char *x;

void f()

{

int i = m_get_myid();

x[i] += 2;

printf("x = %c ", x[i]);

}

int main()

{

initialize();

x = (char *)shmalloc(2 * sizeof(int));

x[0] = 'M';

x[1] = 'N';

m_set_procs(2);

m_fork(f);

m_kill_procs();

clean();

return 0;

}

Question 4 options:

True
False

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

Students also viewed these Databases questions