學號:311551173 姓名:黃牧恩
Q1
What are the pros and cons of the three methods? Give an assumption about their performances.
Method 1
Pros: 每一個thread只需要處理一個pixel
Cons: 有些計算量小的thread只被使用一下,只有部分的thread會因為計算量較大而被使用較久,導致整體thread utilization較低
huang-me changed 3 years agoView mode Like Bookmark
Q1.1: How do you control the number of MPI processes on each node?
MPI run programs according to hostfile, it assign programs to machine in hostfile one-by-one.
machine_1
machine_1
machine_2
If we're going to run 8 copies of the program and hostfile is defined as above, program_1 & program 2 will be assigned to machine_1, program_3 will be assigned to machine_2, program_4 will be assigned to machine_1, ...etc.
huang-me changed 3 years agoView mode Like Bookmark
Q1:
Is speedup linear in the number of threads used? In your writeup hypothesize why this is (or is not) the case?
Refer to the graph above, the speedup is almost linear.
Since all threads doing same thing, using more thread will reduce the loading of threads, which decrease the execution time linearly.
Speedup is also almost linear too.
Q2:
How do your measurements explain the speedup graph you previously created?
huang-me changed 3 years agoView mode Like Bookmark
contributed by <huang-me>
測驗一 (average)
Solution 1
#include <stdint.h>
uint32_t average(uint32_t a, uint32_t b)
{
return (a >> 1) + (b >> 1) + (a & b & 1);
}
huang-me changed 3 years agoView mode Like Bookmark
contributed by < huang-me >
twoSum
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
struct hlist_node { struct hlist_node *next, **pprev; };
struct hlist_head { struct hlist_node *first; };
typedef struct { int bits; struct hlist_head *ht; } map_t;
#define MAP_HASH_SIZE(bits) (1 << bits)
huang-me changed 3 years agoView mode Like Bookmark
contributed by: <huang-me>
Rewrite
Leetcode 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).
C code
int cntbit(int n) {
if(n == 0) return 0;
int cnt = 0;
huang-me changed 4 years agoView mode Like Bookmark
Two Sum
Approach 1:
Iterate through all possible combinations, and check if the sum of combination is equal to target value, return index of two numbers.
Time complexity: O($n^2$). For each element, we try to find its complement by looping through the rest of the array which takes O(n) time. Therefore, the time complexity is O($n^2$).
vector<int> twoSum(vector<int>& nums, int target) {
for(int i=0; i<nums.size(); i++) {
for(int j=i+1; j<nums.size(); j++) {
if(nums[i]+nums[j] == target) return {i, j};
huang-me changed 4 years agoView mode Like Bookmark