Escolar Documentos
Profissional Documentos
Cultura Documentos
h>
#include<stdlib.h>
#include <mpi.h>
#define max_rows 100
#define send_data_tag 2001
#define return_data_tag 2002
int array4[max_rows];
int array3[max_rows];
/* dizi hazirlaniyor */
for(i = 1; i <= num_procs; i++)
for(j=1;j<=num_procs;j++)
{
printf("Lütfen %d*%d matrisinin %d. satýr ve %d. sütunu girin
iz",&num_procs,&num_procs,i,j);
scanf("%d",&array4[(i-1)*num_procs+j]);
}
for(j=1;j<=num_procs;j++)
for(k=1;k<=num_procs;k++)
{
if(array4[k]+array4[(k-1)*num_procs+j]<array4[j])
array4[j]=array4[k]+array4[(k-1)*num_procs+j];
} //ana iþlemci 1. satýrý halletti.
/* distribute a portion of the bector to each child process */
for(an_id = 1; an_id < num_procs; an_id++) {
ierr= MPI_Send(&num_procs, 1, MPI_INT,
an_id, send_data_tag, MPI_COMM_WORLD);
ierr= MPI_Send(&array2[0], an_id+1, MPI_INT,
an_id, send_data_tag, MPI_COMM_WORLD);
}
/* and calculate the sum of the values in the segment assigned
* to the root process */
/* and, finally, I collet the partial sums from the slave processes,
* print them, and add them to the grand sum, and print it */
for(an_id = 1; an_id < num_procs; an_id++) {
ierr = MPI_Recv( &array4, 1, MPI_LONG, MPI_ANY_SOURCE,
return_data_tag, MPI_COMM_WORLD, &status);
sender = status.MPI_SOURCE;
printf("%i. islemci tarafindan gönderilen satýr %i\n");
for(i=1;i<=num_procs;i++)
printf("%d ",array4[(an_id-1)*num_procs+i]);
}
else
{
/* I must be a slave process, so I must receive my array segment,
* storing it in a "local" array, array1. */
ierr = MPI_Recv( &num_procs2, 1,MPI_INT,
root_process, send_data_tag, MPI_COMM_WORLD, &status);
ierr = MPI_Recv( &array3, num_rows_received, MPI_INT,
root_process, send_data_tag, MPI_COMM_WORLD, &status);
/* Calculate the sum of my portion of the array */
for(j=1;j<=num_procs2;j++)
for(k=1;k<=num_procs2;k++)
{
if(array3[(num_rows_received-1)*num_procs2+k]+array3[(k-1)*num_procs
2+j]<array3[(num_rows_received-1)*num_procs2+j])
array3[(num_rows_received-1)*num_procs2+j]=array
3[(num_rows_received-1)*num_procs2+k]+array3[(k-1)*num_procs2+j];
}