OpenFoam中动态库与静态库链接的问题 - 悲催的科学匠人 - 冷水's blog

OpenFoam中动态库与静态库链接的问题

冷水 posted @ 2012年3月04日 06:55 in OpenFOAM , 3353 阅读

1 Pstream封装了MPI,采用mpicxx的编译选项生成了mpi/libPstream.so

同时有串行版的Pstream,生成dummy/libPstream.so

2 OpenFoam库,调用Pstream,并链接了dummy/libPstream.so,生成了libOpenFoam.so

3 基于OpenFoam库的并行程序,链接libOpenFoam.so

 

事实上,第2、3步不需要制定MPI链接选项(-lmpich之类),我做了一个例子来尝试

代码aa.C定义一个函数,

#include <cstdio>

#include "mpi.h"

using namespace std;

void func(int argc,char **argv)

{

int rank ,size;

MPI::Init(argc,argv);

size=MPI::COMM_WORLD.Get_size();

rank=MPI::COMM_WORLD.Get_rank();

printf("Hello world! , I am %d,in %d/n computer", rank, size);

MPI::Finalize();

}

mpicxx -c aa.C

mpicxx aa.o -shared -o libaa.so

这样将其编译为一个动态库

而后代码tt.C定义主函数

void func(int argc, char** argv);

int main(int argc,char **argv)

{
  func(argc,argv);
}

编译

icpc tt.C -L./ -laa -o tt

且定义libaa.so的搜索路径

而后mpirun即可

 

 

但是还是有一个疑问:为何libOpenFoam.so要链接dummy/libPstream.so。也许在执行的时候换上mpi/libPstream.so就可以实现并行?

  • 无匹配
  • 无匹配
Avatar_small
pavzi.com 说:
2024年1月17日 20:30

Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee