Skip to content

Commit f6aa701

Browse files
committed
Initial commit
0 parents  commit f6aa701

13 files changed

+1612
-0
lines changed

Common.mk

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Common.mk
3+
# Common make configuration options
4+
#
5+
6+
INCLUDE_DIR := $(ROOT)/include
7+
SRC_DIR := $(ROOT)/src
8+
LIB_DIR := $(ROOT)/lib
9+
DOCS_DIR := $(ROOT)/docs
10+
BUILD_DIR := $(ROOT)/build
11+
BIN_DIR := $(ROOT)/bin
12+
13+
# Compile options
14+
15+
DEBUG := -g -D__DEBUG__
16+
RELEASE := -O3
17+
PROFILE := -g -pg
18+
19+
CC := clang
20+
MPICC := mpicc
21+
CFLAGS := -Wall -I$(INCLUDE_DIR) -m64 -fPIC
22+
LDFLAGS := -L$(LIB_DIR) -lsesstype -lscribble -l
23+
24+
# Other options
25+
26+
AR := ar
27+
ARFLAGS := -cvq
28+
29+
# Other tools
30+
31+
CP := cp
32+
MAKE := make
33+
MKDIR := mkdir -p
34+
DOXYGEN := doxygen

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Makefile
3+
#
4+
5+
ROOT := .
6+
include $(ROOT)/Common.mk
7+
8+
all: libsc-mpi libsc-mpi.a
9+
10+
libsc-mpi:
11+
$(MAKE) --dir=src
12+
13+
libsc-mpi.a:
14+
$(RM) $(LIB_DIR)/$@
15+
$(MAKE) --dir=src
16+
$(AR) $(ARFLAGS) $(BUILD_DIR)/$@ $(BUILD_DIR)/*.o
17+
$(CP) -v $(BUILD_DIR)/$@ $(LIB_DIR)/$@
18+
19+
include $(ROOT)/Rules.mk

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sessc-mpi: MPI implementation of Session C runtime
2+
==================================================
3+
4+
[Session C](http://www.doc.ic.ac.uk/~cn06/sessionc) runtime support
5+
implemented in MPI.
6+
7+
Dependencies:
8+
* sessionc/libsessiontype
9+
* sessionc/libscribble
10+
* sessionc/sessc-common

Rules.mk

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Global rules
2+
#
3+
4+
.PHONY: all clean clean-all
5+
6+
$(BUILD_DIR)/%.o: %.c $(INCLUDE_DIR)/sc/%-mpi.h
7+
$(MPICC) $(CFLAGS) -c $*.c \
8+
-o $(BUILD_DIR)/$*.o
9+
10+
$(BUILD_DIR)/sc_%.so: $(BUILD_DIR)/%.o
11+
$(CC) $(CFLAGS) -shared $(BUILD_DIR)/$*.o \
12+
-o $(BUILD_DIR)/sc_$*.so
13+
14+
clean:
15+
$(RM) -r $(BUILD_DIR)/*
16+
$(RM) -r $(BIN_DIR)/*
17+
18+
clean-all: clean
19+
$(RM) $(LIB_DIR)/lib*.a

build/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.a
2+
*.o
3+
*.so

include/sc/errors.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef SC__ERRORS_H__
2+
#define SC__ERRORS_H__
3+
4+
// Successful
5+
#define SC_SUCCESS 0
6+
7+
// Protocol is invalid
8+
#define SC_ERR_PROTNVAL 1
9+
// Interaction type unsupported
10+
#define SC_ERR_ROLEINVAL 2
11+
12+
#endif // SC__ERRORS_H__

include/sc/primitives-mpi.h

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#ifndef SC__PRIMITIVES_MPI_H__
2+
#define SC__PRIMITIVES_MPI_H__
3+
/**
4+
* \file
5+
* Session C runtime library MPI backend (libsc-mpi)
6+
* communication primitives module.
7+
*/
8+
9+
#include <stdarg.h>
10+
11+
#include "sc/types-mpi.h"
12+
13+
#define SC_REQ_MGR_SEND 0
14+
#define SC_REQ_MGR_RECV 1
15+
16+
/**
17+
* \brief Send integer.
18+
*
19+
* @param[in] vals Values to send
20+
* @param[in] count Number of elements to send
21+
* @param[in] r Role to send to
22+
* @param[in] label Message label
23+
*
24+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
25+
*/
26+
int send_int(int *vals, int count, role *r, int label);
27+
28+
29+
/**
30+
* \brief Receive integer (pre-allocated).
31+
*
32+
* @param[out] vals Pointer to variable storing recevied value
33+
* @param[in] count Number of elements to receive
34+
* @param[in] r Role to receive from
35+
* @param[in] match_label Message label to match
36+
*
37+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
38+
*/
39+
int recv_int(int *vals, int count, role *r, int match_label);
40+
41+
42+
/**
43+
* \brief All-Broadcast integer.
44+
*
45+
* @param[in,out] vals Value to send
46+
* @param[in] count Number of elements to send/receive
47+
* @param[in] g Group role to broadcast to
48+
*
49+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
50+
*/
51+
int alltoall_int(int *vals, int count, role *g);
52+
53+
54+
/**
55+
* \brief Send double.
56+
*
57+
* @param[in] vals Values to send
58+
* @param[in] count Number of elements to send
59+
* @param[in] r Role to send to
60+
* @param[in] label Message label
61+
*
62+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
63+
*/
64+
int send_double(double *vals, int count, role *r, int label);
65+
66+
67+
/**
68+
* \brief Receive double (pre-allocated).
69+
*
70+
* @param[out] vals Pointer to variable storing recevied value
71+
* @param[in] count Number of elements to receive
72+
* @param[in] r Role to receive from
73+
* @param[in] match_label Message label to match
74+
*
75+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
76+
*/
77+
int recv_double(double *vals, int count, role *r, int match_label);
78+
79+
80+
/**
81+
* \brief All-Broadcast integer.
82+
*
83+
* @param[in,out] vals Value to send
84+
* @param[in] count Number of elements to send/receive
85+
* @param[in] g Group role to broadcast to
86+
*
87+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
88+
*/
89+
int alltoall_double(double *vals, int count, role *g);
90+
91+
92+
/**
93+
* \brief Barrier synchronisation.
94+
*
95+
* @param[in] s Session to perform barrier synchronisation on
96+
*
97+
* \returns SC_SUCCESS (==MPI_SUCCESS) if successful.
98+
*/
99+
int barrier(session *s, int buffersync);
100+
101+
#endif // SC__PRIMITIVES_MPI_H_

