Thuật toỏn JOR

Một phần của tài liệu Một số phương pháp song song cho hệ đại số tuyến tính (Trang 51 - 54)

Chương trỡnh JOR tương tự như Jacobi nhưng khác phần cơng thức tính tốn do cĩ thêm tham số ω.

3.Thut ton SOR

Chương trỡnh viết cho thuật toỏn SOR: #include<stdio.h>

#include<mpi.h> #include<stdlib.h>

#define w 1 /*khai bao tham so ω*/

#define n 256 /* sốđim trong ca lưới */ #define epsilon 0.0000000001 /* sai số */

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

int rank,size,i,j,k,N,myn;

double *x,*y,*subxnew,*subx,sum,temp,total; MPI_Status status;

KILOBOOKS.COM MPI_Init(&argc,&argv); /* Khi to MPI */ /* Ly hng ca cc tiến trnh */ MPI_Comm_rank(MPI_COMM_WORLD,&rank); /* Ly s cc tiến trnh */ MPI_Comm_size(MPI_COMM_WORLD,&size); if(rank==0) { N=n*n; /* s phn t ca véc tơ ct x */ x=(double*)malloc(N*sizeof(double));/* x(k+1) */ y=(double*)malloc(N*sizeof(double)); /* x(k) */ myn=N/size; /* s phn t x trong mi b x lớ */ } MPI_Bcast(&myn,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); /* myn+n phn t x(k+1) trong cc b x l khi to gi tr =0*/ subx=(double*)malloc((myn+n)*sizeof(double)); for(i=0;i<myn;i++) subx[i]=0; /* myn phn t x(k+1) trong cc b x lớ*/ subxnew=(double*)malloc((myn)*sizeof(double)); do {

/* b x l hng rank gi n phn t cho b x l hng rank-1 */ if(rank>0)

KILOBOOKS.COM

/* b x l hng rank nhn n phn t t b x l hng rank+1 */ if(rank<size-1)

MPI_Recv(subx+myn+n,n,MPI_DOUBLE,rank+1,rank+1,MPI_COMM_W ORLD,&status);

/* tính subxnew t subx s dng bước 1 thut tốn */

MPI_Gather(subxnew,myn,MPI_DOUBLE,y,myn,MPI_DOUBLE,0, MPI_COMM_WORLD);

if(rank==0)

/* tnh x(k+1) t y theo bước 2 ca thut tốn */ MPI_Scatter(x,myn,MPI_DOUBLE,subxnew,myn,MPI_DOUBLE,0, MPI_COMM_WORLD); /* tnh sai số */ MPI_Allreduce(&sum,&total,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); }

while (total>epsilon); /* lp khi chưa tho mĩn sai số */ MPI_Finalize(); /* đĩng mơi trường MPI */

return 0; }

KILOBOOKS.COM

BNG CÁC CH VIT TT

SISD Single Instruction Single Data SIMD Single Instruction Multiple Data MISD Multiple Instruction Single Data MIMD Multiple Instruction Multiple Data CPU Central Processing Unit

UMA Uniform Memory Access NUMA NonUniform Memory Access RAM Random Access Memory

PRAM Parallel Random Access Memory CR Concurent Read

CW Concurent Write ER Exclusive Read EW Exclusive Write

COMA Cache – Only Memory Access

WS Workstation

WSC Workstation Cluster

HPC High Performance Computing TCP Transmission Control Protocol UDP User Datagram Protocol (adsbygoogle = window.adsbygoogle || []).push({});

MPI Message Passing Interface JOR Jacobi Overrelaxation SOR Successive Overrelaxation

Một phần của tài liệu Một số phương pháp song song cho hệ đại số tuyến tính (Trang 51 - 54)