git reimport

This commit is contained in:
2019-03-15 13:47:54 +04:00
commit 3b461f73de
489 changed files with 1631603 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,6 @@
class Wrapper {
public static void main(String[] args) {
System.loadLibrary("message");
Main.main(args);
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,51 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.11
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
public class message {
public static int NumberOfNodes() {
return messageJNI.NumberOfNodes();
}
public static int MyNodeId() {
return messageJNI.MyNodeId();
}
public static void PutChar(int target, char value) {
messageJNI.PutChar(target, value);
}
public static void PutInt(int target, int value) {
messageJNI.PutInt(target, value);
}
public static void PutLL(int target, long value) {
messageJNI.PutLL(target, value);
}
public static void Send(int target) {
messageJNI.Send(target);
}
public static int Receive(int source) {
return messageJNI.Receive(source);
}
public static char GetChar(int source) {
return messageJNI.GetChar(source);
}
public static int GetInt(int source) {
return messageJNI.GetInt(source);
}
public static long GetLL(int source) {
return messageJNI.GetLL(source);
}
}

Binary file not shown.

View File

@@ -0,0 +1,21 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.11
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
public class messageJNI {
public final static native int NumberOfNodes();
public final static native int MyNodeId();
public final static native void PutChar(int jarg1, char jarg2);
public final static native void PutInt(int jarg1, int jarg2);
public final static native void PutLL(int jarg1, long jarg2);
public final static native void Send(int jarg1);
public final static native int Receive(int jarg1);
public final static native char GetChar(int jarg1);
public final static native int GetInt(int jarg1);
public final static native long GetLL(int jarg1);
}

View File

@@ -0,0 +1,158 @@
#include "message.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "zeus.h"
#define ZEUS_WRAP(s) zeus_##s
#define DEBUG 1
#define MAX_MESSAGE_SIZE (8 * (1 << 20))
#define MAX_MACHINES 100
static void Die(const char* s) {
fputs(s, stderr);
exit(20);
}
int NumberOfNodes() { return ZEUS_WRAP(NumberOfNodes)(); }
int MyNodeId() { return ZEUS_WRAP(MyNodeId)(); }
static void CheckNodeId(int node) {
if (!DEBUG) return;
if (node < 0 || node >= NumberOfNodes()) Die("Incorrect machine number");
}
typedef struct Buffer {
char* buffer;
int size;
int pos; // for input buffers next byte to be read. for output buffers next
// byte to be written.
} Buffer;
static int Empty(Buffer* buffer) { return buffer->pos >= buffer->size; }
static unsigned char GetRawByte(Buffer* buf) {
if (Empty(buf)) {
Die("Read past the end of the message");
}
char r = buf->buffer[buf->pos++];
if (Empty(buf)) {
free(buf->buffer);
buf->buffer = NULL;
buf->pos = 0;
buf->size = 0;
}
return r;
}
static void PutRawByte(Buffer* buffer, unsigned char byte) {
if (buffer->pos >= buffer->size) {
buffer->size = 2 * buffer->size;
if (buffer->size < 128) buffer->size = 128;
buffer->buffer = (char*)realloc(buffer->buffer, buffer->size);
assert(buffer->buffer);
}
buffer->buffer[buffer->pos++] = byte;
}
static Buffer incoming_buffers[MAX_MACHINES];
static Buffer outgoing_buffers[MAX_MACHINES];
char recv_buffer[MAX_MESSAGE_SIZE];
int Receive(int source) {
if (source != -1) CheckNodeId(source);
if (DEBUG && source == -1) {
int i;
for (i = 0; i < ZEUS_WRAP(NumberOfNodes)(); i++) {
if (!Empty(&incoming_buffers[i]))
Die("Cannot call Receive(-1) if any message is unread.");
}
}
ZEUS_WRAP(MessageInfo) mi =
ZEUS_WRAP(Receive)(source, recv_buffer, sizeof(recv_buffer));
Buffer* buf = &incoming_buffers[mi.sender_id];
if (DEBUG && !Empty(buf))
Die("Receive()'ed a message when the previous one wasn't consumed.");
if (buf->buffer != NULL) {
free(buf->buffer);
buf->buffer = NULL;
}
buf->buffer = (char*)malloc(mi.length);
assert(buf->buffer);
memcpy(buf->buffer, recv_buffer, mi.length);
buf->pos = 0;
buf->size = mi.length;
return mi.sender_id;
}
#define kChar 14
#define kInt 15
#define kLL 16
static void GetTag(int source, int expected) {
if (!DEBUG) return;
int tag = GetRawByte(&incoming_buffers[source]);
if (tag != expected) Die("Type mismatch between read and requested types");
}
int GetInt(int source) {
CheckNodeId(source);
GetTag(source, kInt);
int result = 0, i;
for (i = 0; i < 4; i++)
result |= (int)(GetRawByte(&incoming_buffers[source])) << (8 * i);
return result;
}
void PutInt(int target, int value) {
CheckNodeId(target);
if (DEBUG) PutRawByte(&outgoing_buffers[target], kInt);
int i;
for (i = 0; i < 4; i++)
PutRawByte(&outgoing_buffers[target], (0xff & (value >> (8 * i))));
}
long long GetLL(int source) {
CheckNodeId(source);
GetTag(source, kLL);
long long result = 0;
int i;
for (i = 0; i < 8; i++)
result |= (long long)(GetRawByte(&incoming_buffers[source])) << (8 * i);
return result;
}
void PutLL(int target, long long value) {
CheckNodeId(target);
if (DEBUG) PutRawByte(&outgoing_buffers[target], kLL);
int i;
for (i = 0; i < 8; i++)
PutRawByte(&outgoing_buffers[target], (0xff & (value >> (8 * i))));
}
char GetChar(int source) {
CheckNodeId(source);
GetTag(source, kChar);
return GetRawByte(&incoming_buffers[source]);
}
void PutChar(int target, char value) {
CheckNodeId(target);
if (DEBUG) PutRawByte(&outgoing_buffers[target], kChar);
PutRawByte(&outgoing_buffers[target], value);
}
void Send(int target) {
CheckNodeId(target);
Buffer* buffer = &outgoing_buffers[target];
if (buffer->pos > (int)sizeof(recv_buffer)) Die("Message too long");
ZEUS_WRAP(Send)(target, buffer->buffer, buffer->pos);
free(buffer->buffer);
buffer->buffer = NULL;
buffer->pos = buffer->size = 0;
}

Binary file not shown.

View File

@@ -0,0 +1,335 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.11
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */
#define SWIGJAVA
/* -----------------------------------------------------------------------------
* This section contains generic SWIG labels for method/variable
* declarations/attributes, and other compiler dependent labels.
* ----------------------------------------------------------------------------- */
/* template workaround for compilers that cannot correctly implement the C++ standard */
#ifndef SWIGTEMPLATEDISAMBIGUATOR
# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
# define SWIGTEMPLATEDISAMBIGUATOR template
# elif defined(__HP_aCC)
/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
# define SWIGTEMPLATEDISAMBIGUATOR template
# else
# define SWIGTEMPLATEDISAMBIGUATOR
# endif
#endif
/* inline attribute */
#ifndef SWIGINLINE
# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
# define SWIGINLINE inline
# else
# define SWIGINLINE
# endif
#endif
/* attribute recognised by some compilers to avoid 'unused' warnings */
#ifndef SWIGUNUSED
# if defined(__GNUC__)
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
# define SWIGUNUSED __attribute__ ((__unused__))
# else
# define SWIGUNUSED
# endif
# elif defined(__ICC)
# define SWIGUNUSED __attribute__ ((__unused__))
# else
# define SWIGUNUSED
# endif
#endif
#ifndef SWIG_MSC_UNSUPPRESS_4505
# if defined(_MSC_VER)
# pragma warning(disable : 4505) /* unreferenced local function has been removed */
# endif
#endif
#ifndef SWIGUNUSEDPARM
# ifdef __cplusplus
# define SWIGUNUSEDPARM(p)
# else
# define SWIGUNUSEDPARM(p) p SWIGUNUSED
# endif
#endif
/* internal SWIG method */
#ifndef SWIGINTERN
# define SWIGINTERN static SWIGUNUSED
#endif
/* internal inline SWIG method */
#ifndef SWIGINTERNINLINE
# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
#endif
/* exporting methods */
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
# ifndef GCC_HASCLASSVISIBILITY
# define GCC_HASCLASSVISIBILITY
# endif
#endif
#ifndef SWIGEXPORT
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# if defined(STATIC_LINKED)
# define SWIGEXPORT
# else
# define SWIGEXPORT __declspec(dllexport)
# endif
# else
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
# define SWIGEXPORT __attribute__ ((visibility("default")))
# else
# define SWIGEXPORT
# endif
# endif
#endif
/* calling conventions for Windows */
#ifndef SWIGSTDCALL
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# define SWIGSTDCALL __stdcall
# else
# define SWIGSTDCALL
# endif
#endif
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
# define _CRT_SECURE_NO_DEPRECATE
#endif
/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
# define _SCL_SECURE_NO_DEPRECATE
#endif
/* Fix for jlong on some versions of gcc on Windows */
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
typedef long long __int64;
#endif
/* Fix for jlong on 64-bit x86 Solaris */
#if defined(__x86_64)
# ifdef _LP64
# undef _LP64
# endif
#endif
#include <jni.h>
#include <stdlib.h>
#include <string.h>
/* Support for throwing Java exceptions */
typedef enum {
SWIG_JavaOutOfMemoryError = 1,
SWIG_JavaIOException,
SWIG_JavaRuntimeException,
SWIG_JavaIndexOutOfBoundsException,
SWIG_JavaArithmeticException,
SWIG_JavaIllegalArgumentException,
SWIG_JavaNullPointerException,
SWIG_JavaDirectorPureVirtual,
SWIG_JavaUnknownError
} SWIG_JavaExceptionCodes;
typedef struct {
SWIG_JavaExceptionCodes code;
const char *java_exception;
} SWIG_JavaExceptions_t;
static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
jclass excep;
static const SWIG_JavaExceptions_t java_exceptions[] = {
{ SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
{ SWIG_JavaIOException, "java/io/IOException" },
{ SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
{ SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
{ SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
{ SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
{ SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
{ SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
{ SWIG_JavaUnknownError, "java/lang/UnknownError" },
{ (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
};
const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
while (except_ptr->code != code && except_ptr->code)
except_ptr++;
(*jenv)->ExceptionClear(jenv);
excep = (*jenv)->FindClass(jenv, except_ptr->java_exception);
if (excep)
(*jenv)->ThrowNew(jenv, excep, msg);
}
/* Contract support */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
extern int NumberOfNodes();
extern int MyNodeId();
extern void PutChar(int target, char value);
extern void PutInt(int target, int value);
extern void PutLL(int target, long long value);
extern void Send(int target);
extern int Receive(int source);
extern char GetChar(int source);
extern int GetInt(int source);
extern long long GetLL(int source);
#ifdef __cplusplus
extern "C" {
#endif
SWIGEXPORT jint JNICALL Java_messageJNI_NumberOfNodes(JNIEnv *jenv, jclass jcls) {
jint jresult = 0 ;
int result;
(void)jenv;
(void)jcls;
result = (int)NumberOfNodes();
jresult = (jint)result;
return jresult;
}
SWIGEXPORT jint JNICALL Java_messageJNI_MyNodeId(JNIEnv *jenv, jclass jcls) {
jint jresult = 0 ;
int result;
(void)jenv;
(void)jcls;
result = (int)MyNodeId();
jresult = (jint)result;
return jresult;
}
SWIGEXPORT void JNICALL Java_messageJNI_PutChar(JNIEnv *jenv, jclass jcls, jint jarg1, jchar jarg2) {
int arg1 ;
char arg2 ;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
arg2 = (char)jarg2;
PutChar(arg1,arg2);
}
SWIGEXPORT void JNICALL Java_messageJNI_PutInt(JNIEnv *jenv, jclass jcls, jint jarg1, jint jarg2) {
int arg1 ;
int arg2 ;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
arg2 = (int)jarg2;
PutInt(arg1,arg2);
}
SWIGEXPORT void JNICALL Java_messageJNI_PutLL(JNIEnv *jenv, jclass jcls, jint jarg1, jlong jarg2) {
int arg1 ;
long long arg2 ;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
arg2 = (long long)jarg2;
PutLL(arg1,arg2);
}
SWIGEXPORT void JNICALL Java_messageJNI_Send(JNIEnv *jenv, jclass jcls, jint jarg1) {
int arg1 ;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
Send(arg1);
}
SWIGEXPORT jint JNICALL Java_messageJNI_Receive(JNIEnv *jenv, jclass jcls, jint jarg1) {
jint jresult = 0 ;
int arg1 ;
int result;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
result = (int)Receive(arg1);
jresult = (jint)result;
return jresult;
}
SWIGEXPORT jchar JNICALL Java_messageJNI_GetChar(JNIEnv *jenv, jclass jcls, jint jarg1) {
jchar jresult = 0 ;
int arg1 ;
char result;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
result = (char)GetChar(arg1);
jresult = (jchar)result;
return jresult;
}
SWIGEXPORT jint JNICALL Java_messageJNI_GetInt(JNIEnv *jenv, jclass jcls, jint jarg1) {
jint jresult = 0 ;
int arg1 ;
int result;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
result = (int)GetInt(arg1);
jresult = (jint)result;
return jresult;
}
SWIGEXPORT jlong JNICALL Java_messageJNI_GetLL(JNIEnv *jenv, jclass jcls, jint jarg1) {
jlong jresult = 0 ;
int arg1 ;
long long result;
(void)jenv;
(void)jcls;
arg1 = (int)jarg1;
result = (long long)GetLL(arg1);
jresult = (jlong)result;
return jresult;
}
#ifdef __cplusplus
}
#endif

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,147 @@
#include "zeus.h"
#include <assert.h>
#include <stdio.h>
#include <time.h>
#ifdef WIN32
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#endif
#define MAX_MESSAGE_SIZE (8*1024*1024)
#define MAGIC 1736434764
#define SEND 3
#define RECV 4
static int initialized;
static FILE* cmdin;
static FILE* cmdout;
static int nof_nodes;
static int node_id;
static unsigned char ReadByte() {
unsigned char c;
assert(fread(&c, 1, 1, cmdin) == 1);
return c;
}
static int ReadInt() {
int v = 0;
int i;
for(i=0;i<4;i++)
v |= (int)(ReadByte()) << (8 * i);
return v;
}
static void WriteByte(unsigned char c) {
assert(fwrite(&c, 1, 1, cmdout) == 1);
}
static void WriteInt(int v) {
int i;
for(i=0;i<4;i++)
WriteByte((v >> (8 * i)) & 0xff);
}
#ifdef WIN32
static int GetFd(int dir) {
const char* names[2] = { "ZSHANDLE_IN", "ZSHANDLE_OUT" };
char* handle_s = getenv(names[dir]);
if (handle_s == NULL)
return -1;
int handle = atoi(handle_s);
return _open_osfhandle(handle, dir == 0 ? _O_RDONLY : _O_APPEND);
}
#else
static int GetFd(int dir) {
return 3 + dir;
}
#endif
static void Init() {
if (initialized)
return;
cmdin = fdopen(GetFd(0), "r");
assert(cmdin != NULL);
cmdout = fdopen(GetFd(1), "w");
assert(cmdout != NULL);
if (ReadInt() != MAGIC)
assert(0);
nof_nodes = ReadInt();
assert(1 <= nof_nodes);
node_id = ReadInt();
assert(0 <= node_id && node_id < nof_nodes);
initialized = 1;
}
int ZEUS(NumberOfNodes)() {
Init();
return nof_nodes;
}
ZEUS(NodeId) ZEUS(MyNodeId)() {
Init();
return node_id;
}
#ifdef WIN32
static int CurrentTime() {
HANDLE me = GetCurrentProcess();
FILETIME lpCreationTime, lpExitTime, lpKernelTime, lpUserTime;
GetProcessTimes(me, &lpCreationTime, &lpExitTime, &lpKernelTime, &lpUserTime);
ULONGLONG cTime =
lpUserTime.dwLowDateTime +
lpKernelTime.dwLowDateTime +
(((ULONGLONG) lpUserTime.dwHighDateTime) << 32) +
(((ULONGLONG) lpKernelTime.dwHighDateTime) << 32);
return (int)(cTime / 10000);
}
#else
static int CurrentTime() {
static int warned;
int time = clock();
if (time == -1) {
if (!warned) {
warned = 1;
fprintf(stderr, "Warning: clock() returned -1; time measurements will be bogus.\n");
}
return 0;
}
return time * 1000 / CLOCKS_PER_SEC;
}
#endif
void ZEUS(Send)(ZEUS(NodeId) target, const char* message, int bytes) {
Init();
assert(target >= 0 && target < nof_nodes);
assert(bytes <= MAX_MESSAGE_SIZE);
int i;
WriteByte(SEND);
WriteInt(target);
WriteInt(CurrentTime());
WriteInt(bytes);
for(i=0;i<bytes;i++)
WriteByte(message[i]);
fflush(cmdout);
}
ZEUS(MessageInfo) ZEUS(Receive)(ZEUS(NodeId) source, char* buffer, int buffer_size) {
Init();
assert(source >= -1 && source < nof_nodes);
ZEUS(MessageInfo) mi;
int i;
WriteByte(RECV);
WriteInt(source);
WriteInt(CurrentTime());
fflush(cmdout);
if (ReadInt() != MAGIC + 1)
assert(0);
mi.sender_id = ReadInt();
mi.length = ReadInt();
assert(mi.length <= buffer_size);
for(i=0;i<mi.length;i++)
buffer[i] = ReadByte();
return mi;
}

Binary file not shown.