Skip to content

Commit 818f6cb

Browse files
committed
Fixed the Python ctypes interface by moving several MPWide functions into extern "C" blocks. Swig code content is now obsolete and should be removed soon.
1 parent 0b26bd5 commit 818f6cb

File tree

7 files changed

+53
-21
lines changed

7 files changed

+53
-21
lines changed

MPWide.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ struct init_tmp {
111111
static double pacing_rate = 100*1024*1024; //Pacing rate per stream. This is the maximum throughput in bytes/sec possible for each stream.
112112
static useconds_t pacing_sleeptime = useconds_t(1000000/(pacing_rate/(1.0*tcpbuf_ssize))); //Sleep time for SendRecvs in microseconds.
113113

114+
115+
extern "C" {
114116
double MPW_getPacingRate() {
115117
return pacing_rate;
116118
}
119+
117120
void MPW_setPacingRate(double rate) {
118121
if(rate == -1) {
119122
pacing_rate = -1;
@@ -125,6 +128,7 @@ struct init_tmp {
125128
LOG_INFO("Pacing enabled, rate = " << pacing_rate << " => delay = " << pacing_sleeptime << " us.");
126129
}
127130
}
131+
}
128132

129133
/* autotunePacingRate selects an appropriate pacing rate depending on the number of streams selected. */
130134
static void autotunePacingRate()
@@ -540,6 +544,14 @@ int MPW_CreatePath(std::string host, int server_side_base_port, int streams_in_p
540544
return path_id;
541545
}
542546

547+
extern "C" {
548+
int MPW_CreatePath_c (char* host, int server_side_base_port, int streams_in_path) {
549+
return MPW_CreatePath(host, server_side_base_port, streams_in_path);
550+
}
551+
}
552+
553+
554+
543555
/* Remove a stream from a path. */
544556
void EraseStream(int stream) {
545557
delete client[stream];
@@ -597,21 +609,25 @@ int MPW_DestroyPath(int path) {
597609
return 0;
598610
}
599611

600-
/* Path-based Send and Recv operations*/
601-
int MPW_DSendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int maxrecvsize, int path) {
602-
return MPW_DSendRecv(sendbuf, sendsize, recvbuf, maxrecvsize, paths[path]->streams, paths[path]->num_streams);
603-
}
612+
extern "C" {
604613

605-
int MPW_SendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int recvsize, int path) {
606-
return MPW_SendRecv(sendbuf, sendsize, recvbuf, recvsize, paths[path]->streams, paths[path]->num_streams);
607-
}
614+
/* Path-based Send and Recv operations*/
615+
int MPW_DSendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int maxrecvsize, int path) {
616+
return MPW_DSendRecv(sendbuf, sendsize, recvbuf, maxrecvsize, paths[path]->streams, paths[path]->num_streams);
617+
}
608618

609-
int MPW_Send(char* sendbuf, long long int sendsize, int path) {
610-
return MPW_SendRecv(sendbuf, sendsize, NULL, 0, paths[path]->streams, paths[path]->num_streams);
611-
}
619+
int MPW_SendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int recvsize, int path) {
620+
return MPW_SendRecv(sendbuf, sendsize, recvbuf, recvsize, paths[path]->streams, paths[path]->num_streams);
621+
}
622+
623+
int MPW_Send(char* sendbuf, long long int sendsize, int path) {
624+
return MPW_SendRecv(sendbuf, sendsize, NULL, 0, paths[path]->streams, paths[path]->num_streams);
625+
}
626+
627+
int MPW_Recv(char* recvbuf, long long int recvsize, int path) {
628+
return MPW_SendRecv(NULL, 0, recvbuf, recvsize, paths[path]->streams, paths[path]->num_streams);
629+
}
612630

613-
int MPW_Recv(char* recvbuf, long long int recvsize, int path) {
614-
return MPW_SendRecv(NULL, 0, recvbuf, recvsize, paths[path]->streams, paths[path]->num_streams);
615631
}
616632

617633

MPWide.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ int MPW_CreatePath(std::string host, int server_side_base_port, int num_streams)
4444
// Return 0 on success (negative on failure).
4545
int MPW_DestroyPath(int path);
4646

47-
int MPW_Send(char* sendbuf, long long int sendsize, int path);
48-
int MPW_Recv(char* recvbuf, long long int recvsize, int path);
49-
int MPW_SendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int recvsize, int path);
50-
// returns the size of the newly received data.
51-
int MPW_DSendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int maxrecvsize, int path);
5247

48+
extern "C" {
49+
int MPW_Send(char* sendbuf, long long int sendsize, int path);
50+
int MPW_Recv(char* recvbuf, long long int recvsize, int path);
51+
int MPW_SendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int recvsize, int path);
52+
// returns the size of the newly received data.
53+
int MPW_DSendRecv(char* sendbuf, long long int sendsize, char* recvbuf, long long int maxrecvsize, int path);
54+
}
5355

5456
/* Initialize MPWide. */
5557
int MPW_Init(std::string* url, int* server_side_ports, int* client_side_ports, int num_channels);
@@ -106,11 +108,15 @@ void MPW_Wait(int NBE_id);
106108

107109
#if MPW_PacingMode == 1
108110
/* Get and set rates for pacing data. */
109-
double MPW_getPacingRate();
110-
void MPW_setPacingRate(double rate);
111+
extern "C" {
112+
double MPW_getPacingRate();
113+
void MPW_setPacingRate(double rate);
114+
}
111115
#endif
112116

113117
extern "C" {
118+
int MPW_CreatePath_c (char* host, int server_side_base_port, int streams_in_path);
119+
114120
int MPW_Init_c (char** url, int* ports, int numsockets);
115121
int MPW_Init1_c (char* url, int port);
116122
void MPW_SendRecv1_c (char* sendbuf, long long int sendsize, char* recvbuf, long long int recvsize, int base_channel);

python/MPWTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
if len(sys.argv)>5:
4444
winsize = int(sys.argv[5])
4545

46-
path_id = MPWide.MPW_CreatePath(host,16256,size);
46+
path_id = MPWide.MPW_CreatePath_c(host,16256,size);
4747

4848
msglen = bufsize*1024
4949

python/README

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
run `sh compile.sh` to regenerate the Python interface code.
1+
The Python interface now relies on the Python ctypes module. Compilation is no longer necessary (we dropped swig), and many of the other files here now are redundant (they may be taken out soon).
2+
3+
To test it just run on the server machine:
4+
5+
python MPWTest.py 0
6+
7+
and on the client machine:
8+
9+
python MPWTest.py <ip address or hostname of the server>
10+
11+
Make sure the firewall is properly open though :).

python/build/MPWide.o

-32.8 KB
Binary file not shown.

python/build/Socket.o

-6.77 KB
Binary file not shown.
-16.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)