DESCRIPTION Students: Please note instructions in paper copy of quiz. Save your files often, make sure OMSI fills your entire screen at all times, etc. A question may not fully fit into your OMSI question box, which is not scrollable. You can try adjusting the relative size of the question and answer boxes, but remember that clicking CopyQtoA will copy the entire question box to the answer box. QUESTION Consider the pthreads example, pp.8ff. Each thread is handling only one value of 'nextbase' at a time. Say we define a global variable 'nbinc', set in 'main()'. This variable will replace the 2 in line 49, so as to increase the granularity. We will then need to slightly modify lines 52-59. Show how to do this. They currently are if (base <= lim) { if (prime[base]) { crossout(base); work++; } } else return work; QUESTION Consider the pthreads example, pp.8ff. Suppose I run it under gdb, with n and nthreads equal to 100 and 2, and set a breakpoint at line 49. I then use gdb's thread command to switch to some other thread. I will then be informed as to what line that thread is currently executing. Give the line number(s) that are likely to be indicated. Note that there will be three threads in all, including the one for main(). QUESTION Consider the following R code: x <- c(5,12,13) y <- x y[2] <- 88 x <- y State how many words of memory will be written, and state the name of the relevant R policy. QUESTION -ext .R -run 'Rscript ./omsi_answer4.R' Write a "Snow" function with call form maxpar(cls,x) that will parallelize R's 'max()' function. The latter does e.g. > max(5,2) [1] 5 > max(c(5,12,13,8)) [1] 13 The arguments in 'maxpar()' will be the "Snow" cluster and the input vector. Following is partial code, with some lines omitted, as well as free-standing test code. (You may alter those lines if you wish, but you must comply with the specified call form, and must leave the test code intact.) Hit CopyQtoA. maxpar <- function(cls,x) { require(parallel) clusterExport(cls,'x',envir=environment()) maxidxgrp <- function(igrp) max(x[igrp]) } library(parallel) cls <- makeCluster(2) z <- c(5,2,1,22,6,8,9) print(maxpar(cls,z))