BÁO cáo bài tập lớn hệ điều HÀNH đề tài PThread and multicore programming

19 7 0
BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ĐẠI HỌC QUỐC GIA THÀNH PHỐ HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA  BÁO CÁO BÀI TẬP LỚN HỆ ĐIỀU HÀNH Đề tài : PThread and Multicore programming GVHD: GV: Nguyễn Quang Hùng Thực hiện: Nguyễn Lê Minh Bảo Hà Việt Đức Đoàn Thảo Nhi - 2014010 Trịnh Tiến Đạt - 2012959 Từ Hoàng Phiếm - 2014112 Lớp L04, ngày 20 tháng năm 2022 Mục lục Phần Lý thuyết 2.1 Phần code Mutexes 4 2.1.1 2.1.2 2.1.3 2.2 Review, compile and run the dotprodserial.c program Review, compile and run the dotprodmutex.c program Execute the dotprodmutex.c program with thread are arranged Condition Variables 11 2.2.1 2.2.2 2.3 Review, compile and run the condvar.c program 11 Review, compile, run the bug4.c program and fix the problem 13 Figure out and fix the global sum 14 2.4 Compile and run arrayloops.c 19 Phần Phần Lý thuyết Báo cáo Bài tập lớn Hệ Điều Hành Phần Phần code 2.1 2.1.1 Mutexes Review, compile and run the dotprodserial.c program The dotprodserial.c program used to calculate the indirection of two vectors with length =100000 Two vectors is calculated to be shown struct DOTDATA This program does by running sequentially on a thread Output : Result When dotprodserial.c run Hình 2.1.1: Real time of dotpodserial.c 2.1.2 Review, compile and run the dotprodmutex.c program The dotprodmutex.c program used to calculate the direction of two vectors with length=100000 But here is the difference: • In main() function has initialize with the number of thread is to run parallel processes • In dotprod() function use pthreadmutexlock pthreadmutexunlock is one of the main means to synchronize flows and to protect shared data when multiple writing happens Output : Result when the dotprodmutex.c run Báo cáo Bài tập lớn Hệ Điều Hành Phần Phần code Trường Đại học Bách Khoa Thành phố Hồ Chí Minh Hình 2.1.2: Real time of dotpodmutex.c Output : The dotprodmutex.c run with thread = 2, 4, 8, 16, 32 sum=100000 • Thread=2 Hình 2.1.3: Real time of dotpodmutex.c with thread=2 • Thread=4 Hình 2.1.4: Real time of dotpodmutex.c with thread=4 Báo cáo Bài tập lớn Hệ Điều Hành Trường Đại học Bách Khoa Thành phố Hồ Chí Minh • Thread=8 Hình 2.1.5: Real time of dotpodmutex.c with thread=8 • Thread=16 Hình 2.1.6: Real time of dotpodmutex.c with thread=16 Báo cáo Bài tập lớn Hệ Điều Hành Phần Phần code Phần Phần code Trường Đại học Bách Khoa Thành phố Hồ Chí Minh • Thread=32 Hình 2.1.7: Real time of dotpodmutex.c with thread=32 Comparison chart between dotprodserial.c and dotprodmutex.c 2.1.3 Execute the dotprodmutex.c program with thread are arranged Explain the code : • Wanting the thread to be printed in the same self, we need to let pthreadjoin within for the time of creating pthreadcreate Because the thread is created it will run and wait for pthreadjoin to pay the result, then create a new thread new should order Print it will be true • As for pthreadjoin at another for another round, it only works to wait all the thread returns the result before the main () stops • If there is no pthreadjoin, when the main () is finished, no matter whether other threads are finished or not, the program is terminated Code after fixing : Báo cáo Bài tập lớn Hệ Điều Hành Trường Đại học Bách Khoa Thành phố Hồ Chí Minh #include #include #include typedef struct { double *a; double *b; double sum; int veclen; } DOTDATA; /* Define globally accessible variables and a mutex */ #define NUMTHRDS #define VECLEN 100000 DOTDATA dotstr; pthread_t callThd[NUMTHRDS]; pthread_mutex_t mutexsum; void *dotprod(void *arg) { /* Define and use local variables for convenience */ int i, start, end, len ; long offset; double mysum, *x, *y; offset = (long)arg; len = dotstr.veclen; start = offset*len; end = start + len; x = dotstr.a; y = dotstr.b; /* Báo cáo Bài tập lớn Hệ Điều Hành Phần Phần code Phần Phần code Trường Đại học Bách Khoa Thành phố Hồ Chí Minh Perform the dot product and assign result to the appropriate variable in the structure */ mysum = 0; for (i=start; i

Ngày đăng: 26/04/2022, 06:17

Hình ảnh liên quan

Hình 2.1.1: Real time of dotpodserial.c. - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.1.1.

Real time of dotpodserial.c Xem tại trang 4 của tài liệu.
Hình 2.1.2: Real time of dotpodmutex.c - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.1.2.

Real time of dotpodmutex.c Xem tại trang 5 của tài liệu.
Hình 2.1.3: Real time of dotpodmutex.c with thread=2. - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.1.3.

Real time of dotpodmutex.c with thread=2 Xem tại trang 5 của tài liệu.
Hình 2.1.6: Real time of dotpodmutex.c with thread=16. - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.1.6.

Real time of dotpodmutex.c with thread=16 Xem tại trang 6 của tài liệu.
Hình 2.1.5: Real time of dotpodmutex.c with thread=8. - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.1.5.

Real time of dotpodmutex.c with thread=8 Xem tại trang 6 của tài liệu.
Hình 2.1.7: Real time of dotpodmutex.c with thread=32. - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.1.7.

Real time of dotpodmutex.c with thread=32 Xem tại trang 7 của tài liệu.
Hình 2.2.1: The result after running the bug4.c program. - BÁO cáo bài tập lớn hệ điều HÀNH đề tài  PThread and multicore programming

Hình 2.2.1.

The result after running the bug4.c program Xem tại trang 13 của tài liệu.

Tài liệu cùng người dùng

Tài liệu liên quan