Commit 11465c91 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

ENH: add support for machine info file

parent 6333fbea
......@@ -23,7 +23,7 @@
#include <vtkstd/vector>
vtkCxxRevisionMacro(vtkMPIMToNSocketConnection, "1.4");
vtkCxxRevisionMacro(vtkMPIMToNSocketConnection, "1.5");
vtkStandardNewMacro(vtkMPIMToNSocketConnection);
vtkCxxSetObjectMacro(vtkMPIMToNSocketConnection,Controller, vtkMultiProcessController);
......@@ -37,11 +37,13 @@ public:
vtkstd::string HostName;
};
vtkstd::vector<NodeInformation> ServerInformation;
vtkstd::vector<std::string> MachineNames;
};
vtkMPIMToNSocketConnection::vtkMPIMToNSocketConnection()
{
this->MachinesFileName = 0;
this->Socket = 0;
this->HostName = 0;
this->PortNumber = -1;
......@@ -83,6 +85,37 @@ void vtkMPIMToNSocketConnection::PrintSelf(ostream& os, vtkIndent indent)
}
}
void vtkMPIMToNSocketConnection::LoadMachinesFile()
{
unsigned int myId = this->Controller->GetLocalProcessId();
if(!this->MachinesFileName)
{
return;
}
FILE* file = fopen(this->MachinesFileName, "r");
char machinename[1024];
if(!file)
{
vtkErrorMacro("Could not open file : " << this->MachinesFileName);
return;
}
while(!feof(file))
{
if(fgets(machinename, 1024, file) != 0)
{
int pos = strlen(machinename)-1;
if(machinename[pos] == '\n')
{
machinename[pos] = 0;
}
if(strlen(machinename) > 0)
{
this->Internals->MachineNames.push_back(machinename);
}
}
}
fclose(file);
}
void vtkMPIMToNSocketConnection::SetupWaitForConnection()
......@@ -92,13 +125,32 @@ void vtkMPIMToNSocketConnection::SetupWaitForConnection()
vtkErrorMacro("SetupWaitForConnection called more than once");
return;
}
unsigned int myId = this->Controller->GetLocalProcessId();
this->SocketCommunicator = vtkSocketCommunicator::New();
// open a socket on a random port
int sock = this->SocketCommunicator->OpenSocket(0);
// find out the random port picked
int port = this->SocketCommunicator->GetPort(sock);
cout << "found port " << port << "\n";
this->SetHostName("localhost");
if(this->Internals->MachineNames.size())
{
if( myId < this->Internals->MachineNames.size())
{
this->SetHostName(this->Internals->MachineNames[myId].c_str());
}
else
{
vtkErrorMacro("Bad configuration file more processes than machines listed."
<< " Configfile= " << this->MachinesFileName << "\n"
<< " process id = " << myId << "\n"
<< " number of machines in file: " <<
this->Internals->MachineNames.size() << "\n");
this->SetHostName("localhost");
}
}
else
{
this->SetHostName("localhost");
}
this->PortNumber = port;
this->Socket = sock;
this->NumberOfConnections = this->Controller->GetNumberOfProcesses();
......@@ -112,13 +164,13 @@ void vtkMPIMToNSocketConnection::WaitForConnection()
vtkErrorMacro("SetupWaitForConnection must be called before WaitForConnection");
return;
}
int myId = this->Controller->GetLocalProcessId();
if(myId >= this->NumberOfConnections)
unsigned int myId = this->Controller->GetLocalProcessId();
if(myId >= static_cast<unsigned int>(this->NumberOfConnections))
{
return;
}
cout << "WaitForConnection: id :"
<< myId << " host: " << this->HostName << " Port:" << this->PortNumber << "\n";
<< myId << " Port:" << this->PortNumber << "\n";
this->SocketCommunicator->WaitForConnectionOnSocket(this->Socket);
int data;
this->SocketCommunicator->Receive(&data, 1, 1, 1238);
......@@ -162,7 +214,7 @@ void vtkMPIMToNSocketConnection::SetNumberOfConnections(int c)
void vtkMPIMToNSocketConnection::SetPortInformation(unsigned int processNumber,
int port, const char* host)
{
{
if(processNumber >= this->Internals->ServerInformation.size())
{
vtkErrorMacro("Attempt to set port information for process larger than number of processes.\n"
......@@ -186,7 +238,19 @@ void vtkMPIMToNSocketConnection::GetPortInformation(
// not call AddInformation for process 0
if(myId == 0)
{
info->SetPortInformation(0, this->PortNumber, this->HostName);
this->LoadMachinesFile();
info->SetPortNumber(0, this->PortNumber);
if(this->Internals->MachineNames.size() &&
(this->Internals->MachineNames.size()
< static_cast<unsigned int>(info->GetNumberOfConnections())))
{
vtkErrorMacro("Bad Configuration file, expected " << info->GetNumberOfConnections()
<< " machines and found " << this->Internals->MachineNames.size());
}
for(unsigned int i = 0; i < this->Internals->MachineNames.size(); ++i)
{
info->SetHostName(i, this->Internals->MachineNames[i].c_str());
}
}
info->SetHostName(this->HostName);
info->SetProcessNumber(myId);
......
......@@ -62,8 +62,9 @@ public:
// Description:
// Fill the port information values into the port information object.
void GetPortInformation(vtkMPIMToNSocketConnectionPortInformation*);
vtkSetStringMacro(MachinesFileName);
protected:
void LoadMachinesFile();
virtual void SetController(vtkMultiProcessController*);
virtual void SetSocketCommunicator(vtkSocketCommunicator*);
vtkMPIMToNSocketConnection();
......@@ -72,6 +73,7 @@ private:
int PortNumber;
int Socket;
char* HostName;
char* MachinesFileName;
vtkSetStringMacro(HostName);
int NumberOfConnections;
vtkMPIMToNSocketConnectionInternals* Internals;
......
......@@ -34,7 +34,7 @@ public:
vtkStandardNewMacro(vtkMPIMToNSocketConnectionPortInformation);
vtkCxxRevisionMacro(vtkMPIMToNSocketConnectionPortInformation, "1.1");
vtkCxxRevisionMacro(vtkMPIMToNSocketConnectionPortInformation, "1.2");
//----------------------------------------------------------------------------
vtkMPIMToNSocketConnectionPortInformation::vtkMPIMToNSocketConnectionPortInformation()
......@@ -85,15 +85,23 @@ void vtkMPIMToNSocketConnectionPortInformation::CopyFromObject(vtkObject* obj)
}
void vtkMPIMToNSocketConnectionPortInformation::SetPortInformation(unsigned int processNumber,
int port,
const char* hostname)
void vtkMPIMToNSocketConnectionPortInformation::SetPortNumber(unsigned int processNumber,
int port)
{
if(this->Internals->ServerInformation.size() == 0)
{
this->Internals->ServerInformation.resize(this->NumberOfConnections);
}
this->Internals->ServerInformation[processNumber].PortNumber = port;
}
void vtkMPIMToNSocketConnectionPortInformation::SetHostName(unsigned int processNumber,
const char* hostname)
{
if(this->Internals->ServerInformation.size() == 0)
{
this->Internals->ServerInformation.resize(this->NumberOfConnections);
}
this->Internals->ServerInformation[processNumber].HostName = hostname;
}
......@@ -107,7 +115,7 @@ void vtkMPIMToNSocketConnectionPortInformation::AddInformation(vtkPVInformation*
vtkErrorMacro("Wrong type for AddInformation" << i);
return;
}
this->SetPortInformation(info->ProcessNumber, info->PortNumber, info->HostName);
this->SetPortNumber(info->ProcessNumber, info->PortNumber);
}
//----------------------------------------------------------------------------
......
......@@ -48,7 +48,8 @@ public:
// Description:
// Set the port and host information for a specific process number.
void SetPortInformation(unsigned int processNumber, int port, const char* host);
void SetPortNumber(unsigned int processNumber, int port);
void SetHostName(unsigned int processNumber, const char* host);
// Description:
// Set/Get the number of connections.
......
......@@ -107,7 +107,7 @@
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVApplication);
vtkCxxRevisionMacro(vtkPVApplication, "1.264");
vtkCxxRevisionMacro(vtkPVApplication, "1.265");
vtkCxxSetObjectMacro(vtkPVApplication, RenderModule, vtkPVRenderModule);
......@@ -412,6 +412,7 @@ Tcl_Interp *vtkPVApplication::InitializeTcl(int argc,
//----------------------------------------------------------------------------
vtkPVApplication::vtkPVApplication()
{
this->MachinesFileName = 0;
this->ProgressEnabled = 0;
this->ProgressRequests = 0;
this->Observer = vtkPVApplicationObserver::New();
......@@ -598,6 +599,8 @@ const char vtkPVApplication::ArgumentList[vtkPVApplication::NUM_ARGS][128] =
"Run ParaView as client (MPI run, 1 process) (ParaView Server must be started first).",
"--client-render-server" , "-crs",
"Run ParaView as client (MPI run, 1 process) (ParaView Data Server and Render Server must be started first).",
"--machines" , "-m",
"Specify the network configurations file for the render server (--machines=cfgfile).",
"--server" , "-v",
"Start ParaView as a server (use MPI run).",
"--render-server" , "-rs",
......@@ -1028,7 +1031,7 @@ int vtkPVApplication::ParseCommandLineArguments(int argc, char*argv[])
if ( vtkPVApplication::CheckForArgument(argc, argv, "--render-server-host",
index) == VTK_OK ||
vtkPVApplication::CheckForArgument(argc, argv, "-rsh",
index) == VTK_OK )
index) == VTK_OK )
{
// Strip string to equals sign.
const char* newarg=0;
......@@ -1058,6 +1061,25 @@ int vtkPVApplication::ParseCommandLineArguments(int argc, char*argv[])
}
this->Port = atoi(newarg);
}
if ( vtkPVApplication::CheckForArgument(argc, argv, "--machines",
index) == VTK_OK ||
vtkPVApplication::CheckForArgument(argc, argv, "-m",
index) == VTK_OK)
{
// Strip string to equals sign.
const char* newarg=0;
int len = (int)(strlen(argv[index]));
for (i=0; i<len; i++)
{
if (argv[index][i] == '=')
{
newarg = &(argv[index][i+1]);
}
}
this->SetMachinesFileName(newarg);
}
if ( vtkPVApplication::CheckForArgument(argc, argv, "--render-port",
index) == VTK_OK)
{
......
......@@ -312,6 +312,10 @@ public:
// This path is used to locate demos etc.
vtkGetStringMacro(Argv0);
// Description:
// This is used by the render server only.
vtkGetStringMacro(MachinesFileName);
// Description:
// The name of the trace file.
vtkGetStringMacro(TraceFileName);
......@@ -462,6 +466,8 @@ protected:
void DeleteTraceFiles(char* name, int all);
void SaveTraceFile(const char* fname);
vtkSetStringMacro(MachinesFileName);
char* MachinesFileName;
vtkSetStringMacro(TraceFileName);
char* TraceFileName;
char* Argv0;
......
......@@ -145,7 +145,7 @@ void vtkPVSendStreamToClientServerNodeRMI(void *localArg, void *remoteArg,
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVClientServerModule);
vtkCxxRevisionMacro(vtkPVClientServerModule, "1.67");
vtkCxxRevisionMacro(vtkPVClientServerModule, "1.68");
int vtkPVClientServerModuleCommand(ClientData cd, Tcl_Interp *interp,
int argc, char *argv[]);
......@@ -623,6 +623,13 @@ void vtkPVClientServerModule::InitializeRenderServer()
// now tell the render server to find out what ports it is going
// to use
this->GetStream()
<< vtkClientServerStream::Invoke
<< this->GetApplicationID() << "GetMachinesFileName" << vtkClientServerStream::End;
this->GetStream()
<< vtkClientServerStream::Invoke << id << "SetMachinesFileName"
<< vtkClientServerStream::LastResult
<< vtkClientServerStream::End;
this->GetStream()
<< vtkClientServerStream::Invoke << id << "SetupWaitForConnection"
<< vtkClientServerStream::End;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment