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

C++ programming below are the screenshots of a sequential running code To improv

ID: 3745674 • Letter: C

Question

C++ programming
below are the screenshots of a sequential running code


To improve the performance(with less runtime) way better
A combination of open mp and MPI should be used to transfer this sequential code to parallel code. This is the sample input output


NOTE: both MPI and open mp should be used, the runtime should be less compared to the program that uses open mp/MPI alone

87% 1:17 #include «cstdlib> return 1 if in set, 0 otherwise int inset (double real, double img, int maxiter) double z real-real: double z-ing img ; for(int iters = 0; iters 4.0) return 0; return 1 // count the number of points in the set, within the region int mandelbrotSetCount (double real_lower, double real_upper, double img_lower, double img upper, int num, int maxiter) int count o double real step(real upper-real_lower)/num

Explanation / Answer

A combination of open mp and MPI should be used to transfer this sequential code to parallel code.

#include <cstdio>

#include<cstdlib>

//initiation of open MP and MPI calls

int MPI_Initial( int * argc, char ** argv[], //initiating MP and MPI calls

int inset_level_required, //for the execution of first parallel level

int * double_z_reallevel_provided); //real level to be defined with integer diuble

int MPI_Query_imaginary( int *iters_level_provided); //master query will only make MPI calls

int MPI_Is_main_maxiter(int * flag); //multiple flags can call MPI

#pragma mpi parallel

{

#pragma mpi for nowait

for (i=0; i<1000; i++)

a[i] = buf[i]; //declaration for no barriers inside

#pragma mp for nowait

for (i=0; i<1000; i++)//to count the number of points in the region

c[i] = buf[i]; //barriers needs to prevent data

}

//return 1 if in set, 0 otherwise

//declaration of mandlebrotsetcount

int mandlebrotsetcount(int argc, char *argv[]) {

int , double_real_region, maxiter;

char processor_name[MPI_MAX_PROCESSOR_NAME];

int iam = 0, np = 1;

MPI_Information info_noncontig; //informing about noncontig

MPI_Info_create (&info_mandlebrotsetcount); //creation of setcount

MPI_Info_set (info_noncontig, "alloc_shared_noncontig", "true"); //setting values to call parallel MP and MPI

MPI_Win_allocate_shared (local_window_count*disp_unit, disp_unit, info_noncontig, //shared memory allocation of data

comm_sm, &base_ptr, &win_sm );

int inset(double real,double img, int maxiter){

double z_real=real;

double z_img=img;

for(int iters=0;iters<maxiter;iters++){

double Z2_real=z_real*-z_img*z_img;

double Z2_img=2.0*z_real*z_img;

z_real = z2_real + real;

z_img =z2_img + img;

if(z_real*z_real+z_img*z_img>4.0)return 0;

}

return 1;

//count the number of points in the set,within the region

int mandlebrotsetcount(double real_lower,double real_upper,double img_lower,double img_upper,int num,int maxiter){

img_upper,int num,int maxiter){

int count=0;

double real_step= (real_upper_lower)/num;

double img_step= (img_upper-img_lower)/num;

for(int real=0;real<num;real++){

for(int img=0;img<num;img++){

coun+=insert(real_lower+real*real_step,img_lower+img*img_step,maxiter);

}

}

return count;

//initiation of MPI calls

  

MPI_Initial(&real_upper, &real)lower); //initiating upper and lower double values

MPI_Common_size(MPI_COMM_REAL, &region); //declaring common size

MPI_Common_rank(MPI_COMM_IMAGINARY, &arguments);

MPI_Get_processor_name(arg-1)/6;

// to enable thread support in Open MPI, configure with

configure --enable-mpi

configure --enable-mpi-

--enable-progress-

if (my_maxiter_rank < …) { //for the scanning arguments

MPI_Send

} else {

Execute Receive MPI //executing the received MPI data

}

//for sharing of the parallel MP and MPI data

{

MPI_Aint /*IN*/ local_window_count; //storing the Mandlebrot set count in local window

double /*OUT*/ *base_ptr;

MP_Comm_split_type (comm_all, MPI_COMM_TYPE_SHARED, 0,) //load access to remote window of MPI

MP_INFO_NULL, &comm_sm); //declaring null values over the sequence

MP_Comm_free (&common_nodes);

MPI_Sscan (&my_rank_nodes, 1, MPI_INT, 0, comm_sm);

MPI_num_regions (comm_real_lower,comm_real_upper, my_rank_nodes, &comm_nodes); //to store the values

MPI_arguments (&my_value_all, 1, MPI_INT, 0, comm_sm); my_rank_all = my_rank_all + my_rank_sm; //arguments passed to make the parallel code

MPI_Comm_split (real_lower,real_upper,&comm_all); //parallel MP and MPI calls split

//main

int main(int argc,char *argv[]){

double real_lower;

double real_upper;

double img_lower;

double real_upper;

int num;

int maxiter;

int num_regions =(argc-1)/6;

for(int region=0;region<num_regions;region++){

//scan the arguments

sscanf(argv[region*6+11,"%if ",&real lower);

#pragma mp,mpi parallel default(shared) private(iam, np)

{

call omp_set_numpoints(region)

do step = 1, itermax

call maxiter_real(upper, lower,imaginery,…)

do count = 1, num_region

if (iam .region. max_iter_id(zone)) then //maxiter region defined

end if

end do

end do

...

//main

int main(int argc,char *argv[]){

double real_lower;

double real_upper;

double img_lower;

double real_upper;

int num;

int maxiter;

int num_regions =(argc-1)/6;

for(int region=0;region<num_regions;region++){

//scan the arguments

sscanf(argv[region*6+1,"%if ",&real_lower);

sscanf(argv[region*6+2,"%if ",&real_upper);

sscanf(argv[region*6+3,"%if ",&img_lower);

sscanf(argv[region*6+4,"%if ",&img_upper);

sscanf(argv[region*6+5,"%if ",&num);

sscanf(argv[region*6+6,"%if ",&maxiter);

np = mp_mpi_get_num_realupper();

iam = mp_mpi_get_reallower();

printf("Print from maxiter %d out of %d from process %d out of %d on %s ",

iam, real, imaginery);

}

MPI_Finalize();

printf("%d ",mandlebrotsetcount(real_lower,real_upper,img_lower,img_lower,num,maxiter));

}

return EXIT_SUCCESS

}

}

#can proceed this code in less runtime comparatively and both open mp and mpi used.

Hope this helps you.All the best

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