實驗2-1.?OpenMP程式的編譯和運行?
1.?實驗目的?
1)?在Linux平臺上編譯和運行OpenMP程式;?
2)?在Windows平臺上編譯和運行OpenMP程式。?
3)?掌握OpenMP并行編程基礎。?
2.?實驗環境?
1)?硬體環境:計算機一臺;?
2)?軟體環境:Linux、Win2003、GCC、MPICH、VS2008或其他版本Visual?Studio;?
?
3.?實驗內容?
1.?Linux下OpenMP程式的編譯和運行。OpenMP是一個共享存盤并行系統上的應用編程接
口,支持C/C++和FORTRAN等語言,編譯和運行簡單的"Hello?World"程式。在Linux下編輯
hellomp.c源程式,或在Windows下編輯并通過附件中的FTP工具(埠號:1021)上傳,
用"gcc?-fopenmp?-O2?-o?hellomp.out?hellomp.c"命令編譯,用"./hellomp.out"命令運行程式。?
注:在虛擬機中當使用vi編輯檔案時,不是以ESC鍵退出插入模式,可以使用“Ctrl+c”進
入命令模式,然后輸入wq進行存盤退出。?
代碼如下:?
?
#include?<omp.h>?
#include?<stdio.h>?
int?main()?
{?
int?nthreads,tid;?
omp_set_num_threads(8);?
#pragma?omp?parallel?private(nthreads,tid)?
{?
tid=omp_get_thread_num();?
printf("Hello?World?from?OMP?thread?%d\n",tid);?
if(tid==0)?
{?
nthreads=omp_get_num_threads();?
printf("Number?of?threads?is?%d\n",nthreads);?
}?
}?
}?
?
?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/275920.html
標籤:C語言
上一篇:用C++實作圖片滾動效果