include/sc/session-mpi.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef SC__SESSION_MPI_H__
2+
#define SC__SESSION_MPI_H__
3+
/**
4+
* \file
5+
* Session C runtime library MPI backend (libsc-mpi)
6+
* session handling module.
7+
*
8+
* This includes initialisation and finalisation routines
9+
* for Session C programming.
10+
*/
11+
12+
#include "sc/types-mpi.h"
13+
14+
/**
15+
* \brief Initialise a sesssion.
16+
*
17+
* @param[in,out] argc Command line argument count
18+
* @param[in,out] argv Command line argument list
19+
* @param[out] s Pointer to session varible to create
20+
* @param[in] scribble Endpoint Scribble file path for this session
21+
* (Must be constant string)
22+
*
23+
* \returns 0 if successful, errno otherwise.
24+
*/
25+
int session_init(int *argc, char ***argv, session **s, const char *scribble);
26+
27+
28+
/**
29+
* \brief Create a role group.
30+
*
31+
* @param[in,out] s Session the new role group to create in.
32+
* @param[in] name Name of the new role group.
33+
* @param[in] nrole Number of roles to group together.
34+
* @param[in] ... The handles to existing roles to group together.
35+
*
36+
* \returns Handle to the newly created role group.
37+
*/
38+
role *session_group(session *s, const char *name, int nrole, ...);
39+
40+
41+
/**
42+
* \brief Terminate a session.
43+
*
44+
* @param[in] s Session to terminate
45+
*/
46+
void session_end(session *s);
47+
48+
49+
/**
50+
* \brief Dump content of an established session.
51+
*
52+
* @param[in] s Session to dump
53+
*/
54+
void session_dump(const session *s);
55+
56+
57+
/**
58+
* \brief Dump content of an established session (debug mode).
59+
*
60+
* @param[in] s Session to dump
61+
*/
62+
void session_ddump(const session *s);
63+
64+
65+
/**
66+
* \brief Check if a given coordinate is in range
67+
*/
68+
int sc_range(const session *s, int *from, int *to);
69+
70+
void session_rolegrp_add(session *s, char *name, int root, MPI_Comm comm, MPI_Group group);
71+
void session_role_add(session *s, char *name, int rank, MPI_Comm comm);
72+
73+
#endif // SC__SESSION_MPI_H__

