10120. Hello, MIC testing

I'm a slow walker, but I never walk backwards.

題目描述

在 Host 和 MIC 端,分別輸出裝置名稱、有多少個 logical core 以及實際運作預設 thread 數量。

範例輸入

no input

範例輸出

Host: Mermaid
Host: 4 logical cores
Host: 4 threads
MIC: Mermaid-mic0
MIC: 228 logical cores
MIC: 200 threads

參考寫法

請注意要使用 fflush(stdout); 否則輸出順序有會問題。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <omp.h>
#include <unistd.h>
#include <errno.h>
int main() {
    char hostname[128];
    int threads;
    long cache_size, line_size;
    gethostname(hostname, sizeof(hostname));
    printf("Host: %s\n", hostname);
    printf("Host: %ld logical cores\n", sysconf(_SC_NPROCESSORS_ONLN));
#pragma omp parallel
    {
        #pragma omp single
        threads = omp_get_num_threads();
    }
    printf("Host: %d threads\n", threads);
    fflush(stdout);
 
#pragma offload target(mic)
    {
        char hostname[128];
        gethostname(hostname, sizeof(hostname));
        printf("MIC: %s\n", hostname);
        printf("MIC: %ld logical cores\n", sysconf(_SC_NPROCESSORS_ONLN));
#pragma omp parallel
        {
            #pragma omp single
            threads = omp_get_num_threads();
        }
        printf("MIC: %d threads\n", threads);
    }
    return 0;
}

Discussion