Reorganized directory structure
authorRobert Brunner <rbrunner@uiuc.edu>
Fri, 2 Jun 1995 17:40:29 +0000 (17:40 +0000)
committerRobert Brunner <rbrunner@uiuc.edu>
Fri, 2 Jun 1995 17:40:29 +0000 (17:40 +0000)
12 files changed:
src/ck-perf/charmreplay.c [new file with mode: 0644]
src/ck-perf/perf-none.c [new file with mode: 0644]
src/ck-perf/perf-proj.c [new file with mode: 0644]
src/ck-perf/perf-recd.c [new file with mode: 0644]
src/ck-perf/perf-repl.c [new file with mode: 0644]
src/ck-perf/perf-sum.c [new file with mode: 0644]
src/ck-perf/perfio.c [new file with mode: 0644]
src/ck-perf/performance.h [new file with mode: 0644]
src/conv-core/convcore.c [new file with mode: 0644]
src/conv-core/converse.h [new file with mode: 0644]
src/conv-core/fifo.c [new file with mode: 0644]
src/conv-core/internal.h [new file with mode: 0644]

diff --git a/src/ck-perf/charmreplay.c b/src/ck-perf/charmreplay.c
new file mode 100644 (file)
index 0000000..ceba16c
--- /dev/null
@@ -0,0 +1,381 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.1  1994/10/14  21:00:47  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <string.h>
+
+#define GOOD 0
+
+#define DEBUG 1
+#define PROJECTIONS 2
+
+#define MAXLENGTH 1024
+
+/** Needs to be changed in altered in chare.h **/
+#define NewChareMsg             0
+#define ForChareMsg             1
+#define BocInitMsg              2
+#define BocMsg                  3
+#define TerminateToZero         4
+#define TerminateSys            5
+#define InitCountMsg            6
+#define ReadVarMsg              7
+#define ReadMsgMsg              8
+#define BroadcastBocMsg         9
+#define DynamicBocInitMsg       10
+#define LdbMsg                  12
+#define VidMsg                  13
+#define QdBocMsg                14
+#define QdBroadcastBocMsg       15
+#define AccInitMsg              21
+#define MonoInitMsg             22
+
+
+
+#define  CREATION           1
+#define  BEGIN_PROCESSING   2
+#define  END_PROCESSING     3
+#define  ENQUEUE            4
+#define  DEQUEUE            5
+#define  BEGIN_COMPUTATION  6
+#define  END_COMPUTATION    7
+#define  BEGIN_INTERRUPT    8
+#define  END_INTERRUPT      9
+#define  INSERT             10
+#define  DELETE             11
+#define  FIND               12
+
+
+
+#define HASH_TABLE_SIZE 2591
+#define HashMap(a, b) ((20011*a+20021*b) % HASH_TABLE_SIZE)
+
+typedef struct entry {
+       int pe, event, destination; 
+       struct entry *next;
+} ENTRY;
+
+ENTRY *hash_table[HASH_TABLE_SIZE];
+
+int number_pe;
+char *filename, *pwd;
+int TotalChares, TotalEps, TotalMsgs, TotalPseudos;
+
+InsertDestination(pe, event, destination)
+int pe, event, destination;
+{
+       ENTRY *current;
+       int index = HashMap(pe, event);
+
+       current = (ENTRY *) malloc(sizeof(ENTRY));
+       current->pe = pe;
+       current->event = event;
+       current->destination = destination;
+       current->next = hash_table[index];
+       hash_table[index] = current;
+}
+
+
+
+FindDestination(event, pe)
+int event, pe;
+{
+       int index = HashMap(pe, event);
+       ENTRY *current = hash_table[index];
+
+       while (current != 0)
+               if (current->pe==pe && current->event==event)
+                       return current->destination;
+               else
+                       current = current->next;
+       printf("*** ERROR *** Cannot determine destination for %d, %d\n",
+                               pe, event);
+       return -1;
+}
+
+
+
+main(argc, argv)
+int argc;
+char *argv[];
+{ 
+       int     i, j;
+       FILE *fp;
+       int mode = -1;
+       char template[1000];
+       char *getcwd(), *mktemp();
+       char name[MAXLENGTH], what[MAXLENGTH], pathname[MAXLENGTH];
+
+       filename = argv[1];
+       read_in_state_file(filename);
+       strcpy(template,  ".tempXXXXXX");
+
+       if ((pwd = getcwd(pathname, MAXLENGTH)) == 0) printf("ERROR: %s\n", pathname);
+
+       for (i=0; i<HASH_TABLE_SIZE; i++)
+               hash_table[i] = 0;
+
+       for (i=0; i<number_pe; i++)
+       {
+               sprintf(name, "%s/%s.%d.log", pathname, filename, i);
+               fp = fopen(name, "r");
+               if (fp == 0) {
+                       printf("*** ERROR *** Unable to open log file %s\n", name);
+                       return GOOD;
+               }
+               fscanf(fp, "%s", what);
+               if (!strcmp(what, "DEBUG-REPLAY") || 
+                       !strcmp(what, "PROJECTIONS-REPLAY")) {
+                               fclose(fp);
+                               return GOOD;
+               }
+               if (!strcmp(what, "DEBUG-RECORD")) 
+                       mode = DEBUG;
+               else if (!strcmp(what, "PROJECTIONS-RECORD")) 
+                       mode = PROJECTIONS;
+               else 
+                       printf("*** ERROR *** Unknown type of log file %s\n", name);
+               
+               if (mode==DEBUG) read_in_debug_file(fp, i);
+               else if (mode==PROJECTIONS) read_in_projections_file(fp, i);
+               fclose(fp);
+       }
+
+       mktemp(template);
+       for (i=0; i<number_pe; i++)
+       {
+               FILE    *fp1, *fp2;
+               char    command[MAXLENGTH];
+
+               sprintf(name, "%s/%s.%d.log", pathname, filename, i);
+               fp1 = fopen(name, "r");
+               if (fp1 == 0) {
+                       printf("*** ERROR *** Unable to open log file %s\n", name);
+                       return GOOD;
+               }
+
+               fp2 = fopen(template, "w");
+               if (fp2 == 0) {
+                       printf("*** ERROR *** Unable to open log file %s\n", 
+                                       template);
+                       return GOOD;
+               }
+               
+               if (mode==DEBUG) write_out_debug_file(fp1, fp2, i);
+               else if (mode==PROJECTIONS) write_out_projections_file(fp1, fp2, i);
+               fclose(fp1);
+               fclose(fp2);
+
+               sprintf(name, "%s/%s.%d.rpy", pathname, filename, i);
+               sprintf(command, "cp %s %s", template, name);
+               system(command);
+       }
+       return GOOD;
+}
+
+
+/*************************************************************************/
+/** Read in state file information.                                                                            **/
+/*************************************************************************/
+read_in_state_file(filename)
+char *filename;
+{
+       FILE *fp;
+       int done;
+       int id, chareid,msgid;
+       char type[1000], name[1000];
+       int size, msg_index, pseudo_index, pseudo_type;
+
+       /*****************************************************************/
+       /** Get the file name and open it.              **/
+       /*****************************************************************/
+       sprintf(name, "%s.sts", filename);
+       fp = fopen(name, "r");
+       if (fp == 0)
+               printf("*** ERROR *** Unable to open log file %s\n", name);
+       done = 0;
+       while (!done)
+       {
+               fscanf(fp, "%s", type);
+               if (!strcmp(type, "ENTRY"))
+                       fscanf(fp, "%d %s %d %d", &id, name, &chareid, &msgid);
+               else if (!strcmp(type, "CHARE") || (!strcmp(type, "BOC")))
+                       fscanf(fp, "%d %s", &id, name);
+               else if (!strcmp(type, "MACHINE"))
+                       fscanf(fp, "%s", name);
+               else if (!strcmp(type, "PROCESSORS"))   
+                       fscanf(fp, "%d", &number_pe);
+               else if (!strcmp(type, "MESSAGE"))      
+                       fscanf(fp, "%d %d", &msg_index, &size);
+               else if (!strcmp(type, "PSEUDO"))       
+                       fscanf(fp, "%d %d %s", &pseudo_index, &pseudo_type, name);
+               else if (!strcmp(type, "TOTAL_CHARES")) 
+                       fscanf(fp, "%d", &TotalChares);
+               else if (!strcmp(type, "TOTAL_EPS"))    
+                       fscanf(fp, "%d", &TotalEps);
+               else if (!strcmp(type, "TOTAL_MSGS"))   
+                       fscanf(fp, "%d", &TotalMsgs);
+               else if (!strcmp(type, "TOTAL_PSEUDOS"))        
+                       fscanf(fp, "%d", &TotalPseudos);
+               else if (!strcmp(type, "END"))
+                       done = 1;
+       }
+}
+
+
+/*************************************************************************/
+/** This function is used to read in a log file and generate the display**/
+/** information for it.                                                        **/
+/*************************************************************************/
+
+read_in_debug_file(fp, me)
+FILE *fp;
+int me;
+{
+       int i;
+       unsigned int time;
+       int type, mtype, entry, event, dest, pe;
+
+       /*********************************************************/
+       /** Read in the entries and process them.               **/
+       /*********************************************************/
+       while (read_in_debug_line(fp, 0, &type, &mtype, &entry, &time, &event, 
+                                                               &dest, &pe) != EOF) {
+               /*************************************************/
+               /** Perform appropriate actions for this entry. **/
+               /*************************************************/
+               switch (type)
+               {
+               case BEGIN_PROCESSING:
+                       if (mtype==NewChareMsg) InsertDestination(pe, event, me);
+                       break;
+
+               case END_COMPUTATION: 
+                       break;
+               }
+       }
+}
+
+
+write_out_debug_file(fp1, fp2, me)
+       FILE *fp1, *fp2;
+       int me;
+{
+       int i;
+       char what[100];
+       unsigned int time;
+       int type, mtype, entry, event, pe, dest;
+
+       fscanf(fp1, "%s", what);
+       fprintf(fp2, "DEBUG-REPLAY\n");
+
+       /*********************************************************/
+       /** Read in the entries and process them.               **/
+       /*********************************************************/
+       while (read_in_debug_line(fp1, 0, &type, &mtype, &entry, &time, &event, 
+                                                               &dest, &pe) != EOF) {
+
+               write_out_debug_line(fp2, type, mtype, entry, time, event, pe);
+               switch (type) {
+
+               case CREATION:
+                       if (mtype==NewChareMsg) 
+                               fprintf(fp2, " %d", FindDestination(event, me));
+                       break;
+
+               case END_COMPUTATION:
+                       break;
+               }
+               fprintf(fp2, "\n");
+       }
+}
+
+
+/*************************************************************************/
+/** This function is used to read in a log file and generate the display**/
+/** information for it.                                                        **/
+/*************************************************************************/
+
+read_in_projections_file(fp, me)
+       FILE *fp;
+       int me;
+{
+       unsigned int time;
+       int type, mtype, entry, event, pe, dest;
+
+       /*********************************************************/
+       /** Read in the entries and process them.               **/
+       /*********************************************************/
+       while (read_in_projections_data(fp, 0, &type, &mtype, &entry, &time, 
+                                                                       &event, &dest, &pe) != EOF) {
+               /*************************************************/
+               /** Perform appropriate actions for this entry. **/
+               /*************************************************/
+               switch (type)
+               {
+               case BEGIN_PROCESSING:
+                       if (mtype == NewChareMsg) InsertDestination(pe, event, me);
+                       break;
+
+               case END_COMPUTATION:
+                       break;
+               }
+       }
+}
+
+write_out_projections_file(fp1, fp2, me)
+       FILE *fp1, *fp2;
+       int me;
+{
+       char what[100];
+       unsigned int time;
+       int type, mtype, entry, event, pe, dest;
+
+
+       fscanf(fp1, "%s", what);
+       fprintf(fp2, "PROJECTIONS-REPLAY\n");
+
+       /*********************************************************/
+       /** Read in the entries and process them.               **/
+       /*********************************************************/
+       while (read_in_projections_data(fp1, 0, &type, &mtype, &entry, &time, 
+                                                                       &event, &dest, &pe) != EOF) {
+               write_out_projections_line(fp2, type, mtype, entry, time, event, pe);
+
+               /*************************************************/
+               /** Perform appropriate actions for this entry. **/
+               /*************************************************/
+               switch (type)
+               {
+               case CREATION:
+                       if (mtype==NewChareMsg)
+                               fprintf(fp2, " %d", FindDestination(event, pe));
+                       break;
+
+               case END_COMPUTATION:
+                       break;
+
+               }
+               fprintf(fp2, "\n");
+       }
+}
diff --git a/src/ck-perf/perf-none.c b/src/ck-perf/perf-none.c
new file mode 100644 (file)
index 0000000..f48b700
--- /dev/null
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.2  1995/04/02  00:49:19  sanjeev
+ * changes for separating Converse
+ *
+ * Revision 1.1  1994/11/03  17:40:00  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+static char ident[] = "@(#)$Header$";
+
+/*
+#include "chare.h"
+*/
+
+int RecdPerfMsg = 1;
+
+program_name(s,m) char *s, *m; {}
+
+log_init(){}
+
+trace_creation(msg_type,entry,envelope)
+int msg_type, entry;
+void *envelope;
+{}
+
+trace_begin_execute(envelope)
+void *envelope;
+{}
+
+trace_end_execute(id,msg_type,entry)
+int id, msg_type, entry;
+{}
+
+trace_enqueue(envelope)
+void *envelope;
+{}
+
+trace_dequeue(envelope)
+void *envelope;
+{}
+
+trace_table(type,tbl,key,pe)
+int type,tbl,key,pe;
+{}
+
+
+send_log() {}
+
+CollectPerfFromNodes(msg, data)
+char msg, data;
+{}
+
+close_log(){}
+
+void PrintStsFile(str)
+char *str ;
+{
+}
diff --git a/src/ck-perf/perf-proj.c b/src/ck-perf/perf-proj.c
new file mode 100644 (file)
index 0000000..27756bb
--- /dev/null
@@ -0,0 +1,384 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.3  1995/04/13  20:55:09  sanjeev
+ * Changed Mc to Cmi
+ *
+ * Revision 1.2  1994/12/02  00:02:37  sanjeev
+ * interop stuff
+ *
+ * Revision 1.1  1994/11/03  17:40:02  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+static char ident[] = "@(#)$Header$";
+/* program to log the trace information */
+
+#include <stdio.h>
+#include <string.h>
+#include "chare.h"
+#include "globals.h"
+#define MAIN_PERF
+#include "performance.h"
+#undef MAIN_PERF
+
+char *pgm, *machine;
+int RecdPerfMsg = 1;
+char *log_file_name;           /* log file name        */
+int current_event = 0;
+LOGSTR logbuf[MAXLOGBUFSIZE];
+
+int  logcnt;                   /* no. of log entries   */
+int iteration;
+
+int store_event, store_pe;
+unsigned int store_time;
+
+int begin_pe = -1, begin_event = -1;
+unsigned int begin_processing_time = -1;
+
+
+FILE *state_file_fd;
+
+extern int TotalChares;
+
+
+void PrintStsFile(str)
+char *str ;
+{
+       fprintf(state_file_fd,"%s",str) ;
+}
+
+
+/**********All the trace functions *****************/
+trace_creation(msg_type, entry, envelope)
+int msg_type, entry;
+ENVELOPE *envelope;
+{
+       int i;
+       iteration = 1;
+       if (msg_type == BocInitMsg ||
+               msg_type == BroadcastBocMsg || 
+               msg_type == QdBroadcastBocMsg ||
+               msg_type==DynamicBocInitMsg)
+                       iteration = CmiNumPe();
+
+       SetEnv_event(envelope, current_event);
+       SetEnv_pe(envelope, CmiMyPe());
+       for (i=0; i<iteration; i++)
+               add_to_buffer(CREATION, msg_type, entry, CkUTimer(), 
+                                       GetEnv_event(envelope)+i, GetEnv_pe(envelope));
+       current_event += iteration;     
+}
+
+trace_begin_execute(envelope)
+ENVELOPE *envelope;
+{
+       int msg_type = GetEnv_msgType(envelope);
+       begin_event = GetEnv_event(envelope);
+       if (msg_type ==  BocInitMsg ||
+               msg_type == BroadcastBocMsg || 
+               msg_type == QdBroadcastBocMsg ||
+               msg_type==DynamicBocInitMsg)
+                       begin_event += CmiMyPe();
+       begin_pe = GetEnv_pe(envelope);
+       add_to_buffer(BEGIN_PROCESSING, msg_type, GetEnv_EP(envelope), CkUTimer(),
+                                begin_event, begin_pe);
+}
+
+trace_end_execute(id, msg_type, entry)
+int id, msg_type, entry;
+{
+       add_to_buffer(END_PROCESSING, msg_type, entry, CkUTimer(),
+                                               begin_event, begin_pe);
+}
+
+trace_begin_charminit() 
+{
+    int *msg;
+    ENVELOPE *envelope;
+    msg = (int *) CkAllocMsg(sizeof(int));
+    envelope = (ENVELOPE *) ENVELOPE_UPTR(msg);
+    trace_creation(NewChareMsg, -1, envelope);
+    store_pe = GetEnv_pe(envelope);
+    store_event = GetEnv_event(envelope);
+       add_to_buffer(BEGIN_PROCESSING, NewChareMsg, -1, CkUTimer(),
+                                       store_event, store_pe);
+
+}
+
+trace_end_charminit() 
+{
+    add_to_buffer(END_PROCESSING, NewChareMsg, -1, CkUTimer(),
+                                       store_event, store_pe);
+}
+
+
+trace_enqueue(envelope)
+ENVELOPE *envelope;
+{
+       int add=0;
+       int msg_type = GetEnv_msgType(envelope);
+    if (msg_type ==  BocInitMsg || msg_type == BroadcastBocMsg ||
+        msg_type == QdBroadcastBocMsg || msg_type==DynamicBocInitMsg)
+            add = CmiMyPe();
+
+       add_to_buffer(ENQUEUE, GetEnv_msgType(envelope), GetEnv_EP(envelope),
+                                       CkUTimer(), 
+                                       GetEnv_event(envelope)+add, GetEnv_pe(envelope));
+}
+
+trace_dequeue(envelope)
+ENVELOPE *envelope;
+{
+       int add=0;
+       int msg_type = GetEnv_msgType(envelope);
+    if (msg_type ==  BocInitMsg || msg_type == BroadcastBocMsg ||
+        msg_type == QdBroadcastBocMsg || msg_type==DynamicBocInitMsg)
+            add = CmiMyPe();
+
+       add_to_buffer(DEQUEUE, GetEnv_msgType(envelope), GetEnv_EP(envelope),
+                                       CkUTimer(), 
+                                       GetEnv_event(envelope), GetEnv_pe(envelope));
+}
+
+trace_table(type, tbl, key, pe)
+int type, tbl, key, pe;
+{
+       add_to_buffer(type, tbl, key, CkUTimer(), -1, pe);
+}
+
+trace_begin_computation()
+{
+       add_to_buffer(BEGIN_COMPUTATION, -1, -1, CkUTimer(), -1, -1);
+}
+
+trace_end_computation()
+{
+       add_to_buffer(END_COMPUTATION, -1, -1, CkUTimer(), -1, -1, -1);
+}
+
+/***********************************************************************/ 
+/***   Log the event into this processor's buffer, and if full print **/
+/***   out on the output file.                                       **/
+/***********************************************************************/ 
+
+add_to_buffer(type, msg_type, entry, t1, event, pe)
+int type;
+int msg_type;
+int entry;
+unsigned int t1;
+int event, pe;
+{
+       LOGSTR *buf;
+
+TRACE(CmiPrintf("[%d] add: cnt=%d, type=%d, msg=%d, ep=%d, t1=%d, t2=%d, event=%d\n",
+CmiMyPe(), logcnt, type, msg_type, entry, t1, t2, event));
+       buf  = & (logbuf[logcnt]);
+       buf->type       =  type;
+       buf->msg_type   =  msg_type;
+       buf->entry      =  entry;
+       buf->time1 = t1;
+       buf->event = event;
+       buf->pe = pe;
+
+       /* write the log into the buffer */
+       logcnt++;
+
+       /* if log buffer is full then write out */
+       /* the log into log file                */
+       if (logcnt == MAXLOGBUFSIZE)
+       {
+               int begin_interrupt;
+
+               begin_interrupt = CkUTimer();
+               wrtlog(CmiMyPe(), logbuf, MAXLOGBUFSIZE);
+
+               buf = &(logbuf[logcnt]);
+               buf->type = BEGIN_INTERRUPT;
+               buf->time1 = begin_interrupt;
+               buf->event = current_event;
+               buf->pe = CmiMyPe();
+               logcnt++;
+               buf++;
+
+               buf->type = END_INTERRUPT;
+               buf->time1 = CkUTimer();
+               buf->event = current_event++;
+               buf->pe = CmiMyPe();
+               logcnt++;
+       }
+}
+
+
+/***********************************************************************/ 
+/***   This function is called when the program begins to execute to **/
+/***   set up the log files.                                         **/
+/***********************************************************************/ 
+
+log_init()
+{ 
+       int pe;
+       int length;
+       FILE *log_file_desc;
+
+       pe = CmiMyPe();
+       begin_processing_time = -1;
+
+       /* build log file name from pgm name and pe number */
+
+       length = strlen(pgm) + strlen(".") + CmiNumPe() +
+                strlen(".log") + 1;
+       log_file_name = (char *) CkAlloc(length);
+       sprintf(log_file_name, "%s.%d.log", pgm, pe);
+
+       if((log_file_desc = fopen(log_file_name, "w+")) == NULL)
+               printf("*** ERROR *** Cannot Create %s",log_file_name);
+       fprintf(log_file_desc, "PROJECTIONS-RECORD\n");
+       fclose(log_file_desc);
+       logcnt = 0; 
+}
+
+
+/***********************************************************************/ 
+/*** This function is called at the very end to dump the buffers into **/
+/*** the log files.                                                  **/
+/***********************************************************************/ 
+
+close_log()
+{
+       int i;
+       int pe;
+       LOGSTR *buf;    
+
+
+       pe = CmiMyPe();
+
+       /* flush out the log buffer before closing the log file */
+       buf = logbuf;
+       trace_end_computation();
+       if (logcnt)
+               wrtlog(pe, buf, logcnt);
+       if (pe == 0)
+       {
+               char *state_file;
+
+               state_file = (char *) malloc(strlen(pgm) + strlen(".sts") + 1);
+               strcpy(state_file, pgm);
+               strcat(state_file, ".sts");
+               state_file_fd = (FILE *) fopen(state_file, "w");
+               
+
+               fprintf(state_file_fd, "MACHINE %s\n", machine);
+               fprintf(state_file_fd, "PROCESSORS %d\n", CmiNumPe());
+               fprintf(state_file_fd, "TOTAL_CHARES %d\n", TotalChares);
+               fprintf(state_file_fd, "TOTAL_EPS %d\n", 
+                  /*     TotalEps+TotalBocEps+1);   */
+                         TotalEps+1);   
+
+               fprintf(state_file_fd, "TOTAL_MSGS %d\n", TotalMsgs);
+               fprintf(state_file_fd, "TOTAL_PSEUDOS %d\n", TotalPseudos-1);
+
+               for (i=0; i<TotalChares-1; i++)
+                       fprintf(state_file_fd, "CHARE %d %s\n",
+                               i, ChareNamesTable[i]);
+
+                       for (i=NumSysBocEps; i<TotalEps; i++) {
+                   if ( EpChareTypeTable[i] == CHARE ) {
+                               fprintf(state_file_fd, "ENTRY CHARE %d %s %d %d\n",
+                                       i, EpNameTable[i], EpChareTable[i],
+                                               EpToMsgTable[i]);
+                   }
+                   else {
+                               fprintf(state_file_fd, "ENTRY BOC %d %s %d %d\n",
+                               i, EpNameTable[i], EpChareTable[i],
+                                       EpToMsgTable[i]);
+                   }
+               }
+
+                       for (i=0; i<TotalMsgs; i++)
+                               fprintf(state_file_fd, "MESSAGE %d %d\n",
+                               i, MsgToStructTable[i].size);
+
+                       for (i=0; i<TotalPseudos-1; i++)
+                               fprintf(state_file_fd, "PSEUDO %d %d %s\n",
+                                       i, PseudoTable[i].type,
+                                               PseudoTable[i].name);
+
+
+               fprintf(state_file_fd, "END\n");
+               fflush(state_file_fd);
+               fclose(state_file_fd);
+       }
+}
+
+
+/***********************************************************************/ 
+/***  This function is used to determine the name of the program.     **/
+/***********************************************************************/ 
+
+program_name(s, m)
+char *s, *m;
+{
+       pgm = (char *) malloc(strlen(s) + 1);
+       strcpy(pgm, s);
+       machine = (char *) malloc(strlen(m) + 1);
+       strcpy(machine, m);
+}
+
+
+/***********************************************************************/ 
+/***  This function is used to write into the log file, when the      **/
+/***  buffer is full, or the program has terminated.                 **/
+/***********************************************************************/ 
+
+wrtlog(pe, buffer, count)
+int pe;
+LOGSTR *buffer;
+int count;
+{
+       int i;
+       LOGSTR *buf; 
+       FILE *log_file_desc;
+
+       buf = buffer;
+
+       /* open the logfile in append mode, write the log buffer and close it */
+
+       if((log_file_desc = fopen(log_file_name, "a")) == NULL)
+               CmiPrintf("*** ERROR *** Cannot Create %s",log_file_name);
+       for (i=0; i<count; i++, buf++)
+       {
+               write_out_projections_line(log_file_desc, 
+                                                               buf->type, buf->msg_type,
+                                                               buf->entry, buf->time1,
+                                                               buf->event, buf->pe);
+               fprintf(log_file_desc, "\n");
+       }
+       logcnt = 0;
+       fflush(log_file_desc);
+       fclose(log_file_desc);
+}
+
+
+
+send_log() {}
+
+CollectPerfFromNodes(msg, data)
+char  msg, data;
+{}
+
diff --git a/src/ck-perf/perf-recd.c b/src/ck-perf/perf-recd.c
new file mode 100644 (file)
index 0000000..d3a2ae8
--- /dev/null
@@ -0,0 +1,291 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.2  1995/04/13  20:55:09  sanjeev
+ * Changed Mc to Cmi
+ *
+ * Revision 1.1  1994/11/03  17:40:06  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+static char ident[] = "@(#)$Header$";
+/* program to log the trace information */
+
+#include <stdio.h>
+#include <string.h>
+#include "chare.h"
+#include "globals.h"
+#define MAIN_PERF
+#include "performance.h"
+#undef MAIN_PERF
+
+char *pgm, *machine;
+int RecdPerfMsg = 1;
+char *log_file_name;           /* log file name        */
+LOGSTR logbuf[MAXLOGBUFSIZE];
+
+int  logcnt;                   /* no. of log entries   */
+int iteration;
+int current_event, begin_event, begin_pe;
+
+extern int TotalChares;
+
+FILE *state_file_fd;
+
+
+void PrintStsFile(str)
+char *str ;
+{
+       fprintf(state_file_fd,"%s",str) ;
+}
+
+
+
+/**********All the trace functions *****************/
+trace_creation(msg_type, entry, envelope)
+int msg_type, entry;
+ENVELOPE *envelope;
+{
+       int i;
+
+       if (msg_type==LdbMsg || msg_type==QdBocMsg || msg_type==QdBroadcastBocMsg)
+       {
+               SetEnv_event(envelope, -1);
+               SetEnv_pe(envelope, -1);
+               return;
+       }
+
+        iteration = 1;
+       if (msg_type==BocInitMsg ||
+                       msg_type==BroadcastBocMsg ||
+                       msg_type==DynamicBocInitMsg)
+                               iteration = CmiNumPe(); 
+
+    SetEnv_event(envelope, current_event);
+    SetEnv_pe(envelope, CmiMyPe());
+       for (i=0; i<iteration; i++)
+               add_to_buffer(CREATION, msg_type, entry,  
+                               GetEnv_event(envelope)+i, GetEnv_pe(envelope));
+       current_event += iteration;
+}
+
+trace_begin_execute(envelope)
+ENVELOPE *envelope;
+{
+       int msg_type = GetEnv_msgType(envelope);
+       int entry = GetEnv_EP(envelope);
+
+       if (msg_type==QdBocMsg || msg_type==QdBroadcastBocMsg ||
+                       msg_type==LdbMsg) return;
+       begin_event = GetEnv_event(envelope);
+       if (msg_type==BocInitMsg ||
+                       msg_type==BroadcastBocMsg ||
+                       msg_type==DynamicBocInitMsg)
+                               begin_event += CmiMyPe();
+       add_to_buffer(BEGIN_PROCESSING, msg_type, entry, 
+                                       begin_event, GetEnv_pe(envelope));
+}
+
+
+trace_end_execute(id, msg_type, entry)
+int id, msg_type, entry;
+{}
+
+trace_begin_charminit()
+{
+    int *msg;
+    ENVELOPE *envelope;
+    msg = (int *) CkAllocMsg(sizeof(int));
+    envelope = (ENVELOPE *) ENVELOPE_UPTR(msg);
+    trace_creation(NewChareMsg, -1, envelope);
+       add_to_buffer(BEGIN_PROCESSING, NewChareMsg, -1,
+                               GetEnv_pe(envelope), GetEnv_event(envelope));
+}
+
+trace_end_charminit()
+{}
+
+
+trace_enqueue(envelope)
+ENVELOPE *envelope;
+{}
+
+trace_dequeue(envelope)
+ENVELOPE *envelope;
+{}
+
+trace_table(type,tbl,key,pe)
+int type,tbl,key,pe;
+{}
+
+
+
+
+trace_begin_computation()
+{}
+
+trace_end_computation()
+{
+       add_to_buffer(END_COMPUTATION, -1, -1, -1, -1);
+}
+
+
+/***********************************************************************/ 
+/***   Log the event into this processor's buffer, and if full print **/
+/***   out on the output file.                                       **/
+/***********************************************************************/ 
+add_to_buffer(type, msg_type, entry, event, pe)
+int type, msg_type, entry;
+int event, pe;
+{
+       LOGSTR *buf;
+
+       buf  = & (logbuf[logcnt]);
+       buf->type       =  type;
+       buf->msg_type   =  msg_type;
+       buf->entry      =  entry;
+        buf->event = event;
+        buf->pe = pe; 
+
+       /* write the log into the buffer */
+       logcnt++;
+
+       /* if log buffer is full then write out */
+       /* the log into log file                */
+       if (logcnt == MAXLOGBUFSIZE)
+               wrtlog(CmiMyPe(), logbuf, MAXLOGBUFSIZE);
+}
+
+
+/***********************************************************************/ 
+/***   This function is called when the program begins to execute to **/
+/***   set up the log files.                                         **/
+/***********************************************************************/ 
+
+log_init()
+{ 
+       int pe;
+       int length;
+       FILE *log_file_desc;
+
+       pe = CmiMyPe();
+
+       /* build log file name from pgm name and pe number */
+
+       length = strlen(pgm) + strlen(".") + CmiNumPe() +
+                strlen(".log") + 1;
+       log_file_name = (char *) CkAlloc(length);
+       sprintf(log_file_name, "%s.%d.log", pgm, pe);
+
+       if((log_file_desc = fopen(log_file_name, "w+")) == NULL)
+               printf("*** ERROR *** Cannot Create %s",log_file_name);
+       fprintf(log_file_desc, "DEBUG-RECORD\n");
+       fclose(log_file_desc);
+       logcnt = 0; 
+}
+
+
+/***********************************************************************/ 
+/*** This function is called at the very end to dump the buffers into **/
+/*** the log files.                                                  **/
+/***********************************************************************/ 
+
+close_log()
+{
+       int i;
+       int pe;
+       LOGSTR *buf;    
+
+       pe = CmiMyPe();
+
+       /* flush out the log buffer before closing the log file */
+       buf = logbuf;
+    trace_end_computation();
+       if (logcnt)
+               wrtlog(pe, buf, logcnt);
+    if (pe == 0)
+    {
+        char *state_file;
+
+        state_file = (char *) malloc(strlen(pgm) + strlen(".sts") + 1);
+        strcpy(state_file, pgm);
+        strcat(state_file, ".sts");
+        state_file_fd = (FILE *) fopen(state_file, "w");
+
+        fprintf(state_file_fd, "MACHINE %s\n", machine);
+        fprintf(state_file_fd, "PROCESSORS %d\n", CmiNumPe());
+        fprintf(state_file_fd, "END\n");
+        fflush(state_file_fd);
+        fclose(state_file_fd);
+    }
+
+}
+
+
+/***********************************************************************/ 
+/***  This function is used to determine the name of the program.     **/
+/***********************************************************************/ 
+
+program_name(s, m)
+char *s, *m;
+{
+       pgm = (char *) malloc(strlen(s));
+       strcpy(pgm, s);
+    machine = (char *) malloc(strlen(m) + 1);
+       strcpy(machine, m);
+
+}
+
+
+/***********************************************************************/ 
+/***  This function is used to write into the log file, when the      **/
+/***  buffer is full, or the program has terminated.                 **/
+/***********************************************************************/ 
+
+wrtlog(pe, buffer, count)
+int pe;
+LOGSTR *buffer;
+int count;
+{
+       int i;
+       LOGSTR *buf; 
+       FILE *log_file_desc;
+
+       buf = buffer;
+
+       /* open the logfile in append mode, write the log buffer and close it */
+
+       if((log_file_desc = fopen(log_file_name, "a")) == NULL)
+               CmiPrintf("*** ERROR *** Cannot Create %s",log_file_name);
+       for (i=0; i<count; i++, buf++) 
+       {
+        write_out_debug_line(log_file_desc, buf->type, buf->msg_type, 
+                                                               buf->entry, -1, buf->event, buf->pe);
+               fprintf(log_file_desc, "\n");
+       }
+       logcnt = 0;
+       fflush(log_file_desc);
+       fclose(log_file_desc);
+}
+
+
+send_log() {}
+
+CollectPerfFromNodes(msg, data)
+char  msg, data;
+{}
+
diff --git a/src/ck-perf/perf-repl.c b/src/ck-perf/perf-repl.c
new file mode 100644 (file)
index 0000000..c32f2f1
--- /dev/null
@@ -0,0 +1,457 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.2  1995/04/13  20:55:09  sanjeev
+ * Changed Mc to Cmi
+ *
+ * Revision 1.1  1994/11/03  17:40:04  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+static char ident[] = "@(#)$Header$";
+#include <stdio.h>
+#include <string.h>
+#include <sys/param.h>
+#include "chare.h"
+#include "globals.h"
+#define MAIN_PERF
+#include "performance.h"
+#undef MAIN_PERF
+
+#define MAXTRANSSIZE 50000
+#define MAXEVENTBUFSIZE        50000
+int creation_table[MAXEVENTBUFSIZE];
+LOGSTR event_buffer[MAXEVENTBUFSIZE];
+
+#define HASH_TABLE_SIZE 9001
+#define HashMap(x) (x*9007 % HASH_TABLE_SIZE)
+typedef struct entry {
+       int event, destination;
+       struct entry *next;
+} ENTRY;
+ENTRY *hash_table[HASH_TABLE_SIZE];
+
+FILE *fd; 
+int (*f)();
+LOGSTR *buf;
+unsigned int replay_time; 
+int type, msg_type, entry, event, dest, pe; 
+int read_in_debug_line(), read_in_projections_data(); 
+
+char *pgm;
+int RecdPerfMsg = 1;
+char *event_file_name;                 /* log file name        */
+int debug_replay, projections_replay;
+
+int event_count=0, translation_count, creation_count;
+int  event_index=0, translation_index=0, creation_index=0;
+long fevent_position, ftranslation_position, fcreation_position;
+int  done_with_event=0,done_with_translation=0,done_with_creation=0;
+
+#define open_and_init(position)  { \
+       if ((fd = fopen(event_file_name, "r")) == NULL) \
+               CmiPrintf("ERROR: cannot create %s\n",event_file_name); \
+       if (fseek(fd, position, 0) == -1) \
+               CmiPrintf("ERROR: cannot seek %s\n",event_file_name); \
+       if (debug_replay) f=read_in_debug_line; \
+       else f=read_in_projections_data;  \
+}
+
+#define close_and_finish(position) { \
+       position = ftell(fd); \
+       write_event(); \
+       fclose(fd); \
+}
+
+
+#define SystemEvent(msg_type) \
+        (!debug_replay && \
+        (msg_type==LdbMsg || msg_type==QdBocMsg || msg_type==QdBroadcastBocMsg))
+
+/**********All the trace functions *****************/
+trace_creation(msg_type, entry, envelope)
+int msg_type, entry;
+ENVELOPE *envelope;
+{
+        if (msg_type==LdbMsg || msg_type==QdBroadcastBocMsg || msg_type==QdBocMsg)
+        {
+                SetEnv_event(envelope, -1);
+                SetEnv_pe(envelope, -1);
+                return;
+        }
+
+        SetEnv_event(envelope, determine_creation(msg_type));
+        SetEnv_pe(envelope, CmiMyPe());
+}
+
+
+trace_begin_execute(envelope)
+ENVELOPE *envelope;
+{}
+
+
+trace_end_execute(id, msg_type, entry)
+int id, msg_type, entry;
+{
+       if (msg_type==LdbMsg || msg_type==QdBroadcastBocMsg || msg_type==QdBocMsg)
+               return;
+       increment_event();
+}
+
+trace_begin_charminit() 
+{
+       int *msg;
+       ENVELOPE *envelope;
+       msg = (int *) CkAllocMsg(sizeof(int));
+       envelope = (ENVELOPE *) ENVELOPE_UPTR(msg);
+       trace_creation(NewChareMsg, -1, envelope);
+}
+
+trace_end_charminit() 
+{increment_event();}
+
+
+
+trace_enqueue(envelope)
+ENVELOPE *envelope;
+{}
+
+trace_dequeue(envelope)
+ENVELOPE *envelope;
+{}
+
+
+trace_begin_computation()
+{}
+
+trace_table(type,tbl,key,pe)
+int type,tbl,key,pe;
+{}
+
+
+
+/***********************************************************************/ 
+/***   This function is called when the program begins to execute to **/
+/***   set up the log files.                                         **/
+/***********************************************************************/ 
+
+log_init()
+{ 
+       int i;
+       int pe;
+       int length;
+       char temp[1000];
+       FILE *fd;
+       FILE *translation_file_desc;
+
+       pe = CmiMyPe();
+
+       /* build log file name from pgm name and pe number */
+       length = strlen(pgm) + strlen(".") + CmiNumPe() + strlen(".log") + 1;
+       event_file_name = (char *) CkAlloc(length);
+       sprintf(event_file_name, "%s.%d.rpy", pgm, pe);
+
+       if((fd = fopen(event_file_name, "r")) == NULL)
+               printf("ERROR: cannot open %s\n",event_file_name);
+
+       debug_replay=projections_replay=0;
+       fscanf(fd, "%s", temp); 
+       if (!strcmp(temp, "DEBUG-REPLAY")) debug_replay = 1;
+       else if (!strcmp(temp, "PROJECTIONS-REPLAY")) projections_replay = 1;
+       else {
+               CmiPrintf("ERROR: incorrect replay format for %s\n", event_file_name);
+               fclose(fd);
+               return;
+       }
+       fevent_position = ftranslation_position = fcreation_position =  ftell(fd); 
+       fclose(fd);
+
+       determine_translation_set(MAXTRANSSIZE);
+       determine_event_set(MAXEVENTBUFSIZE);
+       if (projections_replay) determine_creation_set(MAXEVENTBUFSIZE);
+}
+
+
+
+/***********************************************************************/ 
+/*** This function is called at the very end to dump the buffers into **/
+/*** the log files.                                                  **/
+/***********************************************************************/ 
+
+close_log()
+{
+}
+
+void PrintStsFile(str)
+char *str ;
+{ }
+
+/***********************************************************************/ 
+/***  This function is used to determine the name of the program.     **/
+/***********************************************************************/ 
+
+program_name(s, m)
+char *s, *m;
+{
+       pgm = (char *) malloc(strlen(s));
+       strcpy(pgm, s);
+}
+
+
+
+
+send_log() {}
+
+CollectPerfFromNodes(msg, data)
+char  msg, data;
+{}
+
+
+
+
+write_event()
+{
+/*
+       int i;
+       char temp[6*10];
+       char output[6*MAXEVENTBUFSIZE*10];
+
+               strcpy(output, "");
+       for (i=0; i<event_count; i++)
+       {
+               strcpy(temp, "");
+               sprintf(temp, "[%d] event: %d %d %d %d\n",
+                       CmiMyPe(),
+                       event_buffer[i].msg_type, event_buffer[i].entry,
+                       event_buffer[i].event, event_buffer[i].pe);
+               strcat(output, temp);
+       }
+               CmiPrintf("%s\n", output);
+       CmiPrintf("\n\n\n");
+*/
+}
+
+
+write_translation()
+{
+/*
+       int i;
+        char temp[4*10];
+        char output[4*MAXTRANSSIZE*10];
+
+
+        strcpy(output, "");
+       for (i=0; i<MAXTRANSSIZE; i++)
+               if (translation_buffer[i] != -1)
+               {
+                       strcpy(temp, "");
+                       sprintf(temp, "[%d] trans: %d %d\n",
+                                       CmiMyPe(),  i, translation_buffer[i]);
+                       strcat(output, temp);
+               }
+        CmiPrintf("%s\n", output);
+*/
+}
+
+
+increment_event()
+{
+       int index;
+/*
+CmiPrintf("[%d] event: event=%d, pe=%d\n", CmiMyPe(), 
+event_buffer[event_index].event, event_buffer[event_index].pe);
+*/
+    event_index++;
+       index = event_index%MAXEVENTBUFSIZE;
+    if (index>=event_count && !done_with_event)
+        determine_event_set(MAXEVENTBUFSIZE);
+}
+
+determine_current_event(event, pe)
+int *event, *pe;
+{
+       int index=event_index%MAXEVENTBUFSIZE;
+
+    *event = event_buffer[index].event;
+    *pe = event_buffer[index].pe;
+    if (event_buffer[index].msg_type==BroadcastBocMsg ||
+            event_buffer[index].msg_type==DynamicBocInitMsg)
+                *event -= CmiMyPe();
+}
+
+determine_creation(msg_type)
+int msg_type;
+{
+       int store;
+
+       if (debug_replay) store=creation_index;
+       else store=creation_table[creation_index];
+
+       creation_index++;
+       if (msg_type==BocInitMsg || msg_type==BroadcastBocMsg ||
+                       msg_type==DynamicBocInitMsg)
+                creation_index += CmiNumPe()-1;
+
+       if (projections_replay)  {
+               int index = creation_index%MAXEVENTBUFSIZE;
+               if (index>=creation_count && !done_with_creation)
+                       determine_creation_set(MAXEVENTBUFSIZE);
+       }
+
+       return store;
+}
+
+determine_translation(env)
+ENVELOPE *env;
+{
+       int x = GetEnv_event(env);
+
+    if (x>=translation_count && !done_with_translation)
+        determine_translation_set(MAXTRANSSIZE);
+    return DeleteDestination(x);
+    TRACE(CmiPrintf("[%d] trans: for %d, dest=%d\n", CmiMyPe(), x, temp));
+}
+
+
+/***********************************************************************/ 
+/***  These functions are used to read from the log file.                    **/
+/***********************************************************************/ 
+
+determine_event_set(count)
+int count;
+{
+       event_count=0;
+       buf = event_buffer;
+       open_and_init(fevent_position);
+       while (event_count<count && !done_with_event)
+       {
+               (*f)(fd, 1, &type, &msg_type, &entry, &replay_time, &event, &dest, &pe);
+
+               if (SystemEvent(msg_type)) continue;
+               switch (type) {
+
+                       case BEGIN_PROCESSING:
+                buf->msg_type = msg_type;
+                               buf->entry = entry;
+                               buf->event = event;
+                               buf->pe = pe;
+                               buf++;
+                               event_count++;
+                               break;
+
+                       case END_COMPUTATION:
+                               done_with_event = 1;
+                               break;
+
+               }
+       }
+       close_and_finish(fevent_position);
+}
+
+determine_translation_set(count)
+int count;
+{
+       open_and_init(ftranslation_position);
+       while (translation_count<count && !done_with_translation)
+       {
+               (*f)(fd, 1, &type, &msg_type, &entry, &replay_time, &event, &dest, &pe);
+
+               if (SystemEvent(msg_type)) continue;
+               switch (type) {
+
+                       case CREATION:
+                               if (msg_type == NewChareMsg)  {
+                                       InsertDestination(event, dest);
+                    translation_count=event;
+                               }
+                               break;
+
+                       case END_COMPUTATION:
+                               done_with_translation = 1;
+                               break;
+
+               }
+       }
+       close_and_finish(ftranslation_position);
+}
+
+determine_creation_set(count)
+int count;
+{
+       creation_count=0;
+       open_and_init(fcreation_position);
+       while (creation_count<count && !done_with_creation)
+       {
+               (*f)(fd, 1, &type, &msg_type, &entry, &replay_time, &event, &dest, &pe);
+
+               if (SystemEvent(msg_type)) continue;
+               switch (type) {
+
+                       case CREATION:
+                               creation_table[creation_count++] = event; 
+                               break;
+
+                       case END_COMPUTATION:
+                               done_with_creation = 1;
+                               break;
+
+               }
+       }
+       close_and_finish(fcreation_position);
+}
+
+
+/***********************************************************************/ 
+/* Hash table functions.                                                                                       **/
+/***********************************************************************/ 
+
+InsertDestination(event, destination)
+int event, destination;
+{
+    ENTRY *current;
+    int index = HashMap(event);
+
+    current = (ENTRY *) CkAlloc(sizeof(ENTRY));
+    current->event = event;
+    current->destination = destination;
+    current->next = hash_table[index];
+    hash_table[index] = current;
+}
+
+
+DeleteDestination(event, pe)
+int event, pe;
+{
+    ENTRY *previous = NULL;
+    int index = HashMap(event);
+    ENTRY *current = hash_table[index];
+
+    while (current != NULL)
+        if (current->event==event) {
+            if (!previous) hash_table[index] = current->next;
+            else previous->next = current->next;
+            CkFree(current);
+            return current->destination;
+        }
+        else
+            current = current->next;
+    printf("*** ERROR *** Cannot determine destination for %d, %d\n",
+                pe, event);
+    return -1;
+}
+
+
diff --git a/src/ck-perf/perf-sum.c b/src/ck-perf/perf-sum.c
new file mode 100644 (file)
index 0000000..e6c6813
--- /dev/null
@@ -0,0 +1,478 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ ***************************************************************************/
+static char ident[] = "@(#)$Header$";
+/* program to log the trace information */
+
+#include <stdio.h>
+#include <string.h>
+#include "chare.h"
+#include "globals.h"
+#define MAIN_PERF
+#include "performance.h"
+#undef MAIN_PERF
+#include "stat.h"
+
+char *pgm;
+int RecdPerfMsg; 
+char *log_file_name;   /* log file name        */
+
+int display_index;
+int last_time_interval, current_time_interval;
+int display_table[NUMBER_DISPLAYS][MAXLOGMSGSIZE];
+int time, timestep, init_time, start_processing_time;
+
+extern int RecdStatMsg;
+
+trace_creation(msg_type, entry, envelope)
+int msg_type, entry;
+ENVELOPE *envelope;
+{
+       time = CkTimer(); 
+       adjust_time_interval(time);
+       display_index = get_creation_display_index(msg_type); 
+       if (display_index >=0)
+               display_table[display_index][current_time_interval] += 1;
+}
+
+trace_begin_execute(envelope)
+ENVELOPE *envelope;
+{
+       int msg_type = GetEnv_msgType(envelope);
+       if (((msg_type == BocMsg) || (msg_type == BroadcastBocMsg) ||
+                       (msg_type == QdBocMsg) || (msg_type == QdBroadcastBocMsg)) &&
+               (GetEnv_EP(envelope) < NumSysBocEps))
+               return;
+
+       time = CkTimer(); 
+       adjust_time_interval(time);
+       start_processing_time = time;
+       last_time_interval = current_time_interval;
+}
+
+
+trace_end_execute(id, msg_type, entry)
+int id, msg_type, entry;
+{
+       if (start_processing_time == -1)
+               return;
+       time = CkTimer(); 
+       adjust_time_interval(time);
+       display_index = get_processing_display_index(msg_type);
+       compute_busy(start_processing_time, time, last_time_interval, 
+                       current_time_interval);
+       if (display_index >= 0) 
+               update_display(display_index, last_time_interval,
+                               current_time_interval); 
+       start_processing_time = last_time_interval = -1;
+}
+
+trace_enqueue(envelope)
+ENVELOPE *envelope;
+{}
+
+trace_dequeue(envelope)
+ENVELOPE *envelope;
+{}
+
+trace_table(type,tbl,key,pe)
+int type,tbl,key,pe;
+{}
+
+
+
+/***********************************************************************/ 
+/***********************************************************************/ 
+
+adjust_time_interval(time)
+unsigned int time;
+{
+       int temp_time_interval = MAXLOGMSGSIZE - 1;
+
+       current_time_interval = (time - init_time) / timestep;
+       while (current_time_interval >= MAXLOGMSGSIZE)
+       {
+TRACE(CmiPrintf("[%d] adjust_time_interval: current_time_interval=%d\n", 
+CmiMyPe(), current_time_interval));
+
+               adjust_timestep(&timestep, &temp_time_interval,
+                               display_table, 2);
+               current_time_interval = (time - init_time) / timestep;
+               if (start_processing_time != -1)
+                       last_time_interval = (start_processing_time -
+                                                init_time) / timestep;
+
+TRACE(CmiPrintf("[%d] adjust_time_interval: current_time_interval=%d\n", 
+CmiMyPe(), current_time_interval));
+       }
+}
+
+
+/***********************************************************************/ 
+/***   This function is called when the program begins to execute to **/
+/***   set up the log files.                                         **/
+/***********************************************************************/ 
+
+log_init()
+{ 
+       int i, j;
+       timestep = INITIAL_TIMESTEP;
+
+
+       RecdPerfMsg = 0;
+       init_time = CkTimer();
+       start_processing_time = -1;
+        for (i=0; i<NUMBER_DISPLAYS; i++)
+        for (j=0; j<MAXLOGMSGSIZE; j++)
+               display_table[i][j] = 0;
+}
+
+
+/***********************************************************************/ 
+/*** This function is called at the very end to dump the buffers into **/
+/*** the log files.                                                  **/
+/***********************************************************************/ 
+
+close_log()
+{
+       if (CmiMyPe() == 0)
+       {
+               int i, j; 
+               int length;
+               FILE *log_file_desc;
+
+               /* build log file name from pgm name and pe number */
+               /* flush out the log buffer before closing the log file */
+       
+               length = strlen(pgm) + strlen(".pgm") + 1;
+               log_file_name = (char *) CmiAlloc(length);
+               sprintf(log_file_name, "%s.log", pgm);
+       
+               if((log_file_desc = fopen(log_file_name, "w+")) == NULL)
+                       printf("*** ERROR *** Cannot Create %s",
+                                       log_file_name);
+               fprintf(log_file_desc, "%d %d %d\n", CmiNumPe(),
+                       timestep, current_time_interval+1);
+                       
+
+               for (j=0; j<current_time_interval+1; j++)
+                       display_table[IDLE_TIME][j] =
+                               (display_table[IDLE_TIME][j]*100)/
+                               (CmiNumPe()*timestep);
+               for (i=0; i<NUMBER_DISPLAYS; i++)
+               {
+                       for (j=0; j<current_time_interval+1; j++)
+                               fprintf(log_file_desc, "%d ", 
+                                       display_table[i][j]); 
+                       fprintf(log_file_desc, "\n");
+               }
+       }
+}
+
+adjust_timestep(timestep, current_time_interval, display_table, index)
+int *timestep;
+int *current_time_interval;
+int display_table[NUMBER_DISPLAYS][MAXLOGMSGSIZE];
+int index;
+{
+       int i, j, k, l;
+
+TRACE(CmiPrintf("[%d] adjust_timestep: timestep=%d, current_time_interval=%d, index=%d\n",
+               CmiMyPe(), *timestep, *current_time_interval, index));
+
+TRACE(print_idle(*current_time_interval));
+
+        *timestep = (*timestep)*index;
+
+        for (i=0; i<NUMBER_DISPLAYS; i++)
+        for (j=0,l=0; j<(*current_time_interval+1); j+=index,l++)
+       {
+                display_table[i][l] = display_table[i][j];
+               for (k=1; k<index; k++)
+               if (j+k<(*current_time_interval)+1)
+                       display_table[i][l] += display_table[i][j+k];
+       }
+
+       l--;
+       /*
+       for (j=0; j<l+1; j++)
+               display_table[IDLE_TIME][j] /= index;   
+       */
+        *current_time_interval = l;
+
+        for (i=0; i<NUMBER_DISPLAYS; i++)
+               for (j=l+1; j<MAXLOGMSGSIZE; j++)
+                       display_table[i][j] = 0;
+
+TRACE(print_idle(*current_time_interval));
+}
+
+
+
+add_log(msg)
+PERF_MSG *msg;
+{
+       int i, j;
+
+       if ((msg->timestep != 0) && (msg->timestep != timestep))
+               if (msg->timestep > timestep)
+                       adjust_timestep(&timestep, &current_time_interval,
+                                       display_table,
+                                       (msg->timestep/timestep));
+               else
+                       adjust_timestep(&(msg->timestep),
+                                       &(msg->current_time_interval),
+                                       msg->display_table,
+                                       (timestep/msg->timestep));
+
+       /* flush out the log buffer before closing the log file */
+       for (i=0; i<NUMBER_DISPLAYS; i++)
+               for (j=0; j<current_time_interval+1; j++)
+                       display_table[i][j] += msg->display_table[i][j];
+       /*
+       for (j=0; j<current_time_interval+1; j++)
+               display_table[IDLE_TIME][j] /= 2;
+       */
+
+}
+
+/*************************************************************************/ 
+/** Send out performance message.                                      **/
+/*************************************************************************/ 
+SendOutPerfMsg(mype)
+int mype;
+{
+       int i, j;
+       PERF_MSG *msg;
+
+       msg = (PERF_MSG *) CkAllocMsg(sizeof(PERF_MSG));
+
+       msg->current_time_interval = current_time_interval;
+       msg->timestep = timestep;
+       for (i=0; i<NUMBER_DISPLAYS; i++)
+       {
+       for (j=0; j<current_time_interval+1; j++)
+               msg->display_table[i][j] = display_table[i][j]; 
+       for (j=current_time_interval+1; j<MAXLOGMSGSIZE; j++)
+               msg->display_table[i][j] = 0;
+       }
+TRACE(CmiPrintf("[%d] Send out perf message to %d\n", 
+               mype, CmiSpanTreeParent(mype)));
+
+       GeneralSendMsgBranch(StatPerfCollectNodes_EP, msg,
+               CmiSpanTreeParent(mype), USERcat, BocMsg, LdbBocNum);
+}
+
+
+/*************************************************************************/ 
+/** Adjust log and send out messages if necessary.                     **/
+/*************************************************************************/ 
+send_log()
+{
+       int mype = CmiMyPe();
+       if (CmiNumSpanTreeChildren(mype) == 0)
+       {
+               RecdPerfMsg = 1;
+               if (mype != 0)
+                       SendOutPerfMsg(mype);
+       }
+}
+
+/************************************************************************/ 
+/** Collect performance messages sent from children here.              **/
+/************************************************************************/ 
+CollectPerfFromNodes(msg, localdataptr)
+PERF_MSG *msg;
+void  *localdataptr;
+{
+       int mype;
+       static int recd = 0;
+
+       recd++;
+       add_log(msg);
+       mype = CmiMyPe();
+
+TRACE(CmiPrintf("[%d] CollectPerf..: recd=%d,  span=%d\n",
+               mype, recd, CmiNumSpanTreeChildren(mype)));
+       if (recd == CmiNumSpanTreeChildren(mype))
+       {
+               RecdPerfMsg = 1;
+               if (mype != 0)
+                       SendOutPerfMsg(mype);
+TRACE(CmiPrintf("[%d] RecdStatMsg=%d\n", CmiMyPe(), RecdStatMsg));
+               if (RecdStatMsg) ExitNode();    
+       }  
+}
+
+/***********************************************************************/ 
+/***  This function is used to determine the name of the program.     **/
+/***********************************************************************/ 
+
+program_name(s, m)
+char *s, *m;
+{
+       pgm = (char *) malloc(strlen(s)+1);
+       strcpy(pgm, s);
+}
+
+
+
+
+
+/*************************************************************************/
+/** Update the display for this message processing/creation.           **/
+/*************************************************************************/
+update_display(index, last_interval, current_interval)
+int index;
+int last_interval, current_interval;
+{
+       int i;
+
+       /*
+       for (i=last_interval; i<=current_interval; i++)
+               (display_table[index][i])++;
+       */
+       display_table[index][last_interval]++;
+}
+
+
+
+/*************************************************************************/
+/** We compute the busy period in this function.                       **/
+/*************************************************************************/
+compute_busy(begin, end, last_interval, current_interval)
+int begin, end;
+int last_interval, current_interval;
+{
+       int i;
+       int border;
+
+TRACE(CmiPrintf("[%d] compute_busy: begin=%d, end=%d, last_interval=%d, current_interval=%d\n",
+               CmiMyPe(), begin, end, last_interval, current_interval));
+       if (begin == -1) return;
+
+
+       if (current_interval > last_interval)
+       {
+               for (i=last_interval; i<current_interval; i++)
+               {
+                       border = timestep*(i+1) + init_time; 
+                       display_table[IDLE_TIME][i] += border - begin;
+                                /* ((border - begin)*100)/timestep; */
+                       begin = border;
+               }
+               display_table[IDLE_TIME][current_interval] +=
+                                end - border;
+                                /* ((end - border)*100)/timestep; */
+       }
+       else
+               display_table[IDLE_TIME][current_interval] +=
+                        end - begin;
+                        /* ((end - begin)*100)/timestep; */
+}
+
+
+
+/*************************************************************************/
+/** This function is used to process creation message types.           **/
+/*************************************************************************/
+
+get_creation_display_index(msg_type) 
+int msg_type; 
+{
+       int display_index;
+
+       /*****************************************************************/
+       /** Get the proper display table.                               **/
+       /******************************************************************/
+       switch (msg_type) 
+       {
+               case NewChareMsg:
+                       display_index = CREATE_NEWCHARE;
+                       break;
+               case ForChareMsg:
+                       display_index = CREATE_FORCHARE;
+                       break;
+               case BocMsg:
+                       display_index = CREATE_FORBOC;
+                       break;
+               default:
+                       display_index = -1;
+                       break;
+       }
+       return display_index;
+}
+
+
+
+/*************************************************************************/
+/*************************************************************************/
+
+get_processing_display_index(msg_type)
+int msg_type;
+{
+       int display_index;
+
+       /*****************************************************************/
+       /** Get the proper display table.                               **/
+       /******************************************************************/
+       switch (msg_type) 
+       {
+               case NewChareMsg:
+                       display_index = PROCESS_NEWCHARE;
+                       break;
+               case ForChareMsg:
+                       display_index = PROCESS_FORCHARE;
+                       break;
+               case BocMsg:
+                       display_index = PROCESS_FORBOC;
+                       break;
+               default:
+                       display_index = -1;
+                       break;
+       }
+       return display_index;
+}
+
+
+
+
+print_idle(X)
+int X;
+{
+       int j;
+       char *str, *string;
+
+       str = (char *) malloc(100);
+       string = (char *) malloc(1000);
+
+       CmiPrintf("[%d] print_idle: X=%d, current_time_interval=%d\n",
+                        CmiMyPe(), X, current_time_interval);
+       sprintf(string, "");
+       for (j=0; j<X+1; j++)
+       {
+               sprintf(str, "%d ", display_table[0][j]);
+               strcat(string, str);
+       }
+       CmiPrintf("[%d] print_idle: %s \n", CmiMyPe(), string);
+       
+       free(str);
+       free(string);
+}
+
+
+void PrintStsFile(str)
+char *str ;
+{
+}
diff --git a/src/ck-perf/perfio.c b/src/ck-perf/perfio.c
new file mode 100644 (file)
index 0000000..ba80bf8
--- /dev/null
@@ -0,0 +1,188 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.2  1994/11/16  20:06:25  sanjeev
+ * removed char *ident.....
+ *
+ * Revision 1.1  1994/11/03  17:40:12  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+#include <stdio.h>
+#include "chare.h"
+#include "globals.h"
+#include "performance.h"
+
+read_in_debug_line(fp, replay, type, mtype, entry, time, event, dest, pe)
+FILE *fp;
+int replay;
+int *type, *mtype, *entry;
+unsigned int *time;
+int *event, *dest,  *pe;
+{
+       int value;
+
+       value = fscanf(fp, "%d", type);
+       if (value==EOF) return value;
+
+       switch (*type)
+       {
+               case CREATION:
+                       value = fscanf(fp, "%d %d %d\n", mtype, entry, event);
+                       if (value==EOF) return value;
+                       if (replay && *mtype==NewChareMsg) 
+                               value = fscanf(fp, "%d", dest);
+                       return value;
+
+               case BEGIN_PROCESSING:
+                       return fscanf(fp, "%d %d %d %d\n", mtype, entry, event, pe);
+
+               case END_COMPUTATION:
+                       return value;
+
+               default:
+                       printf("***ERROR*** Wierd Event %d.\n", type);
+                       return value; 
+       }
+}
+
+
+write_out_debug_line(fp, type, mtype, entry, time, event, pe)
+FILE *fp;
+int type, mtype, entry;
+unsigned int time;
+int event, pe;
+{
+       fprintf(fp, "%d ", type);
+
+       switch (type)
+       {
+               case CREATION:
+                       fprintf(fp, "%d %d %d", mtype, entry, event);
+                       break;
+
+               case BEGIN_PROCESSING:
+                       fprintf(fp, "%d %d %d %d", mtype, entry, event, pe);
+                       break;
+
+               case END_COMPUTATION:
+                       break;
+
+               default:
+                       printf("***ERROR*** Wierd Event %d.\n", type);
+                       break;
+       }
+}
+
+
+read_in_projections_data(fp, replay, type, mtype, entry, time, event, dest, pe)
+FILE *fp;
+int replay;
+int *type, *mtype, *entry;
+unsigned int *time;
+int *event, *dest, *pe;
+{
+       int value;
+
+       value = fscanf(fp, "%d", type);
+       if (value==EOF) return value;
+
+       switch (*type) {
+               case CREATION:
+               case END_PROCESSING:
+               case BEGIN_PROCESSING:
+               value = fscanf(fp, "%d %d %u %d %d", mtype, entry, time, event, pe);
+                       if (value==EOF) return value;
+                       if (replay && *type==CREATION && *mtype==NewChareMsg) 
+                               value = fscanf(fp, "%d", dest);
+                       return value;
+               break;
+
+               case ENQUEUE:
+               case DEQUEUE:
+               return fscanf(fp, "%d %u %d %d", mtype, time, event, pe);
+               break;
+       
+               case INSERT:
+               case FIND:
+               case DELETE:
+               return fscanf(fp, "%d %d %u %d", mtype, entry, time, pe);
+               break;
+
+               case BEGIN_INTERRUPT:
+               case END_INTERRUPT:
+               return fscanf(fp, "%u %d %d", time, event, pe);
+               break;
+       
+               case BEGIN_COMPUTATION:
+               case END_COMPUTATION:
+               return fscanf(fp, "%u", &time);
+               break;
+       
+               default:
+               printf("***ERROR*** Wierd Event %d.\n", *type);
+                       return value;
+    }
+}
+
+write_out_projections_line(fp, type, mtype, entry, time, event, pe)
+FILE *fp;
+int type, mtype, entry;
+unsigned int time;
+int event, pe;
+{
+       fprintf(fp, "%d ", type);
+
+       /*************************************************/
+       /** Perform appropriate actions for this entry. **/
+       /*************************************************/
+       switch (type)
+       {
+       case CREATION:
+       case BEGIN_PROCESSING:
+       case END_PROCESSING:
+               fprintf(fp, "%d %d %u %d %d", mtype, entry, time, event, pe);
+               break;
+
+       case ENQUEUE:
+       case DEQUEUE:
+               fprintf(fp, "%d %u %d %d", mtype, time, event, pe);
+               break;
+
+       case INSERT:
+       case FIND:
+       case DELETE:
+               fprintf(fp, "%d %d %u %d", mtype, entry, time, pe);
+               break;
+
+       case BEGIN_INTERRUPT:
+       case END_INTERRUPT:
+               fprintf(fp, "%d %d", event, pe);
+               break;
+
+       case BEGIN_COMPUTATION:
+       case END_COMPUTATION:
+       fprintf(fp, "%u", time);
+               break;
+
+       default:
+               printf("***ERROR*** Wierd Event %d.\n", type);
+               break;
+       }
+}
+
+
diff --git a/src/ck-perf/performance.h b/src/ck-perf/performance.h
new file mode 100644 (file)
index 0000000..62c1275
--- /dev/null
@@ -0,0 +1,90 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *     $RCSfile$
+ *     $Author$        $Locker$                $State$
+ *     $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ * $Log$
+ * Revision 2.0  1995-06-02 17:40:29  brunner
+ * Reorganized directory structure
+ *
+ * Revision 1.2  1994/11/11  05:31:17  brunner
+ * Removed ident added by accident with RCS header
+ *
+ * Revision 1.1  1994/11/07  15:39:40  brunner
+ * Initial revision
+ *
+ ***************************************************************************/
+#define  CREATION           1
+#define  BEGIN_PROCESSING   2
+#define  END_PROCESSING     3
+#define  ENQUEUE            4
+#define  DEQUEUE            5
+#define  BEGIN_COMPUTATION  6
+#define  END_COMPUTATION    7
+#define  BEGIN_INTERRUPT    8
+#define  END_INTERRUPT      9
+#define  INSERT                                10
+#define  DELETE                        11
+#define  FIND                      12
+
+
+#define  NUMBER_DISPLAYS       7
+#define CREATE_NEWCHARE         0
+#define CREATE_FORCHARE         1
+#define CREATE_FORBOC           2
+#define PROCESS_NEWCHARE        3
+#define PROCESS_FORCHARE        4
+#define PROCESS_FORBOC          5
+#define IDLE_TIME               6
+
+#define MAXLOGBUFSIZE                  100000    /* max size of log buffer */
+#define MAXLOGMSGSIZE                  400   /* max size of log buffer */
+
+#define INITIAL_TIMESTEP       100
+
+typedef struct _debug {
+    int timestep;
+    int current_time_interval;
+    int display_table[NUMBER_DISPLAYS][MAXLOGMSGSIZE]; 
+} PERF_MSG;
+
+
+#ifdef DEBUGGING_MODE
+typedef struct logstr {         /* structure of the log entry          */
+       int type;               /* creation/processing                  */
+       int msg_type;           /* type of message                      */
+       int entry;              /* entry point message was sent         */
+       int event;              /* message event number                 */
+       int pe;                 /* message event processor number       */
+    unsigned int time1;     /* time in microseconds of event        */
+} LOGSTR;
+#else
+typedef struct logstr {         /* structure of the log entry           */
+    int type;             /* creation/processing                  */
+    int msg_type;         /* type of message                      */
+    int entry;              /* entry point message was sent         */
+    unsigned int time1;     /* time in microseconds of event        */
+} LOGSTR;
+#endif
+
+
+#ifdef MAIN_PERF
+
+#define MAX_COLORS 5
+#define MAX_EPS 100
+char * colors [] = {
+       "black", "blue", "yellow", "red", "green"
+};
+
+#endif
+
+
+
diff --git a/src/conv-core/convcore.c b/src/conv-core/convcore.c
new file mode 100644 (file)
index 0000000..f60a909
--- /dev/null
@@ -0,0 +1,312 @@
+/***************************************************************************
+ * RCS INFORMATION:
+ *
+ *      $RCSfile$
+ *      $Author$        $Locker$                $State$
+ *      $Revision$      $Date$
+ *
+ ***************************************************************************
+ * DESCRIPTION:
+ *
+ ***************************************************************************
+ * REVISION HISTORY:
+ *
+ ***************************************************************************/
+static char ident[] = "@(#)$Header$";
+
+#include <stdio.h>
+#include "converse.h"
+#include "conv-mach.h"
+
+
+
+/*****************************************************************************
+ *
+ * Statistics: currently, the following statistics are not updated by converse.
+ *
+ *****************************************************************************/
+
+int CstatsMaxChareQueueLength=0;
+int CstatsMaxForChareQueueLength=0;
+int CstatsMaxFixedChareQueueLength=0;
+
+int CstatMemory(int i)
+{
+  return 0;
+}
+
+static int CstatPrintQueueStatsFlag;
+int CstatPrintQueueStats()
+{
+  return CstatPrintQueueStatsFlag;
+}
+
+static int CstatPrintMemStatsFlag;
+int CstatPrintMemStats()
+{
+  return CstatPrintMemStatsFlag;
+}
+
+/*****************************************************************************
+ *
+ * The following are some CMI functions.  Having this code here makes
+ * the module boundaries for the Cmi quite blurry.
+ *
+ *****************************************************************************/
+
+#define MAX_HANDLERS 512
+CmiHandler *CmiHandlerTable;
+extern void *CmiLocalQueue;
+void        *CmiGetNonLocal();
+
+void CmiInit(argv)
+char **argv;
+{
+  void *FIFO_Create();
+  CmiHandlerTable =
+    (CmiHandler *)CmiAlloc((MAX_HANDLERS + 1) * sizeof(CmiHandler)) ;
+  CmiInitMc(argv);
+}
+
+void *CmiGetMsg()
+{
+  void *msg;
+  if (!FIFO_Empty(CmiLocalQueue)) {
+    FIFO_DeQueue(CmiLocalQueue, &msg);
+    return msg;
+  }
+  msg=CmiGetNonLocal();
+  return msg;
+}
+
+int CmiRegisterHandler(handlerf)
+CmiHandler handlerf ;
+{
+  static int handlerCount=0 ;
+
+  CmiHandlerTable[handlerCount] = handlerf;
+  handlerCount++ ;
+  return handlerCount-1 ;
+}
+
+void *CmiGetSpecificMsg(lang)
+int lang;
+{
+/* loop till a message for lang is recvd, then return it */
+  int msgType;
+  int *msg, *first ;
+  
+  /* the LocalQueue-FIFO can have only thoses msgs enqueued at the
+     FIFO_EnQueues in this function */
+  /* We assume that there can be no self-messages (messages from my
+     processor to myself) for the PVM/MPI msg manager
+     (ie. the PVM msg manager checks for a self message while sending
+     and keeps it within itself instead of giving it to Converse)  */
+  
+  if ( !FIFO_Empty(CmiLocalQueue) ) {
+    FIFO_DeQueue(CmiLocalQueue, &msg);
+    first = msg;
+    do {
+      if ( CmiGetHandler(msg)==lang ) 
+       return (void *)msg ;
+      else
+       FIFO_EnQueue(CmiLocalQueue, msg);
+      
+      FIFO_DeQueue(CmiLocalQueue, &msg);
+    } while ( msg != first ) ;
+    
+    FIFO_EnQueue(CmiLocalQueue, msg);
+  }
+  
+  /* receive message from network */
+  while ( 1 ) { /* Loop till proper message is received */
+    
+    while ( (msg = CmiGetNonLocal()) == NULL )
+      ;
+    
+    if ( CmiGetHandler(msg)==lang ) 
+      return (void *)msg ;
+    else
+      FIFO_EnQueue(CmiLocalQueue, msg);
+  }
+  return NULL ;
+}
+
+
+/* This function gets all outstanding messages out of the network, executing
+   their handlers if they are for this lang, else enqueing them in the FIFO 
+   queue */
+int
+CmiClearNetworkAndCallHandlers(lang)
+int lang;
+{
+  int retval = 0;
+  int *msg, *first ;
+  if ( !FIFO_Empty(CmiLocalQueue) ) {
+    
+    FIFO_DeQueue(CmiLocalQueue, &msg);
+    first = msg ;
+    do {
+      if ( CmiGetHandler(msg)==lang ) 
+       {
+         (CmiGetHandlerFunction(msg))(msg);
+         retval = 1;
+       }
+      else
+       FIFO_EnQueue(CmiLocalQueue, msg);
+      FIFO_DeQueue(CmiLocalQueue, &msg);
+    } while ( msg != first ) ;
+    FIFO_EnQueue(CmiLocalQueue, msg);
+  }
+  
+  while ( (msg = CmiGetNonLocal()) != NULL )
+    if ( CmiGetHandler(msg)==lang ) 
+      {
+       (CmiGetHandlerFunction(msg))(msg);
+       retval = 1;
+      }
+    else
+      FIFO_EnQueue(CmiLocalQueue, msg);
+  return retval;
+}
+
+/* 
+  Same as above function except that it does not execute any handler functions
+*/
+int
+CmiClearNetwork(lang)
+int lang;
+{
+  int retval = 0;
+  int *msg, *first ;
+  if ( !FIFO_Empty(CmiLocalQueue) ) {
+    
+    FIFO_DeQueue(CmiLocalQueue, &msg);
+    first = msg ;
+    do {
+      if ( CmiGetHandler(msg)==lang ) 
+         retval = 1;
+      FIFO_EnQueue(CmiLocalQueue, msg);
+      FIFO_DeQueue(CmiLocalQueue, &msg);
+    } while ( msg != first ) ;
+    FIFO_EnQueue(CmiLocalQueue, msg);
+  }
+  while ( (msg = CmiGetNonLocal()) != NULL )
+    {
+      if ( CmiGetHandler(msg)==lang ) 
+       retval = 1;
+      FIFO_EnQueue(CmiLocalQueue, msg);
+    }
+  return retval;
+}
+
+/***************************************************************************
+ *
+ * 
+ ***************************************************************************/
+
+void *CsdSchedQueue;
+int   CsdStopFlag=0;
+
+CsdInit(char **argv)
+{
+  void *CqsCreate();
+  CsdSchedQueue = CqsCreate();
+}
+
+void *CsdGetMsg()
+{
+  int *msg ;
+  
+  if ((msg = CmiGetMsg()) != NULL)
+    return msg;
+  
+  if ( !CqsEmpty(CsdSchedQueue) ) {
+    CqsDequeue(CsdSchedQueue,&msg);
+    return msg ;
+  }
+  
+  return NULL ;
+}
+
+void CsdScheduler(counter)
+int counter;
+{
+  int *msg;
+  
+  while (1) {
+    msg = CsdGetMsg();
+    if (msg)
+      (CmiGetHandlerFunction(msg))(msg);
+    if (CsdStopFlag) break;
+    counter--;
+    if (counter==0) break;
+  }
+}
+/*****************************************************************************
+ *
+ * Convenient initializer/deinitializer for "the whole shebang"
+ *
+ * Note: This module cannot parse arguments, in the long run.  Each
+ * independent module must parse its own arguments.
+ *
+ *****************************************************************************/
+
+static char *DeleteArg(argv)
+  char **argv;
+{
+  char *res = argv[0];
+  if (res==0) { CmiError("Bad arglist."); exit(1); }
+  while (*argv) { argv[0]=argv[1]; argv++; }
+  return res;
+}
+
+static int ConverseParseOptions(argv)
+    char **argv;
+{
+  int sysmem;
+  /*
+   * configure the chare kernel according to command line parameters.
+   * by convention, chare kernel parameters begin with '+'.
+   */
+  while (*argv) {
+    if (strcmp(*argv, "+m") == 0) {
+      DeleteArg(argv);
+      DeleteArg(argv);
+    } else
+    if (sscanf(*argv, "+m%d", &sysmem) == 1) {
+      DeleteArg(argv);
+    } else
+    if (strcmp(*argv, "+mm") == 0) {
+      DeleteArg(argv);
+      DeleteArg(argv);
+    } else
+    if (sscanf(*argv, "+mm%d", &sysmem) == 1) {
+      DeleteArg(argv);
+      DeleteArg(argv);
+    } else
+    if (strcmp(*argv, "+mems") == 0) {
+      CstatPrintMemStatsFlag=1;
+      DeleteArg(argv);
+    } else
+    if (strcmp(*argv, "+qs") == 0) {
+      CstatPrintQueueStatsFlag=1;
+      DeleteArg(argv);
+    } else
+    argv++;
+  }
+}
+
+ConverseInit(argv)
+char **argv;
+{
+  ConverseParseOptions(argv);
+  CmiInit(argv);
+  CsdInit(argv);
+}
+
+ConverseExit()
+{
+  CmiExit();
+}
diff --git a/src/conv-core/converse.h b/src/conv-core/converse.h
new file mode 100644 (file)
index 0000000..23939c6
--- /dev/null
@@ -0,0 +1,94 @@
+
+#ifndef CONVERSE_H
+#define CONVERSE_H
+
+#ifndef _conv_mach_h
+#include "conv-mach.h"
+#endif
+
+/**** DEAL WITH DIFFERENCES: KERNIGHAN-RITCHIE-C, ANSI-C, AND C++ ****/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#if defined(__cplusplus)||defined(__STDC__)
+#define CMK_PROTO(x) x
+#else
+#define CMK_PROTO(x) ()
+#endif
+
+/******** PROTOTYPES FOR CONVERSE TYPES ********/
+
+typedef void (*CmiHandler)();
+typedef void  *CmiCommHandle;
+
+
+/******** PROTOTYPES FOR CMI FUNCTIONS AND MACROS *******/
+
+
+extern CmiHandler *CmiHandlerTable ;
+
+#define CmiMsgHeaderSizeBytes 4
+
+extern int CmiRegisterHandler CMK_PROTO((CmiHandler));
+
+#define CmiGetHandler(env)  (*((int *)(env)))
+
+#define CmiSetHandler(env,x)  (*((int *)(env)) = x)
+
+#define CmiGetHandlerFunction(env) (CmiHandlerTable[CmiGetHandler(env)])
+
+void *CmiGetMsg CMK_PROTO(());
+
+#ifdef CMK_CMIMYPE_IS_A_BUILTIN
+int CmiMyPe CMK_PROTO((void));
+int CmiNumPe CMK_PROTO((void));
+#endif
+
+#ifdef CMK_CMIMYPE_IS_A_VARIABLE
+extern int Cmi_mype;
+extern int Cmi_numpe;
+#define CmiMyPe() Cmi_mype
+#define CmiNumPe() Cmi_numpe
+#endif
+
+void *CmiAlloc  CMK_PROTO((int size));
+int   CmiSize   CMK_PROTO((...));
+void  CmiFree   CMK_PROTO((...));
+
+#ifdef CMK_CMIPRINTF_IS_A_BUILTIN
+void  CmiPrintf CMK_PROTO((...));
+void  CmiError  CMK_PROTO((...));
+int   CmiScanf  CMK_PROTO((...));
+#endif
+
+#ifdef CMK_CMIPRINTF_IS_JUST_PRINTF
+#define CmiPrintf printf
+#define CmiError  printf
+#define CmiScanf  scanf
+#endif
+
+/******** PROTOTYPES FOR CSD FUNCTIONS AND MACROS ********/
+
+extern void   *CsdSchedQueue;
+extern int     CsdStopFlag;
+
+#define CsdExitScheduler()  (CsdStopFlag=1)
+
+#define CsdEnqueue(x)  (CqsEnqueue(CsdSchedQueue,x))
+
+#define CsdEmpty()     (CqsEmpty(CsdSchedQueue))
+
+extern  void  CsdScheduler CMK_PROTO((int));
+extern  void *CsdGetMsg CMK_PROTO(());
+
+/**** DEAL WITH DIFFERENCES: KERNIGHAN-RITCHIE-C, ANSI-C, AND C++ ****/
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif  /* CONVERSE_H */
+
+
diff --git a/src/conv-core/fifo.c b/src/conv-core/fifo.c
new file mode 100644 (file)
index 0000000..1434d69
--- /dev/null
@@ -0,0 +1,89 @@
+
+#include <stdio.h>
+
+typedef struct fifo_queue {
+        void **block;
+        short block_len;
+        short first;
+        short avail;
+        short length;
+} FIFO_QUEUE;
+
+
+#define BLK_LEN 512
+
+void           *
+FIFO_Create()
+{
+       FIFO_QUEUE     *queue;
+       queue = (FIFO_QUEUE *)CmiAlloc(sizeof(FIFO_QUEUE));
+       queue->block = (void **) CmiAlloc(BLK_LEN * sizeof(void *));
+       queue->block_len = BLK_LEN;
+       queue->first = queue->avail = 0;
+       queue->length = 0;
+
+       return (void *) queue;
+}
+
+
+FIFO_Empty(queue)
+FIFO_QUEUE     *queue;
+{
+       return (queue->length == 0) ? 1 : 0;
+}
+
+
+FIFO_EnQueue(queue, element)
+FIFO_QUEUE     *queue;
+void           *element;
+{
+
+       if (!queue->length)     /* Queue is empty */
+       {
+               queue->block[queue->avail] = element;
+               queue->first = queue->avail;
+               queue->avail = (queue->avail + 1) % queue->block_len;
+               queue->length++;
+       }
+       else
+       {
+               if (queue->avail == queue->first)       /* Queue is full */
+               {
+                       void          **blk = queue->block;
+                       int             i, j;
+                       queue->block = (void **) CmiAlloc(sizeof(void *) * (queue->
+                                                            block_len) *3);
+                       for (i = queue->first, j = 0; i < queue->block_len; i++, j++)
+                               queue->block[j] = blk[i];
+                       for (i = 0; i < queue->avail; i++, j++)
+                               queue->block[j] = blk[i];
+                       queue->block[j++] = element;
+                       queue->block_len *= 3;
+                       queue->first = 0;
+                       queue->avail = j;
+                       queue->length++;
+                       CmiFree(blk);
+               }
+               else
+               {
+                       queue->block[queue->avail] = element;
+                       queue->avail = (queue->avail + 1) % queue->block_len;
+                       queue->length++;
+               }
+       }
+
+}
+
+
+FIFO_DeQueue(queue, element)
+FIFO_QUEUE     *queue;
+void      **element;
+{
+       *element = NULL;
+       if (queue->length)
+       {
+               *element = queue->block[queue->first++];
+               queue->first %= queue->block_len;
+               queue->length--;
+       }
+}
diff --git a/src/conv-core/internal.h b/src/conv-core/internal.h
new file mode 100644 (file)
index 0000000..395318c
--- /dev/null
@@ -0,0 +1,3 @@
+#define PVECTOR int
+int   *CmiAlloc();
+void   CmiFree();