當前位置:首頁 » 編程軟體 » 編譯器運算

編譯器運算

發布時間: 2023-11-04 23:16:31

『壹』 C語言 運算符%是怎麼運算的

1、%是求余運算符,也叫模除運算符,用於求余數。

2、%要求兩個操作數均為整數(或可以隱式轉換成整數的類型),%是求余數的運算,例如7%2=1。

3、舉例:

#include<stdio.h>

void main()

{

int i=7;

i=i%2;

printf("%d ",i);

}

運行結果如下圖:

(1)編譯器運算擴展閱讀

1、%d整型輸出,%ld長整型輸出,

2、%o以八進制數形式輸出整數,

3、%x以十六進制數形式輸出整數,或輸出字元串的地址。

4、%u以十進制數輸出unsigned型數據(無符號數)。注意:%d與%u有無符號的數值范圍,也就是極限的值,不然數值列印出來會有誤。

5、%c用來輸出一個字元,

6、%s用來輸出一個字元串,

7、%f用來輸出實數,以小數形式輸出,默認情況下保留小數點6位。

8、%.100f來輸出實數,保留小數點100位。

9、%e以指數形式輸出實數,

10、%g根據大小自動選f格式或e格式,且不輸出無意義的零。

『貳』 如何在命令行中使用intel c++編譯器,並使用openmp和mkl來編譯自己的程序,並運算

1、icc

Intel C/C++編譯器接受遵守ANSI C/C++ , ISO C/C++ standards,GNU inline ASM for IA-32 architecture標準的輸入。與linux下常用的gcc兼容並支持更大的C語言擴展,包括源文件、命令行參數、目標文件。不支持gcc的inline方式的匯編。例,f.c

#include<stdio.h>

int main(int argc, char* argv[]){

printf("Hello\n");

return 0;

}

編譯:icc -c f.cpp -o f.o

鏈接:icc f.o -o f

運行:./f

注意,編譯與鏈接都由icc來完成,icc常用命令行參數:

-o 輸出文件命名

-I include路徑

-L lib路徑

-l 包含的lib名

-c 僅生成目標文件(*.o),不鏈接

-On n=0,1,2,3 編譯器優化選項,n=0關閉編譯器優化,n=3使用最激進的優化

-c99[-] 打開/關閉 c99規范的支持

詳細的請參照icc的manpage.

2、ifort

Intel Fortran編譯器支持F77/90/95標准並與CFV(Compaq Visual Fortran)兼容。例,f.f90

program f

print *, "Hello"

stop

end

編譯:ifort -c f.f90 -o f.o

鏈接:ifort f.o -o f

運行:./f

編譯與連接同樣由ifort來完成,ifort常用命令行參數:

-o 輸出文件命名

-I include路徑

-L lib路徑

-l 包含的lib名

-c 僅生成目標文件(*.o),不鏈接

-On n=0,1,2,3 編譯器優化選項,n=0關閉編譯器優化,n=3使用最激進的優化

-std90 使用F90標准編譯

-std95 使用F 95標准編譯

-f77rtl 編譯使用F77運行方式的代碼(用於解決特殊問題)

These options optimize application performance for a particular Intel? processor or family of processors. The compiler generates code that takes advantage of features of the specified processor.

Option

Description
tpp5 or G5 Optimizes for Intel? Pentium? and Pentium? with MMX? technology processors.
tpp6 or G6 Optimizes for Intel? Pentium? Pro, Pentium? II and Pentium? III processors.
tpp7 or G7 Optimizes for Intel? Pentium? 4, Intel? Xeon?, Intel? Pentium? M processors, and Intel? Pentium? 4 processors with Streaming SIMD Extensions 3 (SSE3) instruction support.
On Intel? EM64T systems, only option tpp7 (Linux) or G7 (Windows) is valid.

About tpp:

http://www.ncsa.illinois.e/UserInfo/Resources/Software/Intel/Compilers/9.0/main_for/mergedProjects/copts_for/common_options/option_tpp567_g567.htm

https://wiki.ke.e/display/SCSC/Compilers+and+Libraries

Intel Fortran Compiler Options: http://geco.mines.e/guide/ifort.html

Intel(R) Fortran Compiler Options: http://www.rcac.pure.e/userinfo/resources/common/compile/compilers/intel/man/ifort.txt

ifort編譯器提供了非常多的優化參數

$ ifort --help | more 查看就可以
也可以定位到某個參數

$ifort --help | grep -5 '-mkl'
-5表示顯示查找到的行及下面5行的內容。

3、Intel MKL數學庫針對Intel系列處理器進行了專門的優化,主要包含的庫有:

基本線形代數運算(BLAS)

向量與向量、向量與矩陣、矩陣與矩陣的運算

稀疏線形代數運算

快速傅立葉變換(單精度/雙精度)

LAPACK(求解線形方程組、最小方差、特徵值、Sylvester方程等)

向量數學庫(VML)

向量統計學庫(VSL)

高級離散傅立葉變換

編譯:

icc multi.c -I/opt/intel/mkl/include –L/intel/mkl/lib –lmpi_ipf –o multi

4、MPI程序編譯

消息傳遞介面(MPI)並行程序設計模型程序的編譯命令。例,f.c

include<stdio.h>

#include<mpi.h>

main(argc,argv)

int argc;

char *argv[];

{

char name[BUFSIZ];

int length;

MPI_Init(&argc,&argv);

MPI_Get_processor_name(name, &length);

printf("%s: hello world\n", name);

MPI_Finalize();

}

編譯與連接均使用mpicc,參數與mpicc中定義的編譯器相同,這里與icc相同。

mpicc –c hello.c –o hello.o

mpicc hello.o –o hello

運行使用mpirun 命令,將運行需要的節點定義在文件中並在-machinfile中制定。

文件: nodelist

node1

node1

node2

node3

運行:

$mpirun –machefile nodelist –np 4 ./hello

node1: hello world

node1: hello world

node2: hello world

node3: hello world

5、32位向64位的移植

32位程序到64位移植中應注意的常見問題:

數據截斷:

由於long類型變數的運算(賦值、比較、移位等)產生。long定義在x86上為32bits,而在ia64上為64bits.容易在與int型變數運算時出現異常。

處理方法:盡量避免不同類型變數間的運算,避免將長度較長的變數賦值到較短的變數中,統一變數長度可以解決這個問題。簡單的對於32位轉移到64位可以將所有long定義轉換為int定義。

熱點內容
php配置mail 發布:2024-05-19 11:52:37 瀏覽:906
歐洲國家的雲伺服器 發布:2024-05-19 11:43:30 瀏覽:44
左游手柄助手2腳本 發布:2024-05-19 11:40:28 瀏覽:1002
挖礦需要什麼配置 發布:2024-05-19 11:38:02 瀏覽:895
eclipse導出ant腳本 發布:2024-05-19 11:20:28 瀏覽:99
如何改變vivo手機賬戶密碼 發布:2024-05-19 10:56:07 瀏覽:377
sql的length函數 發布:2024-05-19 10:55:15 瀏覽:546
資料庫管理系統設計報告 發布:2024-05-19 10:49:50 瀏覽:685
linux怎麼將驅動編譯進內核 發布:2024-05-19 10:23:47 瀏覽:768
c語言讀程序題 發布:2024-05-19 10:13:52 瀏覽:675