Shubert.c # include # include # include # include // Prototype for computation double shubert(double x1, double x2); int main () { double x1, x2,
Shubert.c
# include
// Prototype for computation double shubert(double x1, double x2);
int main () { double x1, x2, y, min = 0; struct timeval start_time, stop_time, elapsed_time; // timers gettimeofday(&start_time,NULL); // Unix timer // Loops for (x1 = -2; x1
// Compute Shubert value for x1,x2 combination double shubert(double x1, double x2) { double sum1 = 0; double sum2 = 0; int i; for (i = 1; i
shuared_double.c
#include
int main() { const char *name = "Double Example"; const int SIZE = sizeof(double);
int shm_fd; double *ptr; // Pointer to shared memory
/* create the shared memory segment */ shm_fd = shm_open(name, O_CREAT | O_RDWR, 0666);
/* configure the size of the shared memory segment */ ftruncate(shm_fd, SIZE);
/* now map the shared memory segment in the address space of the process */ ptr = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); if (ptr == MAP_FAILED) { printf("Map failed "); return -1; }
/* store and read from the shared memory region */ *ptr = 3.14; printf("%f ", *ptr);
/* remove the shared memory segment */ if (shm_unlink(name) == -1) { printf("Error removing %s ", name); exit(-1); }
return 0; }
The program "shubert.c" demonstrates the use of the Shubert function, which is a test case for optimization algorithms (see Appendix). Using two processes and the communication methods below print the minimum values (local and global) of the Shubert function for -2.0Sxlx22.0 and the run time of the parent/server. Use a step size for both loops to yield a run time of at least I second. Compare your run time to that of the sample program using the same step size. Each process should perform an equal amount of work to find a local minimum in its range. For example, one process can do half of the xl values (-2.0 to 0.0), and the other process can to the other half. You don't need to modify the other loop. The parent process can determine which of the two local minima is the least and print it as the global minimum Include the output in your report for each of the three programs and the sample program (shubert.c) using appropriate step size. Below is an example of output for one program: Total time was 10.65 seconds. Local min -62.12412 Local min-186.73064 Global min -186.73064 a. Create a single program that uses fork0 and shared memory. Tip: you can create shared memory witlh a value of type double and access the value using the dereference operator *. The program "shared_double.c" is provided as an example b. Create a single program that uses fork0 and a pipe. c. Create a either a single program or separate programs that use(s) a socket. Tip: there are two ways you can work with the double value. One way is to use an array of doubles with only one value. Another way is to declare a regular double and use the addressof operator & for read0 and writeC ppendix: The Shubert function The program "shubert.c" demonstrates the use of the Shubert function, which is a test case for optimization algorithms (see Appendix). Using two processes and the communication methods below print the minimum values (local and global) of the Shubert function for -2.0Sxlx22.0 and the run time of the parent/server. Use a step size for both loops to yield a run time of at least I second. Compare your run time to that of the sample program using the same step size. Each process should perform an equal amount of work to find a local minimum in its range. For example, one process can do half of the xl values (-2.0 to 0.0), and the other process can to the other half. You don't need to modify the other loop. The parent process can determine which of the two local minima is the least and print it as the global minimum Include the output in your report for each of the three programs and the sample program (shubert.c) using appropriate step size. Below is an example of output for one program: Total time was 10.65 seconds. Local min -62.12412 Local min-186.73064 Global min -186.73064 a. Create a single program that uses fork0 and shared memory. Tip: you can create shared memory witlh a value of type double and access the value using the dereference operator *. The program "shared_double.c" is provided as an example b. Create a single program that uses fork0 and a pipe. c. Create a either a single program or separate programs that use(s) a socket. Tip: there are two ways you can work with the double value. One way is to use an array of doubles with only one value. Another way is to declare a regular double and use the addressof operator & for read0 and writeC ppendix: The Shubert functionStep by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started