Skip to content
Snippets Groups Projects
Commit 914f0aba authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better gestion of remote messages ("a la getdp")
parent 102c74e3
No related branches found
No related tags found
No related merge requests found
......@@ -129,7 +129,7 @@ void GetOptions(int argc, char *argv[])
if(!strcmp(argv[i] + 1, "socket")) {
i++;
if(argv[i])
CTX::instance()->solver.socketName = argv[i++];
Msg::InitClient(argv[i++]);
else
Msg::Fatal("Missing string");
CTX::instance()->batch = -3;
......
......@@ -139,7 +139,7 @@ int GmshBatch()
#endif
if(CTX::instance()->batch == -3){
GmshRemote(CTX::instance()->solver.socketName);
GmshRemote();
}
else if(CTX::instance()->batch == -2){
GModel::current()->checkMeshCoherence(CTX::instance()->geom.tolerance);
......@@ -167,5 +167,7 @@ int GmshBatch()
currtime.resize(currtime.size() - 1);
Msg::Info("Stopped on %s", currtime.c_str());
Msg::FinalizeClient();
return 1;
}
......@@ -9,6 +9,7 @@
#include <time.h>
#include "GmshConfig.h"
#include "GmshMessage.h"
#include "GmshSocket.h"
#include "Gmsh.h"
#include "Options.h"
#include "Context.h"
......@@ -36,6 +37,7 @@ int Msg::_errorCount = 0;
GmshMessage *Msg::_callback = 0;
std::string Msg::_commandLine;
std::string Msg::_launchDate;
GmshClient *Msg::_client = 0;
#if defined(HAVE_NO_VSNPRINTF)
static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
......@@ -118,6 +120,7 @@ void Msg::Fatal(const char *fmt, ...)
va_end(args);
if(_callback) (*_callback)("Fatal", str);
if(_client) _client->Error(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -158,6 +161,7 @@ void Msg::Error(const char *fmt, ...)
va_end(args);
if(_callback) (*_callback)("Error", str);
if(_client) _client->Error(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -190,6 +194,7 @@ void Msg::Warning(const char *fmt, ...)
va_end(args);
if(_callback) (*_callback)("Warning", str);
if(_client) _client->Warning(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -216,6 +221,7 @@ void Msg::Info(const char *fmt, ...)
va_end(args);
if(_callback) (*_callback)("Info", str);
if(_client) _client->Info(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -255,6 +261,7 @@ void Msg::Direct(int level, const char *fmt, ...)
va_end(args);
if(_callback) (*_callback)("Direct", str);
if(_client) _client->Info(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -288,6 +295,7 @@ void Msg::StatusBar(int num, bool log, const char *fmt, ...)
va_end(args);
if(_callback && log) (*_callback)("Info", str);
if(_client && log) _client->Info(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -318,6 +326,7 @@ void Msg::Debug(const char *fmt, ...)
va_end(args);
if(_callback) (*_callback)("Debug", str);
if(_client) _client->Info(str);
#if defined(HAVE_FLTK)
if(FlGui::available()){
......@@ -498,6 +507,29 @@ bool Msg::GetBinaryAnswer(const char *question, const char *yes,
}
}
void Msg::InitClient(std::string sockname)
{
if(_client) delete _client;
_client = new GmshClient();
if(_client->Connect(sockname.c_str()) < 0){
Msg::Error("Unable to connect to server on %s", sockname.c_str());
delete _client;
_client = 0;
}
else
_client->Start();
}
void Msg::FinalizeClient()
{
if(_client){
_client->Stop();
_client->Disconnect();
delete _client;
}
_client = 0;
}
void Msg::Barrier()
{
#if defined(HAVE_MPI)
......@@ -520,3 +552,4 @@ int Msg::GetMaxThreads(){ return 1; }
int Msg::GetThreadNum(){ return 0; }
#endif
......@@ -10,6 +10,8 @@
#include <string>
#include <stdarg.h>
class GmshClient;
// the external message handler
class GmshMessage{
public:
......@@ -36,6 +38,8 @@ class Msg {
static GmshMessage *_callback;
// command-line and startup time
static std::string _commandLine, _launchDate;
// communication with Gmsh when run remotely
static GmshClient *_client;
public:
Msg() {}
static void Init(int argc, char **argv);
......@@ -72,6 +76,9 @@ class Msg {
static double GetValue(const char *text, double defaultval);
static bool GetBinaryAnswer(const char *question, const char *yes,
const char *no, bool defaultval=true);
static void InitClient(std::string sockname);
static GmshClient *GetClient(){ return _client; }
static void FinalizeClient();
};
#endif
// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#include <sstream>
#include "GmshMessage.h"
#include "GmshSocket.h"
......@@ -7,12 +12,9 @@
#include "PViewOptions.h"
#include "PViewData.h"
#include "VertexArray.h"
#include "Context.h"
static void computeAndSendVertexArrays(GmshClient &client)
static void computeAndSendVertexArrays(GmshClient *client)
{
CTX::instance()->terminal = 1; // debug
client.Info("Sending vertex arrays");
for(unsigned int i = 0; i < PView::list.size(); i++){
PView *p = PView::list[i];
p->fillVertexArrays();
......@@ -32,54 +34,48 @@ static void computeAndSendVertexArrays(GmshClient &client)
(p->getNum(), data->getName(), type + 1, min, max,
data->getNumTimeSteps(), data->getTime(opt->timeStep),
data->getBoundingBox(), len);
client.SendMessage(GmshSocket::GMSH_VERTEX_ARRAY, len, str);
client->SendMessage(GmshSocket::GMSH_VERTEX_ARRAY, len, str);
delete [] str;
}
}
}
}
int GmshRemote(std::string socket)
int GmshRemote()
{
GmshClient client;
GmshClient *client = Msg::GetClient();
if(client.Connect(socket.c_str()) < 0){
Msg::Error("Unable to connect to server on %s", socket.c_str());
return 1;
}
client.Start();
client.Info("Remote Gmsh sucessfully started");
if(!client) return 0;
computeAndSendVertexArrays(client);
client.Info("Remote Gmsh is listening...");
while(1){
// stop if we have no communications for 5 minutes
int ret = client.Select(300, 0);
int ret = client->Select(300, 0);
if(!ret){
client.Info("Timout: stopping remote Gmsh...");
client->Info("Timout: stopping remote Gmsh...");
break;
}
else if(ret < 0){
client.Error("Error on select: stopping remote Gmsh...");
client->Error("Error on select: stopping remote Gmsh...");
break;
}
int type, length;
if(!client.ReceiveHeader(&type, &length)){
client.Error("Did not receive message header: stopping remote Gmsh...");
if(!client->ReceiveHeader(&type, &length)){
client->Error("Did not receive message header: stopping remote Gmsh...");
break;
}
char *msg = new char[length + 1];
if(!client.ReceiveString(length, msg)){
client.Error("Did not receive message body: stopping remote Gmsh...");
if(!client->ReceiveString(length, msg)){
client->Error("Did not receive message body: stopping remote Gmsh...");
delete [] msg;
break;
}
if(type == GmshSocket::GMSH_STOP){
client.Info("Stopping remote Gmsh...");
client->Info("Stopping remote Gmsh...");
break;
}
else if(type == GmshSocket::GMSH_VERTEX_ARRAY){
......@@ -94,20 +90,16 @@ int GmshRemote(std::string socket)
ParseString(msg);
}
else if(type == GmshSocket::GMSH_SPEED_TEST){
client.Info("Sending huge array");
client->Info("Sending huge array");
std::string huge(500000000, 'a');
client.SpeedTest(huge.c_str());
client->SpeedTest(huge.c_str());
}
else{
client.Error("Ignoring unknown message");
client->Error("Ignoring unknown message");
}
delete [] msg;
}
client.Info("Remote Gmsh is stopped");
client.Stop();
client.Disconnect();
return 0;
}
......@@ -8,7 +8,7 @@
#include <string>
int GmshRemote(std::string socket);
int GmshRemote();
#endif
......@@ -123,7 +123,6 @@ void VertexArray::finalize()
_data3.clear();
}
_barycenters.clear();
//printf("vert array : %d Mb\n", getMemoryUsage());
}
class AlphaElement {
......@@ -210,11 +209,11 @@ void VertexArray::sort(double x, double y, double z)
_colors = sortedColors;
}
int VertexArray::getMemoryUsage()
double VertexArray::getMemoryInMb()
{
int bytes = _vertices.size() * sizeof(float) + _normals.size() * sizeof(char) +
_colors.size() * sizeof(unsigned char);
return bytes / 1024 / 1024;
return (double)bytes / 1024. / 1024.;
}
char *VertexArray::toChar(int num, std::string name, int type, double min, double max,
......
......@@ -161,7 +161,7 @@ class VertexArray{
// sort the arrays with elements back to front wrt the eye position
void sort(double x, double y, double z);
// estimate the size of the vertex array in megabytes
int getMemoryUsage();
double getMemoryInMb();
// serialize the vertex array into a string (for sending over the
// network)
char *toChar(int num, std::string name, int type, double min, double max,
......
......@@ -1114,9 +1114,11 @@ class initPView {
p->va_triangles->finalize();
p->va_vectors->finalize();
Msg::Info("%d vertices in vertex arrays", p->va_points->getNumVertices() +
Msg::Info("%d vertices in vertex arrays (%g Mb)", p->va_points->getNumVertices() +
p->va_lines->getNumVertices() + p->va_triangles->getNumVertices() +
p->va_vectors->getNumVertices());
p->va_vectors->getNumVertices(), p->va_points->getMemoryInMb() +
p->va_lines->getMemoryInMb() + p->va_triangles->getMemoryInMb() +
p->va_vectors->getMemoryInMb());
p->setChanged(false);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment