[vtkusers] vtkMPIController

seafloat at sohu.com seafloat at sohu.com
Thu Apr 1 20:06:16 EST 2004


Dear All:
   When I compile a program In VC++, I meet with a error.It is that "ParallelIso.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class vtkMPIController * __cdecl vtkMPIController::New(void)" (__imp_?New at vtkMPIController@@SAPAV1 at XZ)". I have setting the Include files -c:program filesvtk42includevtk, and the library files-c:program filesvtk42libvtk, and also add vtkcommon.lib vtkfiltering.lib vtkgraphics.lib vtkimaging.lib vtkIO.lib vtkRendering.lib vtkParallel.lib in link settings. Why is it?
   Thank you very much.
the program is:
#include "vtkImageReader.h"
#include "vtkContourFilter.h"
#include "vtkAppendPolyData.h"
#include "vtkOutputPort.h"
#include "vtkInputPort.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkElevationFilter.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTimerLog.h"
#include "vtkMath.h"
#include "vtkMultiProcessController.h"
#include "vtkMPIController.h"
#include "vtkCamera.h"
#include "vtkPolyData.h"


static const float ISO_VALUE=500.0;

// Just pick a tag which is available
static const int ISO_VALUE_RMI_TAG=300; 
static const int PORT_TAG=999;

// This will be called by all processes

void MyMain( vtkMultiProcessController *controller, void *arg )
{
  vtkImageReader *reader;
  vtkContourFilter *iso;
  vtkElevationFilter *elev;
  int myid, numProcs;
  float val;
  int numTris,numTris0;
 // char* fname = reinterpret_cast<char*>(arg); 
  char * fname = "D:/VTKData/Data/headsq/quarter";
  
  myid = controller->GetLocalProcessId(); 
  numProcs = controller->GetNumberOfProcesses(); 
    
  // Create the reader, the data file name might have
  // to be changed depending on where the data files are.
  reader = vtkImageReader::New();  
  reader->SetDataByteOrderToLittleEndian(); 
								
  reader->SetDataExtent(0, 63, 0, 63, 1, 93); 
  reader->SetFilePrefix(fname);   
							
  reader->SetDataSpacing(3.2, 3.2, 1.5); 

  iso = vtkContourFilter::New();
  iso->SetInput((vtkDataSet*)reader->GetOutput());
  iso->SetValue(0, ISO_VALUE);   
  iso->ComputeScalarsOff();
  iso->ComputeGradientsOff();
  

  elev = vtkElevationFilter::New();  
  elev->SetInput((vtkDataSet*)iso->GetOutput());
  vtkMath::RandomSeed(myid * 100);
  val = vtkMath::Random();
  elev->SetScalarRange(val, val+0.001); 

  if (myid != 0)
    {
 
    vtkOutputPort *upPort = vtkOutputPort::New();
    
    // Last, set up a RMI call back to change the iso surface value.
    // This is done so that the root process can let this process
    // know that it wants the contour value to change.

    controller->AddRMI(NULL, (void *)iso, ISO_VALUE_RMI_TAG); 
	upPort->SetInput((vtkDataObject *)elev->GetPolyDataOutput());
    upPort->SetTag(PORT_TAG);   
	
    upPort->WaitForUpdate(); 
 
    upPort->Delete();  
    }
  
  else
    {
	
	    int i;
		vtkAppendPolyData *app = vtkAppendPolyData::New(); 
	            
		vtkInputPort *downPort;      
		vtkRenderer *ren = vtkRenderer::New();
		vtkRenderWindow *renWindow = vtkRenderWindow::New();
		vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
		vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
		vtkActor *actor = vtkActor::New();
		vtkTimerLog *timer = vtkTimerLog::New();
		vtkCamera *cam = vtkCamera::New();

		app->AddInput(elev->GetPolyDataOutput()); 

		
		app->ParallelStreamingOn(); 
    
		for (i = 1; i < numProcs; ++i)
		 {
		 downPort = vtkInputPort::New();   
		 downPort->SetRemoteProcessId(i); 

		 downPort->SetTag(PORT_TAG);      

	     app->AddInput(downPort->GetPolyDataOutput()); 
		
		downPort->Delete();           
		downPort = NULL;
		}

		
		 renWindow->AddRenderer(ren);
		iren->SetRenderWindow(renWindow);
		ren->SetBackground(0.9, 0.9, 0.9);
		renWindow->SetSize( 400, 400);
  
		mapper->SetInput(app->GetOutput());
		actor->SetMapper(mapper);
  
		ren->AddActor(actor);
  
		 cam->SetFocalPoint(100, 100, 65);
		cam->SetPosition(100, 450, 65);
		cam->SetViewUp(0, 0, -1);
		 cam->SetViewAngle(30);

		cam->SetClippingRange(177.0, 536.0);
		ren->SetActiveCamera(cam);
    
	
		for (i = 1; i < numProcs; ++i)
		{
			
			controller->TriggerRMI(i, ISO_VALUE_RMI_TAG);    
		}
      
	
		timer->StartTimer();			
	   app->Update();					
	   timer->StopTimer();          
	   numTris0 = iso->GetOutput()->GetNumberOfCells(); 
		numTris  = app->GetOutput()->GetNumberOfCells();
	
		val = iso->GetValue(0);      
		cerr << "total processes:   " << numProcs<<"
";
		cerr << "contour value:  " << val<<"
" ;
		
  
		renWindow->Render();
    
		iren->Start();            

		
		 for (i = 1; i < numProcs; ++i)
		 {
			  controller->TriggerRMI(i, vtkMultiProcessController::BREAK_RMI_TAG); 
		 }

	    app->Delete();
	      ren->Delete();
	      renWindow->Delete();
	      iren->Delete();
          mapper->Delete();
		   actor->Delete();
          cam->Delete();
	      timer->Delete();
	}

  
  reader->Delete();
  iso->Delete();
  elev->Delete();
}


int main( int argc, char* argv[] )
{

  vtkMPIController *controller;

 
  controller = vtkMPIController::New();

  controller->Initialize(&argc, &argv);

 
  controller->SetSingleMethod(MyMain, NULL);
			
  if (controller->IsA("vtkThreadedController"))
    {
	    
         controller->SetNumberOfProcesses(2);
         cout<<"OKOKOK";  
    } 
  controller->SingleMethodExecute();


  controller->Finalize();
  controller->Delete();

  return 0;
}



More information about the vtkusers mailing list