pmpi简单实例
来源:互联网 发布:mysql数据库5.5.20安装 编辑:程序博客网 时间:2024/05/19 20:18
1. Compile OpenMPI with --enable-mpi-profile. This option will enable building of PMPI interface.
./configure --prefix=/home/dycz0fx/opt/ompi/debug --enable-mpirun-prefix-by-default --enable-debug --enable-mpi-profile
2. Build OpenMPI
make all install
3. Write PMPI profiler, name it as test_pmpi.c.
/* PMPI profiler example */#include <stdio.h>#include "mpi.h"int MPI_Init(int *argc, char ***argv){ int rank, err; err = PMPI_Init(argc, argv); PMPI_Comm_rank(MPI_COMM_WORLD, &rank) ; printf("[%d]: Profile MPI_Init.\n", rank) ; return err;}int MPI_Finalize(){int rank;PMPI_Comm_rank(MPI_COMM_WORLD, &rank) ;printf("[%d]: Profile MPI_Finalize.\n", rank) ;return PMPI_Finalize( );}
4. Compile test_pmpi.c to a object file.
mpicc -c test_pmpi.c -o test_pmpi.o
5. Produce a static library with the object file test_pmpi.o.ar rcs libtestpmpi.a test_pmpi.o
6. For any MPI program, for example bcast.c below./* MPI_Bcast example */
#include <mpi.h>#include <stdio.h>#define SIZE 10#define TIMES 1int main(int argc, char** argv) { int rank; int buf[SIZE]; const int root=1; int i, j; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); for (j = 0; j<TIMES; j++) { if(rank == root) { for (i=0; i<SIZE; i++) { buf[i] = 10 * i; } } else{ for (i=0; i<SIZE; i++) { buf[i] = 0; } } printf("[%d]: Before Bcast, buf is", rank); for (i=0; i<SIZE; i++) { printf(" %d", buf[i]); } printf("\n"); /* everyone calls bcast, data is taken from root and ends up in everyone's buf */ MPI_Bcast(&buf, SIZE, MPI_INT, root, MPI_COMM_WORLD); printf("[%d]: After Bcast, buf is", rank); for (i=0; i<SIZE; i++) { printf(" %d", buf[i]); } printf("\n"); } MPI_Finalize(); return 0;}~Compile bcast.c with the link to the static library created before.
mpicc bcast.c -L. -ltestpmpi -g -o bcast
0 0
- pmpi简单实例
- JQuery实例Ajax 简单实例
- ActiveMQ简单介绍+简单实例
- jboss ejb 简单实例
- 简单的struts实例
- AWK简单实例
- Struts简单实例
- xsl+xml简单实例
- Socket编程简单实例
- Spring简单入门实例
- web 打印简单实例
- struts简单入门实例
- .net Remoting简单实例
- Ntbackup简单使用实例
- .net Remoting简单实例
- Ajax应用简单实例
- RMI简单实例
- SOCKET简单实例
- 5. Longest Palindromic Substring
- Android 正确的闪屏方式。
- Epoll模型详解
- Epoll模型讲解
- laravel的吐槽
- pmpi简单实例
- laravel眼瞎么?
- caffe中如何可视化cnn各层的输出
- permutations
- subsets
- [译]时间自动机:语义,算法和工具 UPPAAL
- [Exploratory Data Analysis] Week 1
- [Exploratory Data Analysis] Project 1
- 表单中邮箱自动完成的实现