Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Files I already have .. 1) X11Macros.h // set up and initialization macro for X1

ID: 3667495 • Letter: F

Question

Files I already have ..

1) X11Macros.h

// set up and initialization macro for X11 graphics. B. Wilkinson June 1, 2015

// x_resn, y_resn are the resolutions in x and y direction provided by programmer

#include        // X11 library headers

#include

#include

#define initX11(x_resn,y_resn)

Window       win;

unsigned int width, height,win_x,win_y,border_width,display_width, display_height,screen;

char       *window_name = "N-body with X11 graphics, Nbody-G.c", *display_name = NULL;

GC       gc;

unsigned long   valuemask = 0;

XGCValues   values;

Display       *display;

XSizeHints   size_hints;

Pixmap       bitmap;

XPoint       points[800];

XSetWindowAttributes attr[1];

if ((display = XOpenDisplay (display_name)) == NULL ) {

   fprintf (stderr, "drawon: cannot connect to X server %s ",XDisplayName (display_name) );

   exit (-1);

}

screen = DefaultScreen (display);

display_width = DisplayWidth (display, screen);

display_height = DisplayHeight (display, screen);

width = x_resn;

height = y_resn;

win_x = 0;

win_y = 0;

border_width = 4;

win = XCreateSimpleWindow (display, RootWindow (display, screen),win_x, win_y, width, height, border_width,BlackPixel (display, screen), WhitePixel(display, screen));

size_hints.flags = USPosition|USSize;

size_hints.x = win_x;

size_hints.y = win_y;

size_hints.width = width;

size_hints.height = height;

size_hints.min_width = 300;

size_hints.min_height = 300;

XSetNormalHints (display, win, &size_hints);

XStoreName(display, win, window_name);

gc = XCreateGC (display, win, valuemask, &values);

XSetBackground (display, gc, WhitePixel (display, screen));

XSetForeground (display, gc, BlackPixel (display, screen));

XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound);

attr[0].backing_store = Always;

attr[0].backing_planes = 1;

attr[0].backing_pixel = BlackPixel(display, screen);

XChangeWindowAttributes(display, win, CWBackingStore | CWBackingPlanes | CWBackingPixel, attr);

XMapWindow (display, win);

XSync(display, 0);

usleep(1000)

#define BLACK (long) 0x000000

#define BLUE (long) 0x0000FF

#define BROWN (long) 0xA52A2A

#define CYAN (long) 0x00FFFF

#define GRAY (long) 0xBEBEBE

#define GREEN (long) 0x00FF00

#define MAGENTA (long) 0xFF00FF

#define ORANGE (long) 0xFFA500

#define PINK (long) 0xFFC0CB

#define PURPLE (long) 0xA020F0

#define RED (long) 0xFF0000

#define TURQUOISE (long) 0x40E0D0

#define VIOLET (long) 0xEE82EE

#define WHITE (long) 0xFFFFFF

#define YELLOW (long) 0xFFFF00

2) matrixmult.c

#include
#include
#include
#include "X11Macros.h"       // X11 macros graphics

#define X_RESN   800    // x resolution // graphics
#define Y_RESN   800    // y resolution // graphics

void getIn(int*, int*);

void main(int arc, char* argv) {

omp_set_num_threads(4);

double b,e;

double seq_time, par_time;

int ite, i, j, c, nex, N, T,x,y;

getIn(&N, &T);

//initaialize the array

double h[2][N][N];

double g[2][N][N];

// Initialize both arrays 0s

for (i = 0; i < N; i++) {

for (j = 0; j < N; j++) {

h[0][i][j] = 0;

h[1][i][j] = 0;

g[0][i][j] = 0;

g[1][i][j] = 0;

}

}

// Set all the walls to 20C degrees

for(i = 0; i < N; i++) {

h[0][0][i] = 20.0;

h[0][i][0] = 20.0;

h[0][N-1][i] = 20.0;

h[0][i][N-1] = 20.0;

g[0][0][i] = 20.0;

g[0][i][0] = 20.0;

g[0][N-1][i] = 20.0;

g[0][i][N-1] = 20.0;

}

// Set the starting point and the ending point of the fireplace

double fp_start, fp_end;

fp_start = 0.3 * N;

fp_end = (0.7 * N);

// Initialize the values of the location of the fireplacee to 100C

for(i = fp_start; i < fp_end; i++) {

h[0][0][i] = 100.0;

g[0][0][i] = 100.0;

}

// start time

b = omp_get_wtime();

//Sequential

c = 0;

nex = 1;

for (ite = 0; ite < T; ite++) {

for( i = 1; i < N-1; i++) {

for( j = 1; j < N-1; j++) {

h[nex][i][j] = 0.25 * (h[c][i-1][j] + h[c][i+1][j] + h[c][i][j-1] + h[c][i][j+1]);

}

}

c = nex;

nex = (c + 1) % 2;

}

// Calculate time spent comment out start here

e = omp_get_wtime();

seq_time = e-b;

// Sequential Array printing

printf(" Sequential Execution ");

for(i = 0; i < N; i+= N/10) {

for(j = 0; j < N; j+= N/10) {

printf("%06.2f ", h[c][i][j]);

}

printf(" ");

}

printf(" ");

//Parallel

b = omp_get_wtime();

for (ite = 0; ite < T; ite++) {

#pragma omp parallel for private(i, j)

for( i = 1; i < N-1; i++) {

for( j = 1; j < N-1; j++) {

g[nex][i][j] = 0.25 * (g[c][i-1][j] + g[c][i+1][j]+ g[c][i][j-1] + g[c][i][j+1]);

}

}

c = nex;

nex = (c + 1) % 2;

}

// Calculate the time spent

e = omp_get_wtime();

par_time = e - b;

// Print the array after Parallel computing
  
printf(" Parallel Execution ");

for(i = 0; i < N; i+= N/10) {

for(j = 0; j < N; j+= N/10) {

printf("%06.2f ", g[0][i][j]);

}

printf(" ");

}

printf(" ");

// Check to see if the two arrays match

for(i = 0; i < N; i++) {

for(j = 0; j < N; j++) {

if(g[0][i][j] != h[c][i][j]) {

printf("2 arrays do not match ");

exit(1);

}

}

}

// Print the time in seconds that the program took to run

printf("Parallel: %f Sequential: %f Difference: %f ", par_time, seq_time, seq_time - par_time);

printf("Speedup factor: %f ", seq_time/par_time);

/* --------------------------- X11 graphics setup ------------------------------ */

   initX11(X_RESN,Y_RESN);

/* ----- End of X11 graphics setup, continue with application code, sample given here ----- */

for (x = 0; x < 800; x = x+50) {

y=x;

   XClearWindow(display, win);                 // clear window for next drawing
   XSetForeground(display,gc,(long) 0xDC143C);         // color of foreground (applies to object to be drawn)

   XDrawPoint (display, win, gc, x, y);            // draw point at location x, y in window
                          
   XFillArc (display,win,gc,x-25,x-25,50,50,0,23040);   // draw circle of size 50x50 at location (x,y)
                               // X11 parameters specify upper-left corner of bounding rectangle.

  
   XFlush(display);                   // necessary to write to display
  
   usleep(10000000);                       // provide a delay beween each drawing

}

  
}

void getIn(int* N, int* T) {

// Get the size of the matrix

int valid = 0;

while(!valid) {

printf("Please enter matrix size(NxN): ");

scanf("%d", N);

if(N) {

valid = 1;

}

}

// Get the number of iterations

valid = 0;

while(!valid) {

printf("Please enter the number of iterations: ");

scanf("%d", T);

if(N) {

valid = 1;

}

}

}

I need help with Task 3 parts b&c

Assignment 2 Second OpenMP Programming Assignment B. Wilkinson: Modification date February 2. 2016 Overview In this assignment, you will arite and evecute your own OpenMP program to model the static heat distrbution of a room with a fireplace (two dimensions only)using the stencil patterm. You are also asked to generate Xl1 graphical output and sample X11 code is provided All the programming and testing will be done on your own conmputer (VirtualBox or a native Linus installation) Heat Distribution (Static Heat Equation) The obiective is to write an OpenP program that will model the staric heat distribution of a room with a fireplace (where the heat source temperatures do not vary with time) using a stencil Although a room is 3-dimensional we will be modeling the room in two dimensions. room is 10 feet wide and 10 feet long with a fireplace along one wall as depicted in Figure 1. 20°C 2ft 100°C 10ft 10ft Figure I: 10 xI0 Room with a Firaplace The fireplace is 2 feet wide and is centered along one wall (it takes up 20% of the wall, with 40% of the walls on either side). The fireplace emits 100° C of heat (although in reality a fire is much hotter)The walls are considered to be at 20° C. The boundary values (the fireplace and the walls) are considered to be fixed temperatures.

Explanation / Answer

I do not understand this question...sorry i am not givng the answer

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote