Subash Kumar Rawat - 230155 - WPS02
Subash Kumar Rawat - 230155 - WPS02
Subash Kumar Rawat - 230155 - WPS02
Overview
The aim of this workshop is to build on the previous workshop with MPI and to carry out an assessed task.
You can carry out this workshop either the university servers: thinlinc.wlv.ac.uk or your own Linux system
(if you prefer to use Putty to log in instead of the Thinlinc client, connect to the server tl-01.wlv.ac.uk
instead). Tasks
1. The following C program sums up all the values in array "data" and displays the sum total.:
#include <stdio.h>
Convert it to MPI to run with any number of nodes including just one.
2. Write an MPI program called pingpong.c to run with exactly 2 processes. Process rank 0 is to send an integer
variable called "ball" initialised with the value zero to Process rank 1. Process rank 1 will add 1 to the ball and
send it back. This will repeat until the ball has a value of 10 in Process rank 0.
Ans
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h> #define
NUMDATA 1000
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
Modify it so that it doesn't use a fixed size data buffer but uses "malloc()" to allocate the correct amount
of memory to use every time. Note this means that Process rank 0 will need to know what the amount of
data it is expecting before it receives it. Ans:
Your MPI program should work with any number of processes from 1 to 100 processes. Only Process rank 0
(zero) should read in the file and send the appropriate chunk of file to each other process. The other processes
should not read in the file.
You should submit this program as "workshoptask1.c" as part of your final portfolio submission. You can also
upload it to the formative submission point for formative feedback.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "mpi.h"
#define ALPHABET_SIZE 26
MPI_File mpi_file;
MPI_File_open(MPI_COMM_WORLD, "WarAndPeace.txt", MPI_MODE_RDONLY, MPI_INFO_NULL,
&mpi_file);
MPI_File_set_view(mpi_file, process_rank * portionsize, MPI_CHAR, MPI_CHAR, "native",
MPI_INFO_NULL);
MPI_File_read_all(mpi_file, portionsizes_ptr, portionsize, MPI_CHAR,
MPI_STATUS_IGNORE);
MPI_File_close(&mpi_file);
// Cleanup
free(portionsizes_ptr);
free(counts_ptr); if (process_rank
== 0) fclose(file);
MPI_Finalize();
return 0;
}