Commits

Jay Barra  committed 4c5303e

pretty much starting over, but smoother so far

  • Participants
  • Parent commits e2ef6c5

Comments (0)

Files changed (1)

File Firefly/main.cpp

 #include <string.h>
 #include <mpi.h>
 //---------------------------------------------------------------------------
-#include "mpiNode.h"
+#define ROOT 0
+
+#define MESSAGE_TAG 1000
+#define WORK_TAG    1001
+//---------------------------------------------------------------------------
+void getStatus(MPI_Status status, char* pcStatus);
 //---------------------------------------------------------------------------
 main (int argc, char** argv)
 {
-	MPI::Init(argc, argv);
+  MPI_Init(&argc, &argv);
 	
-	mpiNode* node = new mpiNode(argc, argv);
-	node->run();
+  int iNameLen;
+  int iNodes;
+  int id;
+  
+  MPI_Status status;
+ 
+  char* pcName    = (char*)malloc(1024);
+  char* pcMessage = (char*)malloc(1024);
+  char* pcStatus  = (char*)malloc(1024);
+  
+  MPI_Comm_rank(MPI_COMM_WORLD, &id);
+  MPI_Comm_size(MPI_COMM_WORLD, &iNodes);
+  MPI_Get_processor_name(pcName, &iNameLen);
+  
+  bool bRoot = (id == ROOT);
+
+  if (!bRoot) {
+    sprintf(pcMessage, "%i", id, pcName);
+    MPI_Send(pcMessage, strlen(pcMessage)+1, MPI_CHAR, ROOT, MESSAGE_TAG, MPI_COMM_WORLD);
+  } else {
+    printf("Initializing Nodes\n");
+    printf("*********************************************************\n");
+    printf("Root Node: %s\n", pcName);
+    printf("Awaiting worker node responses...\n");
+    for (int iSource = 1; iSource < iNodes; iSource++) {
+      MPI_Recv(pcMessage, 1024, MPI_CHAR, iSource, MESSAGE_TAG, MPI_COMM_WORLD, &status);
+      getStatus(status, pcStatus);
+      printf("AgentNode: %s\t| Status: %s\n", pcMessage, pcStatus);
+    }
+    printf("Node initialization complete...\n");
+    printf("%i Nodes Registered for work...\n", iNodes);
+    printf("*********************************************************\n");
+  }
+
 
-	MPI::Finalize();
-	delete node;
-	return 0;
+
+  MPI_Finalize();
+  
+  return 0; 
+}
+//-------------------------------------------------
+void getStatus(MPI_Status status, char* pcStatus)
+{
+switch (status.MPI_ERROR) {
+	case MPI_SUCCESS:
+		sprintf(pcStatus, "Success");
+		break;
+	case MPI_ERR_BUFFER:
+		sprintf(pcStatus, "Buffer Error");
+		break;
+	case MPI_ERR_COUNT:
+		sprintf(pcStatus, "Count Error");
+		break;
+	case MPI_ERR_TYPE:
+		sprintf(pcStatus, "Type Error");
+		break;
+	case MPI_ERR_TAG:
+		sprintf(pcStatus, "Tag Error");
+		break;
+	case MPI_ERR_COMM:
+		sprintf(pcStatus, "COMM Error");
+		break;
+	case MPI_ERR_RANK:
+		sprintf(pcStatus, "Rank Error");
+		break;
+	case MPI_ERR_REQUEST:
+		sprintf(pcStatus, "Request Error");
+		break;
+	case MPI_ERR_ROOT:
+		sprintf(pcStatus, "Root Error");
+		break;
+	case MPI_ERR_GROUP:
+		sprintf(pcStatus, "Group Error");
+		break;	
+	case MPI_ERR_OP:
+		sprintf(pcStatus, "OP Error");
+		break;
+	case MPI_ERR_TOPOLOGY:
+		sprintf(pcStatus, "Topology Error");
+		break;
+	case MPI_ERR_DIMS:
+		sprintf(pcStatus, "DIMS Error");
+		break;
+	case MPI_ERR_ARG:
+		sprintf(pcStatus, "Args Error");
+		break;
+	case MPI_ERR_UNKNOWN:
+		sprintf(pcStatus, "Unknown Error");
+		break;
+	case MPI_ERR_TRUNCATE:
+		sprintf(pcStatus, "Truncate Error");
+		break;	
+	case MPI_ERR_OTHER:
+		sprintf(pcStatus, "Other Error");
+		break;	
+	case MPI_ERR_INTERN:
+		sprintf(pcStatus, "Internal Error");
+		break;
+	case MPI_ERR_IN_STATUS:
+		sprintf(pcStatus, "In Status Error");
+		break;
+	case MPI_ERR_PENDING:
+		sprintf(pcStatus, "Pending Error");
+		break;
+	default:
+		sprintf(pcStatus, "Unknown Error");
+  }
 }
-//----------------------------------------------------------------------------
+//------------------------------------------------