include/sc/types-mpi.h

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#ifndef SC__TYPES_MPI_H__
2+
#define SC__TYPES_MPI_H__
3+
/**
4+
* \file
5+
* Session C runtime library MPI backend (libsc-mpi)
6+
* type definitions (MPI version).
7+
*/
8+
9+
#include "mpi.h"
10+
11+
#define SESSION_ROLE_P2P 0
12+
#define SESSION_ROLE_GRP 1
13+
14+
15+
/**
16+
* For request tracking.
17+
*
18+
*/
19+
typedef struct {
20+
int nsend;
21+
MPI_Request *send_reqs;
22+
void **send_bufs;
23+
} sc_req_tbl_t;
24+
25+
26+
struct role_endpoint
27+
{
28+
char *name;
29+
char *basename;
30+
int rank;
31+
MPI_Comm comm; // MPI Communicator
32+
};
33+
34+
35+
struct role_group
36+
{
37+
char *name;
38+
int root; // The only non-parametrised role
39+
MPI_Comm comm; // MPI Communicator
40+
MPI_Group group;
41+
};
42+
43+
44+
/**
45+
* An endpoint.
46+
*
47+
* Endpoint is represented as a composite type:
48+
* (1) Basic point-to-point role.
49+
* (2) Group of roles.
50+
*
51+
* Internally, role is communicator + rank,
52+
* and group is communicator.
53+
*/
54+
struct role_t
55+
{
56+
struct session_t *s;
57+
int type;
58+
59+
union {
60+
struct role_endpoint *p2p;
61+
struct role_group *grp;
62+
};
63+
};
64+
65+
typedef struct role_t role;
66+
67+
68+
/**
69+
* An endpoint session.
70+
*
71+
* Holds all information on an
72+
* instantiated endpoint protocol.
73+
*/
74+
struct session_t
75+
{
76+
int nrole; // # of roles (expanded) in session (size)
77+
role **roles; // Pointers to roles in session
78+
char *name;
79+
char *basename;
80+
int myindex;
81+
int *coords;
82+
int _myrank; // My rank, don't use this directly
83+
84+
// Lookup functions.
85+
role *(*role)(struct session_t *s, char *name); // P2P and builtin groups
86+
role *(*rolei)(struct session_t *s, char *name, int index); // Index addressing
87+
role *(*idx)(struct session_t *s, int offset); // Index offset
88+
role *(*coord)(struct session_t *s, int *offset_vec); // Vector offset
89+
role *(*param)(struct session_t *s, char *param_name); // Parametrised groups
90+
role *(*parami)(struct session_t *s, char *param_name, int index); // Parametrised groups index addressing
91+
};
92+
93+
typedef struct session_t session;
94+
95+
#endif // SC__TYPES_MPI_H__

lib/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.a

src/Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# src/Makefile
3+
#
4+
5+
ROOT := ..
6+
include $(ROOT)/Common.mk
7+
8+
all: sharedlib objs
9+
10+
objs: $(BUILD_DIR)/session.o $(BUILD_DIR)/primitives.o
11+
12+
sharedlib: $(BUILD_DIR)/sc_session.so $(BUILD_DIR)/sc_primitives.so
13+
14+
include $(ROOT)/Rules.mk

0 commit comments

Comments
 (0)