netgen/ng/parallelfunc.cpp

363 lines
8.1 KiB
C++
Raw Normal View History

2022-04-27 01:00:25 +05:00
#ifdef OLDFILE
2009-01-25 07:54:27 +05:00
#ifdef PARALLEL
2011-02-14 17:27:18 +05:00
#include "dlfcn.h"
2009-01-25 07:54:27 +05:00
// #include <mystdlib.h>
#include <meshing.hpp>
// #include "incvis.hpp"
#include <visual.hpp>
#ifdef PARALLELGL
#ifndef WIN32
#define GLX_GLXEXT_LEGACY
#define GLX_GLXEXT_PROTOTYPES
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h> /* for XA_RGB_DEFAULT_MAP atom */
#include <GL/glx.h>
#include <GL/glxext.h>
#endif
#endif
#include <meshing.hpp>
2016-07-15 18:26:25 +05:00
#include "../interface/writeuser.hpp"
2009-01-25 07:54:27 +05:00
2011-02-14 17:27:18 +05:00
void (*NGS_ParallelRun) (const string & message) = NULL;
2009-01-25 07:54:27 +05:00
namespace netgen
{
extern string ngdir;
#ifdef OPENGL
extern VisualSceneMesh vsmesh;
#endif
}
void Parallel_Exit();
namespace netgen {
2014-10-14 02:35:28 +06:00
extern std::shared_ptr<NetgenGeometry> ng_geometry;
2014-09-08 21:21:09 +06:00
extern shared_ptr<Mesh> mesh;
2011-02-14 18:01:51 +05:00
extern VisualSceneMesh vsmesh;
2017-09-21 20:58:38 +05:00
extern VisualSceneSolution & GetVSSolution();
2012-06-16 18:10:38 +06:00
extern Flags parameters;
2012-07-05 17:05:33 +06:00
extern DLL_HEADER MeshingParameters mparam;
2009-01-25 07:54:27 +05:00
}
using namespace netgen;
using netgen::RegisterUserFormats;
2011-02-14 17:27:18 +05:00
2009-01-25 07:54:27 +05:00
void ParallelRun()
{
2017-09-21 20:58:38 +05:00
VisualSceneSolution vssolution = GetVSSolution();
2009-01-25 07:54:27 +05:00
string message;
MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
2019-05-28 16:51:53 +05:00
if (parameters.StringFlagDefined ("testout"))
{
delete testout;
testout = new ofstream (string("testout_proc") + id );
}
2012-08-20 20:10:50 +06:00
2012-06-16 18:10:38 +06:00
2009-01-25 07:54:27 +05:00
2012-06-13 17:37:13 +06:00
while ( true )
2009-01-25 07:54:27 +05:00
{
2011-07-15 03:36:19 +06:00
message = MyMPI_RecvCmd();
2016-11-08 16:57:59 +05:00
2009-01-25 07:54:27 +05:00
if ( message.compare(0, 3, "ngs") == 0 )
{
2011-06-16 23:55:08 +06:00
// PrintMessage ( 1, "Starting NgSolve routine ", message ) ;
2011-02-14 17:27:18 +05:00
if (NGS_ParallelRun == NULL)
{
2012-06-19 00:40:25 +06:00
static int timer = NgProfiler::CreateTimer ("load shared library ngsolve");
NgProfiler::RegionTimer reg (timer);
2011-02-14 17:27:18 +05:00
void * handle = dlopen ("libngsolve.so", RTLD_NOW | RTLD_GLOBAL);
if (!handle)
{
cerr << "cannot load shared library libngsolve.so" << endl;
exit(1);
}
NGS_ParallelRun = (void (*) (const string & message)) dlsym (handle, "NGS_ParallelRun");
if (!NGS_ParallelRun)
{
cerr << "cannot bind function NGS_ParallelRun" << endl;
exit(1);
}
}
(*NGS_ParallelRun) (message);
2009-01-25 07:54:27 +05:00
}
2011-07-22 02:52:45 +06:00
else if ( message == "mesh" )
{
VT_USER_START ("Mesh::ReceiveParallelMesh");
2014-09-10 22:15:35 +06:00
mesh.reset( new netgen::Mesh);
2011-07-22 02:52:45 +06:00
mesh->SendRecvMesh();
2015-01-09 15:33:06 +05:00
// vsmesh.SetMesh (mesh);
// vssolution.SetMesh (mesh);
SetGlobalMesh (mesh);
2011-07-22 02:52:45 +06:00
VT_USER_END ("Mesh::ReceiveParallelMesh");
}
else if ( message == "visualize" )
{
cout << "parallel message visualize depreciated" << endl;
}
else if ( message == "bcastparthread" )
{
2019-02-13 02:11:55 +05:00
MyMPI_Bcast (mparam.parthread, MPI_COMM_WORLD);
2011-07-22 02:52:45 +06:00
}
2009-01-25 07:54:27 +05:00
#ifdef PARALLELGL
2011-07-22 02:52:45 +06:00
else if ( message == "redraw" )
{
// draw into the same GLX - drawing context
// works on parallel machine, but
// did not manage to get glXImportContextEXT working on Laptop (JS)
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
string redraw_cmd;
// MyMPI_Recv (redraw_cmd, 0, MPI_TAG_VIS);
redraw_cmd = MyMPI_RecvCmd();
2011-07-22 02:52:45 +06:00
// PrintMessage (1, "Redraw - ", redraw_cmd);
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
static string displname;
static int curDrawable, contextid;
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
static Display * display = NULL;
static GLXContext context;
static XVisualInfo * visinfo = 0;
2011-07-22 02:52:45 +06:00
// if (!display)
if (redraw_cmd == "init")
{
MyMPI_Recv (displname, 0, MPI_TAG_VIS);
MyMPI_Recv (curDrawable, 0, MPI_TAG_VIS);
MyMPI_Recv (contextid, 0, MPI_TAG_VIS);
display = XOpenDisplay (displname.c_str());
2016-11-08 16:57:59 +05:00
2011-07-22 02:52:45 +06:00
/*
PrintMessage (3, "displ - name = ", displname);
PrintMessage (3, "display = ", display,
" display props: ",
" screen w = ", XDisplayWidth (display, 0),
" , h = ", XDisplayHeight (display, 0));
*/
2016-11-08 16:57:59 +05:00
/*
Window win;
int wx, wy;
unsigned int ww, wh, bw, depth;
cout << "got drawable: " << curDrawable << ", contextid: " << contextid << endl;
2009-01-25 07:54:27 +05:00
2016-11-08 16:57:59 +05:00
cout << "get geometriy..." << endl;
XGetGeometry(display, curDrawable, &win,
&wx, &wy, &ww, &wh,
&bw, &depth);
cout << "have!" << endl;
2016-11-08 16:57:59 +05:00
cout << "P" << id << ": window-props: x = " << wx << ", y = " << wy
<< ", w = " << ww << ", h = " << wh << ", depth = " << depth << endl;
*/
2009-01-25 07:54:27 +05:00
#define VISUAL
#ifdef VISUAL
#ifdef VISINFO_OLD
//this does not seem to work anymore (but might still be with togl1.7?)
2011-07-22 02:52:45 +06:00
// make a new GLXContext
// first, generate a visual (copied from togl)
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
int attrib_list[1000];
2009-01-25 07:54:27 +05:00
# define MAX_ATTEMPTS 12
2011-07-22 02:52:45 +06:00
static int ci_depths[MAX_ATTEMPTS] = {
8, 4, 2, 1, 12, 16, 8, 4, 2, 1, 12, 16
};
static int dbl_flags[MAX_ATTEMPTS] = {
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1
};
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
/* It may take a few tries to get a visual */
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
for (int attempt = 0; attempt < MAX_ATTEMPTS; attempt++)
{
int attrib_count = 0;
attrib_list[attrib_count++] = GLX_USE_GL;
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
/* RGB[A] mode */
attrib_list[attrib_count++] = GLX_RGBA;
attrib_list[attrib_count++] = GLX_RED_SIZE;
attrib_list[attrib_count++] = 1;
attrib_list[attrib_count++] = GLX_GREEN_SIZE;
attrib_list[attrib_count++] = 1;
attrib_list[attrib_count++] = GLX_BLUE_SIZE;
attrib_list[attrib_count++] = 1;
// attrib_list[attrib_count++] = GLX_ALPHA_SIZE;
// attrib_list[attrib_count++] = 1;
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
attrib_list[attrib_count++] = GLX_DEPTH_SIZE;
attrib_list[attrib_count++] = 1;
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
attrib_list[attrib_count++] = GLX_DOUBLEBUFFER;
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
attrib_list[attrib_count++] = None;
2016-11-08 16:57:59 +05:00
2011-07-22 02:52:45 +06:00
visinfo = glXChooseVisual(display, 0,
attrib_list);
cout << "have vis?" << endl;
2016-11-08 16:57:59 +05:00
2011-07-22 02:52:45 +06:00
if (visinfo) {
/* found a GLX visual! */
2016-11-08 16:57:59 +05:00
// cout << "found VISINFO !!!" << endl;
cout << "found VISINFO !!!" << endl;
2009-01-25 07:54:27 +05:00
2016-11-08 16:57:59 +05:00
/*
int hi = 0;
std::cout << "attribs = ";
while (attrib_list[hi] != None)
2011-07-22 02:52:45 +06:00
std::cout << attrib_list[hi++] << " ";
std::cout << std::endl;
2016-11-08 16:57:59 +05:00
*/
2011-07-22 02:52:45 +06:00
break;
2009-01-25 07:54:27 +05:00
}
2011-07-22 02:52:45 +06:00
}
if (!visinfo)
cerr << "no VISINFO found" << endl;
2009-01-25 07:54:27 +05:00
#else
2016-11-08 16:57:59 +05:00
//get all possible confs
int nconfs;
auto cptr = glXGetFBConfigs (display,0, &nconfs);
2019-07-09 13:39:16 +05:00
NgArray<int> conf_ids(nconfs);
for(int k=0;k<nconfs;k++)
glXGetFBConfigAttrib(display, cptr[k], GLX_FBCONFIG_ID, &(conf_ids[k]));
2016-11-08 16:57:59 +05:00
//get drawable->FBConfig->visual
unsigned int d_fbc_id;
glXQueryDrawable( display, curDrawable, GLX_FBCONFIG_ID, &d_fbc_id);
GLXFBConfig d_fbc;
for(int k=0;k<nconfs;k++)
if(d_fbc_id==conf_ids[k])
d_fbc = cptr[k];
visinfo = glXGetVisualFromFBConfig(display,d_fbc);
#endif
2011-07-22 02:52:45 +06:00
// context = glXCreateContext( display, visinfo, 0, /* curContext, */ False );
context = glXCreateContext( display, visinfo, glXImportContextEXT ( display, contextid ), False);
glXMakeCurrent (display, curDrawable, context);
2009-01-25 07:54:27 +05:00
#else
2011-07-22 02:52:45 +06:00
// try to get GLXcontext from the master.
// this needs an indirect context (BUT DOES NOT WORK ????)
2011-07-22 02:52:45 +06:00
context = glXImportContextEXT ( display, contextid );
2009-01-25 07:54:27 +05:00
PrintMessage (1, "GLX-contextid = " , contextid,
" imported context ", context);
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
glXMakeCurrent (display, curDrawable, context);
2009-01-25 07:54:27 +05:00
#endif
2011-07-22 02:52:45 +06:00
// PrintMessage (1, "redraw - init complete");
}
2016-11-08 16:57:59 +05:00
2011-07-22 02:52:45 +06:00
if (redraw_cmd == "broadcast")
{
vsmesh.Broadcast ();
}
if (redraw_cmd == "linelist")
{
// glXMakeCurrent (display, curDrawable, context);
vsmesh.BuildLineList();
// glXMakeCurrent (display, None, NULL);
}
if (redraw_cmd == "filledlist")
{
vsmesh.BuildFilledList (false);
}
if (redraw_cmd == "solsurfellist")
{
vssolution.DrawSurfaceElements();
}
2012-08-20 20:10:50 +06:00
if (redraw_cmd == "solsurfellinelist")
{
vssolution.DrawSurfaceElementLines();
}
2011-07-22 02:52:45 +06:00
if (redraw_cmd == "clipplanetrigs")
{
vssolution.DrawClipPlaneTrigs();
}
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
if (redraw_cmd == "getminmax")
{
double hmin, hmax;
vssolution.GetMinMax (-1, -1, hmin, hmax);
}
}
2009-01-25 07:54:27 +05:00
#endif
2011-07-22 02:52:45 +06:00
else if ( message == "end" )
{
2014-10-14 02:35:28 +06:00
mesh.reset();
ng_geometry.reset();
2012-06-13 17:37:13 +06:00
break;
2011-07-22 02:52:45 +06:00
}
2009-01-25 07:54:27 +05:00
2011-07-22 02:52:45 +06:00
else
{
PrintMessage ( 1, "received unidentified message '" + message + "'\n");
2012-06-13 17:37:13 +06:00
break;
2011-07-22 02:52:45 +06:00
}
2009-01-25 07:54:27 +05:00
}
2011-07-22 02:52:45 +06:00
}
2009-01-25 07:54:27 +05:00
2022-04-27 01:00:25 +05:00
#endif
2009-01-25 07:54:27 +05:00
#endif