diff --git a/src/STUBS/Makefile b/src/STUBS/Makefile index 38d013cbb..491e2e75c 100644 --- a/src/STUBS/Makefile +++ b/src/STUBS/Makefile @@ -1,40 +1,40 @@ # Makefile for MPI stubs - edit this for your platform SHELL = /bin/sh .IGNORE: # Files SRC = mpi.c INC = mpi.h # Definitions EXE = libmpi.a OBJ = $(SRC:.c=.o) # System-specific settings -CC = g++ -CCFLAGS = -O +CC = cc +CCFLAGS = -O # -fPIC ARCHIVE = ar ARCHFLAG = rs # Target $(EXE): $(OBJ) $(ARCHIVE) $(ARCHFLAG) $(EXE) $(OBJ) # Clean clean: rm *.o libmpi.a # Compilation rules -.cpp.o: +.c.o: $(CC) $(CCFLAGS) -c $< # Individual dependencies $(OBJ): $(INC) diff --git a/src/STUBS/mpi.cpp b/src/STUBS/mpi.c similarity index 98% rename from src/STUBS/mpi.cpp rename to src/STUBS/mpi.c index 82288fff3..ea383ef72 100644 --- a/src/STUBS/mpi.cpp +++ b/src/STUBS/mpi.c @@ -1,453 +1,446 @@ /* ----------------------------------------------------------------------- LAMMPS 2003 (July 31) - Molecular Dynamics Simulator Sandia National Laboratories, www.cs.sandia.gov/~sjplimp/lammps.html Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------ */ /* Single-processor "stub" versions of MPI routines */ #include "stdlib.h" #include "string.h" #include "stdio.h" #include "stdint.h" #include #include "mpi.h" -/* lo-level function prototypes */ - -void mpi_copy_int(void *, void *, int); -void mpi_copy_float(void *, void *, int); -void mpi_copy_double(void *, void *, int); -void mpi_copy_char(void *, void *, int); -void mpi_copy_byte(void *, void *, int); - /* lo-level data structure */ -struct { +struct _mpi_double_int { double value; int proc; -} double_int; +}; +typedef struct _mpi_double_int double_int; /* ---------------------------------------------------------------------- */ /* MPI Functions */ /* ---------------------------------------------------------------------- */ int MPI_Init(int *argc, char ***argv) {return 0;} /* ---------------------------------------------------------------------- */ int MPI_Initialized(int *flag) { *flag = 1; return 0; } /* ---------------------------------------------------------------------- */ /* return "localhost" as name of the processor */ void MPI_Get_processor_name(char *name, int *resultlen) { const char host[] = "localhost"; int len; if (!name || !resultlen) return; len = strlen(host); memcpy(name,host,len+1); *resultlen = len; return; } /* ---------------------------------------------------------------------- */ int MPI_Comm_rank(MPI_Comm comm, int *me) { *me = 0; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Comm_size(MPI_Comm comm, int *nprocs) { *nprocs = 1; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Abort(MPI_Comm comm, int errorcode) { exit(1); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Finalize() {return 0;} /* ---------------------------------------------------------------------- */ double MPI_Wtime() { double time; struct timeval tv; gettimeofday(&tv,NULL); time = 1.0 * tv.tv_sec + 1.0e-6 * tv.tv_usec; return time; } /* ---------------------------------------------------------------------- */ int MPI_Type_size(MPI_Datatype datatype, int *size) { if (datatype == MPI_INT) *size = sizeof(int); else if (datatype == MPI_FLOAT) *size = sizeof(float); else if (datatype == MPI_DOUBLE) *size = sizeof(double); else if (datatype == MPI_CHAR) *size = sizeof(char); else if (datatype == MPI_BYTE) *size = sizeof(char); else if (datatype == MPI_LONG_LONG) *size = sizeof(uint64_t); else if (datatype == MPI_DOUBLE_INT) *size = sizeof(double_int); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { printf("MPI Stub WARNING: Should not send message to self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Rsend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { printf("MPI Stub WARNING: Should not rsend message to self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status) { printf("MPI Stub WARNING: Should not recv message from self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request) { printf("MPI Stub WARNING: Should not recv message from self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Wait(MPI_Request *request, MPI_Status *status) { printf("MPI Stub WARNING: Should not wait on message from self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Waitall(int n, MPI_Request *request, MPI_Status *status) { printf("MPI Stub WARNING: Should not wait on message from self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Waitany(int count, MPI_Request *request, int *index, MPI_Status *status) { printf("MPI Stub WARNING: Should not wait on message from self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Sendrecv(void *sbuf, int scount, MPI_Datatype sdatatype, int dest, int stag, void *rbuf, int rcount, MPI_Datatype rdatatype, int source, int rtag, MPI_Comm comm, MPI_Status *status) { printf("MPI Stub WARNING: Should not send message to self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Get_count(MPI_Status *status, MPI_Datatype datatype, int *count) { printf("MPI Stub WARNING: Should not get count of message to self\n"); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out) { *comm_out = comm; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *comm_out) { *comm_out = comm; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Comm_free(MPI_Comm *comm) {return 0;} /* ---------------------------------------------------------------------- */ int MPI_Cart_create(MPI_Comm comm_old, int ndims, int *dims, int *periods, int reorder, MPI_Comm *comm_cart) { *comm_cart = comm_old; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Cart_get(MPI_Comm comm, int maxdims, int *dims, int *periods, int *coords) { dims[0] = dims[1] = dims[2] = 1; periods[0] = periods[1] = periods[2] = 1; coords[0] = coords[1] = coords[2] = 0; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Cart_shift(MPI_Comm comm, int direction, int displ, int *source, int *dest) { *source = *dest = 0; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Cart_rank(MPI_Comm comm, int *coords, int *rank) { *rank = 0; return 0; } /* ---------------------------------------------------------------------- */ int MPI_Barrier(MPI_Comm comm) {return 0;} /* ---------------------------------------------------------------------- */ int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {return 0;} /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int n; if (datatype == MPI_INT) n = count*sizeof(int); else if (datatype == MPI_FLOAT) n = count*sizeof(float); else if (datatype == MPI_DOUBLE) n = count*sizeof(double); else if (datatype == MPI_CHAR) n = count*sizeof(char); else if (datatype == MPI_BYTE) n = count*sizeof(char); else if (datatype == MPI_LONG_LONG) n = count*sizeof(uint64_t); else if (datatype == MPI_DOUBLE_INT) n = count*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) { int n; if (datatype == MPI_INT) n = count*sizeof(int); else if (datatype == MPI_FLOAT) n = count*sizeof(float); else if (datatype == MPI_DOUBLE) n = count*sizeof(double); else if (datatype == MPI_CHAR) n = count*sizeof(char); else if (datatype == MPI_BYTE) n = count*sizeof(char); else if (datatype == MPI_LONG_LONG) n = count*sizeof(uint64_t); else if (datatype == MPI_DOUBLE_INT) n = count*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ int MPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int n; if (datatype == MPI_INT) n = count*sizeof(int); else if (datatype == MPI_FLOAT) n = count*sizeof(float); else if (datatype == MPI_DOUBLE) n = count*sizeof(double); else if (datatype == MPI_CHAR) n = count*sizeof(char); else if (datatype == MPI_BYTE) n = count*sizeof(char); else if (datatype == MPI_LONG_LONG) n = count*sizeof(uint64_t); else if (datatype == MPI_DOUBLE_INT) n = count*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { int n; if (sendtype == MPI_INT) n = sendcount*sizeof(int); else if (sendtype == MPI_FLOAT) n = sendcount*sizeof(float); else if (sendtype == MPI_DOUBLE) n = sendcount*sizeof(double); else if (sendtype == MPI_CHAR) n = sendcount*sizeof(char); else if (sendtype == MPI_BYTE) n = sendcount*sizeof(char); else if (sendtype == MPI_LONG_LONG) n = sendcount*sizeof(uint64_t); else if (sendtype == MPI_DOUBLE_INT) n = sendcount*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm) { int n; if (sendtype == MPI_INT) n = sendcount*sizeof(int); else if (sendtype == MPI_FLOAT) n = sendcount*sizeof(float); else if (sendtype == MPI_DOUBLE) n = sendcount*sizeof(double); else if (sendtype == MPI_CHAR) n = sendcount*sizeof(char); else if (sendtype == MPI_BYTE) n = sendcount*sizeof(char); else if (sendtype == MPI_LONG_LONG) n = sendcount*sizeof(uint64_t); else if (sendtype == MPI_DOUBLE_INT) n = sendcount*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int n; if (datatype == MPI_INT) n = *recvcounts*sizeof(int); else if (datatype == MPI_FLOAT) n = *recvcounts*sizeof(float); else if (datatype == MPI_DOUBLE) n = *recvcounts*sizeof(double); else if (datatype == MPI_CHAR) n = *recvcounts*sizeof(char); else if (datatype == MPI_BYTE) n = *recvcounts*sizeof(char); else if (datatype == MPI_LONG_LONG) n = *recvcounts*sizeof(uint64_t); else if (datatype == MPI_DOUBLE_INT) n = *recvcounts*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { int n; if (sendtype == MPI_INT) n = sendcount*sizeof(int); else if (sendtype == MPI_FLOAT) n = sendcount*sizeof(float); else if (sendtype == MPI_DOUBLE) n = sendcount*sizeof(double); else if (sendtype == MPI_CHAR) n = sendcount*sizeof(char); else if (sendtype == MPI_BYTE) n = sendcount*sizeof(char); else if (sendtype == MPI_LONG_LONG) n = sendcount*sizeof(uint64_t); else if (sendtype == MPI_DOUBLE_INT) n = sendcount*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm) { int n; if (sendtype == MPI_INT) n = sendcount*sizeof(int); else if (sendtype == MPI_FLOAT) n = sendcount*sizeof(float); else if (sendtype == MPI_DOUBLE) n = sendcount*sizeof(double); else if (sendtype == MPI_CHAR) n = sendcount*sizeof(char); else if (sendtype == MPI_BYTE) n = sendcount*sizeof(char); else if (sendtype == MPI_LONG_LONG) n = sendcount*sizeof(uint64_t); else if (sendtype == MPI_DOUBLE_INT) n = sendcount*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } /* ---------------------------------------------------------------------- */ /* copy values from data1 to data2 */ int MPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { int n; if (sendtype == MPI_INT) n = recvcount*sizeof(int); else if (sendtype == MPI_FLOAT) n = recvcount*sizeof(float); else if (sendtype == MPI_DOUBLE) n = recvcount*sizeof(double); else if (sendtype == MPI_CHAR) n = recvcount*sizeof(char); else if (sendtype == MPI_BYTE) n = recvcount*sizeof(char); else if (sendtype == MPI_LONG_LONG) n = recvcount*sizeof(uint64_t); else if (sendtype == MPI_DOUBLE_INT) n = recvcount*sizeof(double_int); memcpy(recvbuf,sendbuf,n); return 0; } diff --git a/src/STUBS/mpi.h b/src/STUBS/mpi.h index bebf65316..7f2c5d931 100644 --- a/src/STUBS/mpi.h +++ b/src/STUBS/mpi.h @@ -1,124 +1,135 @@ /* ----------------------------------------------------------------------- LAMMPS 2003 (July 31) - Molecular Dynamics Simulator Sandia National Laboratories, www.cs.sandia.gov/~sjplimp/lammps.html Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------ */ #ifndef MPI_STUBS #define MPI_STUBS +/* use C bindings for MPI interface */ + +#ifdef __cplusplus +extern "C" { +#endif + /* Dummy defs for MPI stubs */ #define MPI_COMM_WORLD 0 #define MPI_SUCCESS 0 #define MPI_INT 1 #define MPI_FLOAT 2 #define MPI_DOUBLE 3 #define MPI_CHAR 4 #define MPI_BYTE 5 #define MPI_LONG_LONG 6 #define MPI_DOUBLE_INT 7 #define MPI_SUM 1 #define MPI_MAX 2 #define MPI_MIN 3 #define MPI_MAXLOC 4 #define MPI_MINLOC 5 #define MPI_LOR 6 #define MPI_ANY_SOURCE -1 #define MPI_Comm int #define MPI_Request int #define MPI_Datatype int #define MPI_Op int #define MPI_MAX_PROCESSOR_NAME 128 /* MPI data structs */ -struct MPI_Status { +struct _MPI_Status { int MPI_SOURCE; }; +typedef struct _MPI_Status MPI_Status; /* Function prototypes for MPI stubs */ int MPI_Init(int *argc, char ***argv); int MPI_Initialized(int *flag); void MPI_Get_processor_name(char *name, int *resultlen); int MPI_Comm_rank(MPI_Comm comm, int *me); int MPI_Comm_size(MPI_Comm comm, int *nprocs); int MPI_Abort(MPI_Comm comm, int errorcode); int MPI_Finalize(); double MPI_Wtime(); int MPI_Type_size(int, int *); int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); int MPI_Rsend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status); int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request); int MPI_Wait(MPI_Request *request, MPI_Status *status); int MPI_Waitall(int n, MPI_Request *request, MPI_Status *status); int MPI_Waitany(int count, MPI_Request *request, int *index, MPI_Status *status); int MPI_Sendrecv(void *sbuf, int scount, MPI_Datatype sdatatype, int dest, int stag, void *rbuf, int rcount, MPI_Datatype rdatatype, int source, int rtag, MPI_Comm comm, MPI_Status *status); int MPI_Get_count(MPI_Status *status, MPI_Datatype datatype, int *count); int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out); int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *comm_out); int MPI_Comm_free(MPI_Comm *comm); int MPI_Cart_create(MPI_Comm comm_old, int ndims, int *dims, int *periods, int reorder, MPI_Comm *comm_cart); int MPI_Cart_get(MPI_Comm comm, int maxdims, int *dims, int *periods, int *coords); int MPI_Cart_shift(MPI_Comm comm, int direction, int displ, int *source, int *dest); int MPI_Cart_rank(MPI_Comm comm, int *coords, int *rank); int MPI_Barrier(MPI_Comm comm); int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm); int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); int MPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); int MPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); int MPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm); int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); int MPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm); int MPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); +#ifdef __cplusplus +} +#endif + #endif