⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpi.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 5 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * *  (C) 2001 by Argonne National Laboratory. *      See COPYRIGHT in top-level directory. */#include "mpi.h"#include <winsock2.h>#include <windows.h>#include "mpichconf.h"#include "mpichtimer.h"#include "mpimem.h"#include <stdio.h>#include <stdarg.h>#define MPIU_UNREFERENCED_ARG(a) a/* * Windows only mpi binding * * This file implements an mpi binding that calls another dynamically loaded mpi binding. * The environment variables MPI_DLL_NAME and MPICH2_CHANNEL control which library should be loaded. * The default library is mpich2.dll or mpich2d.dll. * A wrapper dll can also be named to replace only the MPI functions using the MPI_WRAP_DLL_NAME * environment variable. * * The motivation for this binding is to allow compiled mpi applications to be able * to use different implementations of mpich2 at run-time without re-linking the application. * This way mpiexec or the user can choose the best channel to use at run-time. * * For example, mpiexec may choose the shm channel for up to 8 processes on a single node * and sshm for more than 8 processes on a single node and the sock channel for multi-node * jobs. * Example 2: A user has an infiniband cluster and wants the ib channel to be the default. * So the user sets the mpiexec option to use the ib channel as the default and then all * jobs run on the cluster use the ib channel without modification or re-linking. * * A profiled or logged mpi implementation may be selected at run-time.  If the mpi dll is itself * profiled then the dll can be specified just as any other dll would be named.  Or a wrapper * dll can be named to work in conjunction with the mpi dll using the MPI_WRAP_DLL_NAME environment * variable.  The wrapper dll will implement the MPI interface and the mpi dll will implement the  * PMPI interface. * * The user can run a job and then decide to run the job again and produce a log file.  All that * needs to be done is specify the logged version of the mpich2 channel or a wrapper dll like mpe * and a log file will be produced. * Examples: * mpiexec -n 4 cpi * mpiexec -env MPICH2_CHANNEL ib -n 4 cpi * mpiexec -env MPI_DLL_NAME mpich2p.dll -n 4 cpi * mpiexec -env MPI_WRAP_DLL_NAME mpich2mped.dll -n 4 cpi * mpiexec -env MPICH2_CHANNEL ib -env MPI_WRAP_DLL_NAME mpich2mped.dll -n 4 cpi * */#define MPI_ENV_DLL_NAME          "MPI_DLL_NAME"#define MPI_ENV_CHANNEL_NAME      "MPICH2_CHANNEL"#define MPI_ENV_MPIWRAP_DLL_NAME  "MPI_WRAP_DLL_NAME"#ifdef _DEBUG#define MPI_DEFAULT_DLL_NAME      "mpich2d.dll"#define MPI_DEFAULT_WRAP_DLL_NAME "mpich2mped.dll"#define DLL_FORMAT_STRING         "mpich2%sd.dll"#else#define MPI_DEFAULT_DLL_NAME      "mpich2.dll"#define MPI_DEFAULT_WRAP_DLL_NAME "mpich2mpe.dll"#define DLL_FORMAT_STRING         "mpich2%s.dll"#endif#define MAX_DLL_NAME              100MPIU_DLL_SPEC MPI_Fint *MPI_F_STATUS_IGNORE = 0;MPIU_DLL_SPEC MPI_Fint *MPI_F_STATUSES_IGNORE = 0;static struct fn_table{    /* MPI */    MPI_Comm (*MPI_Comm_f2c)(MPI_Fint);    MPI_Datatype (*MPI_Type_f2c)(MPI_Fint);    MPI_File (*MPI_File_f2c)(MPI_Fint);    MPI_Fint (*MPI_Comm_c2f)(MPI_Comm);    MPI_Fint (*MPI_File_c2f)(MPI_File);    MPI_Fint (*MPI_Group_c2f)(MPI_Group);    MPI_Fint (*MPI_Info_c2f)(MPI_Info);    MPI_Fint (*MPI_Op_c2f)(MPI_Op);    MPI_Fint (*MPI_Request_c2f)(MPI_Request);    MPI_Fint (*MPI_Type_c2f)(MPI_Datatype);    MPI_Fint (*MPI_Win_c2f)(MPI_Win);    MPI_Group (*MPI_Group_f2c)(MPI_Fint);    MPI_Info (*MPI_Info_f2c)(MPI_Fint);    MPI_Op (*MPI_Op_f2c)(MPI_Fint);    MPI_Request (*MPI_Request_f2c)(MPI_Fint);    MPI_Win (*MPI_Win_f2c)(MPI_Fint);    int (*MPI_File_open)(MPI_Comm, char *, int, MPI_Info, MPI_File *);    int (*MPI_File_close)(MPI_File *);    int (*MPI_File_delete)(char *, MPI_Info);    int (*MPI_File_set_size)(MPI_File, MPI_Offset);    int (*MPI_File_preallocate)(MPI_File, MPI_Offset);    int (*MPI_File_get_size)(MPI_File, MPI_Offset *);    int (*MPI_File_get_group)(MPI_File, MPI_Group *);    int (*MPI_File_get_amode)(MPI_File, int *);    int (*MPI_File_set_info)(MPI_File, MPI_Info);    int (*MPI_File_get_info)(MPI_File, MPI_Info *);    int (*MPI_File_set_view)(MPI_File, MPI_Offset, MPI_Datatype, MPI_Datatype, char *, MPI_Info);    int (*MPI_File_get_view)(MPI_File, MPI_Offset *, MPI_Datatype *, MPI_Datatype *, char *);    int (*MPI_File_read_at)(MPI_File, MPI_Offset, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_read_at_all)(MPI_File, MPI_Offset, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_write_at)(MPI_File, MPI_Offset, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_write_at_all)(MPI_File, MPI_Offset, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_iread_at)(MPI_File, MPI_Offset, void *, int, MPI_Datatype, MPIO_Request *);    int (*MPI_File_iwrite_at)(MPI_File, MPI_Offset, void *, int, MPI_Datatype, MPIO_Request *);    int (*MPI_File_read)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);     int (*MPI_File_read_all)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);     int (*MPI_File_write)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_write_all)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_iread)(MPI_File, void *, int, MPI_Datatype, MPIO_Request *);     int (*MPI_File_iwrite)(MPI_File, void *, int, MPI_Datatype, MPIO_Request *);    int (*MPI_File_seek)(MPI_File, MPI_Offset, int);    int (*MPI_File_get_position)(MPI_File, MPI_Offset *);    int (*MPI_File_get_byte_offset)(MPI_File, MPI_Offset, MPI_Offset *);    int (*MPI_File_read_shared)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_write_shared)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_iread_shared)(MPI_File, void *, int, MPI_Datatype, MPIO_Request *);    int (*MPI_File_iwrite_shared)(MPI_File, void *, int, MPI_Datatype, MPIO_Request *);    int (*MPI_File_read_ordered)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_write_ordered)(MPI_File, void *, int, MPI_Datatype, MPI_Status *);    int (*MPI_File_seek_shared)(MPI_File, MPI_Offset, int);    int (*MPI_File_get_position_shared)(MPI_File, MPI_Offset *);    int (*MPI_File_read_at_all_begin)(MPI_File, MPI_Offset, void *, int, MPI_Datatype);    int (*MPI_File_read_at_all_end)(MPI_File, void *, MPI_Status *);    int (*MPI_File_write_at_all_begin)(MPI_File, MPI_Offset, void *, int, MPI_Datatype);    int (*MPI_File_write_at_all_end)(MPI_File, void *, MPI_Status *);    int (*MPI_File_read_all_begin)(MPI_File, void *, int, MPI_Datatype);    int (*MPI_File_read_all_end)(MPI_File, void *, MPI_Status *);    int (*MPI_File_write_all_begin)(MPI_File, void *, int, MPI_Datatype);    int (*MPI_File_write_all_end)(MPI_File, void *, MPI_Status *);    int (*MPI_File_read_ordered_begin)(MPI_File, void *, int, MPI_Datatype);    int (*MPI_File_read_ordered_end)(MPI_File, void *, MPI_Status *);    int (*MPI_File_write_ordered_begin)(MPI_File, void *, int, MPI_Datatype);    int (*MPI_File_write_ordered_end)(MPI_File, void *, MPI_Status *);    int (*MPI_File_get_type_extent)(MPI_File, MPI_Datatype, MPI_Aint *);    int (*MPI_Register_datarep)(char *, MPI_Datarep_conversion_function *, MPI_Datarep_conversion_function *, MPI_Datarep_extent_function *, void *);    int (*MPI_File_set_atomicity)(MPI_File, int);    int (*MPI_File_get_atomicity)(MPI_File, int *);    int (*MPI_File_sync)(MPI_File);    int (*MPI_Send)(void*, int, MPI_Datatype, int, int, MPI_Comm);    int (*MPI_Recv)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *);    int (*MPI_Get_count)(MPI_Status *, MPI_Datatype, int *);    int (*MPI_Bsend)(void*, int, MPI_Datatype, int, int, MPI_Comm);    int (*MPI_Ssend)(void*, int, MPI_Datatype, int, int, MPI_Comm);    int (*MPI_Rsend)(void*, int, MPI_Datatype, int, int, MPI_Comm);    int (*MPI_Buffer_attach)( void*, int);    int (*MPI_Buffer_detach)( void*, int *);    int (*MPI_Isend)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *);    int (*MPI_Ibsend)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *);    int (*MPI_Issend)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *);    int (*MPI_Irsend)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *);    int (*MPI_Irecv)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *);    int (*MPI_Wait)(MPI_Request *, MPI_Status *);    int (*MPI_Test)(MPI_Request *, int *, MPI_Status *);    int (*MPI_Request_free)(MPI_Request *);    int (*MPI_Waitany)(int, MPI_Request *, int *, MPI_Status *);    int (*MPI_Testany)(int, MPI_Request *, int *, int *, MPI_Status *);    int (*MPI_Waitall)(int, MPI_Request *, MPI_Status *);    int (*MPI_Testall)(int, MPI_Request *, int *, MPI_Status *);    int (*MPI_Waitsome)(int, MPI_Request *, int *, int *, MPI_Status *);    int (*MPI_Testsome)(int, MPI_Request *, int *, int *, MPI_Status *);    int (*MPI_Iprobe)(int, int, MPI_Comm, int *, MPI_Status *);    int (*MPI_Probe)(int, int, MPI_Comm, MPI_Status *);    int (*MPI_Cancel)(MPI_Request *);    int (*MPI_Test_cancelled)(MPI_Status *, int *);    int (*MPI_Send_init)(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *);    int (*MPI_Bsend_init)(void*, int, MPI_Datatype, int,int, MPI_Comm, MPI_Request *);    int (*MPI_Ssend_init)(void*, int, MPI_Datatype, int,int, MPI_Comm, MPI_Request *);    int (*MPI_Rsend_init)(void*, int, MPI_Datatype, int,int, MPI_Comm, MPI_Request *);    int (*MPI_Recv_init)(void*, int, MPI_Datatype, int,int, MPI_Comm, MPI_Request *);    int (*MPI_Start)(MPI_Request *);    int (*MPI_Startall)(int, MPI_Request *);    int (*MPI_Sendrecv)(void *, int, MPI_Datatype,int, int, void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *);    int (*MPI_Sendrecv_replace)(void*, int, MPI_Datatype, int, int, int, int, MPI_Comm, MPI_Status *);    int (*MPI_Type_contiguous)(int, MPI_Datatype, MPI_Datatype *);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -