openmp编程

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

void Hello(int thread_c);

int main(int argc, char* argv[]) {
    int thread_count = strtol(argv[1], NULL, 10);
    // printf("thread_count is %d \n", thread_count);
    
    Hello(thread_count);

    return 0;
}

void Hello(int thread_c) {
    
    omp_set_num_threads(thread_c);
    #pragma omp parallel
    {
        int my_rank = omp_get_thread_num();
        int thread_count = omp_get_num_threads();

        printf("Hello from thread %d of %d \n", my_rank, thread_count);
    }
    
}

终端执行:

gcc -g -Wall -fopenmp -o omp_hello omp_hello.c
./omp_hello 4

输出为:

Hello from thread 3 of 4 
Hello from thread 1 of 4 
Hello from thread 2 of 4 
Hello from thread 0 of 4 

相关链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值