1. Trang chủ
  2. » Giáo án - Bài giảng

tính toán song song thoại nam lab8 define new datatype with mpi datatype sinhvienzone com

9 21 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Buổi 8a: Định nghĩa kiểu liệu cho hàm truyền thông Nội dung: Mục tiêu lab tìm hiểu số phương pháp truyền liệu trường hợp đặc biệt như: liệu cần truyền trải vùng nhớ liên tục không liền nhau, liệu không kiểu… om Sinh viên tìm hiểu cách định nghĩa kiểu liệu dẫn xuất từ kiểu cấu trúc C/C++, để dùng hàm truyền thông MPI_Send(), MPI_Recv(), MPI_Bcast()… Chúng ta có hàm MPI hỗ trợ định nghĩa kiểu liệu kiểu sau: Zo ne C MPI_Type_contiguous (count, oldtype, *newtype) MPI_Type_vector (count,blocklength,stride,oldtype,*newtype) MPI_Type_hvector (count,blocklength,stride,oldtype,*newtype) MPI_Type_indexed (count, blocklens[], offsets[], old_type,*newtype) MPI_Type_hindexed (count, blocklens[], offsets[], old_type, *newtype) MPI_Type_struct(int count, int *lengths, MPI_Aint *disps, MPI_Datatype *oldtypes, MPI_Datatype *newtype) en Đối với trường hợp truyền liệu không kiểu, MPI cung cấp hàm MPI_Pack MPI_Unpack Vi int MPI_Pack( void *inbuf,int incount,MPI_Datatype datatype, void *outbuf,int outcount,int *position,MPI_Comm comm ) Si nh int MPI_Unpack( void *inbuf,int insize,int *position, void *outbuf,int outcount,MPI_Datatype datatype, MPI_Comm comm ) Vấn đề: Giả sử muốn truyền cấu trúc C (ví dụ: typedef struct INDATA) không kiểu thuộc MPI_Datatype nên dùng với hàm truyền thông điểm nối điểm hay hàm nhóm (MPI_Send, MPI_Recv, MPI_Bcast, MPI_Scatter, MPI_Reduce, MPI_Gather…) Giải pháp: Có nhiều cách đóng gói liệu MPI, giải pháp chọn định nghĩa kiểu liệu dẫn xuất từ MPI_Datatype hàm MPI_Type_struct( ), MPI_Type_commit( ), MPI_Address( ) Đọc thêm: https://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types SinhVienZone.com https://fb.com/sinhvienzonevn Chương trình mẫu: Ví dụ 1: C Language - Contiguous Derived Data Type Example #include "mpi.h" #include #define SIZE C om int main(argc,argv) int argc; char *argv[]; { int numtasks, rank, source=0, dest, tag=1, i; float a[SIZE][SIZE] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0}; float b[SIZE]; ne MPI_Status stat; MPI_Datatype rowtype; Zo MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); en MPI_Type_contiguous(SIZE, MPI_FLOAT, &rowtype); MPI_Type_commit(&rowtype); nh Vi if (numtasks == SIZE) { if (rank == 0) { for (i=0; i

Ngày đăng: 30/01/2020, 22:31

Xem thêm:

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN