Введение в практику разработки параллельных программ в стандарте MPI. Баканов В.М - 53 стр.

UptoLike

Составители: 

- 53 -
Рисунок 6.— Схема распределения блоков умножаемых матриц по процессам
(пересылаемые части выделены серым фоном)
// source code of MM_MPI_0.C program
#include "mpi.h"
#include <stdio.h>
#define NRA 3000 /* number of rows in matrix A */
#define NCA 3000 /* number of columns in matrix A */
#define NCB 10 /* number of columns in matrix B */
#define MASTER 0 /* taskid of MASTER task */
#define FROM_MASTER 1 /* setting a message type */
#define FROM_WORKER 2 /* setting a message type */
#define M_C_W MPI_COMM_WORLD
int main(int argc, char *argv[])
{
int numtasks, /* number of tasks in partition */
taskid, /* a task identifier */
numworkers, /* number of worker tasks */
source, /* task id of message source */
dest, /* task id of message destination */
rows, /* rows of matrix A sent to each worker */
averow, extra, offset, /* used to determine rows sent to each worker */
i, j, k, rc; /* indexes */
double a[NRA][NCA], /* matrix A to be multiplied */
b[NCA][NCB], /* matrix B to be multiplied */
c[NRA][NCB], /* result matrix C */
t1,t2; // time's momemts
MPI_Status status;
rc = MPI_Init(&argc,&argv);
rc|= MPI_Comm_size(M_C_W, &numtasks);
rc|= MPI_Comm_rank(M_C_W, &taskid);
 Рисунок 6.— Схема распределения блоков умножаемых матриц по процессам
             (пересылаемые части выделены серым фоном)


// source code of MM_MPI_0.C program
#include "mpi.h"
#include 

#define NRA 3000 /* number of rows in matrix A */
#define NCA 3000 /* number of columns in matrix A */
#define NCB 10   /* number of columns in matrix B */

#define MASTER 0 /* taskid of MASTER task */
#define FROM_MASTER 1 /* setting a message type */
#define FROM_WORKER 2 /* setting a message type */
#define M_C_W MPI_COMM_WORLD

int main(int argc, char *argv[])
{
int    numtasks,           /* number of tasks in partition */
       taskid,             /* a task identifier */
       numworkers, /* number of worker tasks */
       source,             /* task id of message source */
       dest,               /* task id of message destination */
       rows,                /* rows of matrix A sent to each worker */
       averow, extra, offset, /* used to determine rows sent to each worker */
       i, j, k, rc; /* indexes */
double a[NRA][NCA],               /* matrix A to be multiplied */
        b[NCA][NCB],              /* matrix B to be multiplied */
        c[NRA][NCB],              /* result matrix C */
         t1,t2; // time's momemts
MPI_Status status;

rc = MPI_Init(&argc,&argv);
rc|= MPI_Comm_size(M_C_W, &numtasks);
rc|= MPI_Comm_rank(M_C_W, &taskid);

                                            - 53 -