在Linux进行C语言编程的时候,程序里使用了mpi或者openmp或者都使用了该怎么进行编译执行??谢谢

在Linux进行C语言编程的时候,程序里使用了mpi或者openmp或者都使用了该怎么进行编译执行??谢谢,第1张

mpi或者openmp

这个,你指的是库?颂野猛

如果是的话,编译时,加脊御上链接野桥库的编译选项就可以。

比如 gcc -hello.c -o hello -lm -lxml -L/usr/local/lib -lts

-lm 链接了math库

-lxml链接了xml库

-L/usr/local/lib -lts 链接了ts库,ts库存在目录/usr/local/lib中

在LINUX上要GCC 4.1并要安装MPI软件包,派烂碧命令是:比如是CPI.c的原文件,那么如下:

编译:/usr/local/bin/mpicc -o CPI CPI.c -fopenmp

执行历慎:/usr/local/bin/mpirun -np 4 CPI 8 //4表示4台机器,尘举8表示线程

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.edu/UserInfo/Resources/Software/Intel/Compilers/9.0/main_for/mergedProjects/copts_for/common_options/option_tpp567_g567.htm

https://wiki.duke.edu/display/SCSC/Compilers+and+Libraries

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

Intel(R) Fortran Compiler Options: http://www.rcac.purdue.edu/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定义。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12551996.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存