[vtkusers] double free or corruption with vtkPLYWriter

jbouffar julian.m.bouffard at erdc.dren.mil
Wed Mar 23 14:38:08 EDT 2016


Hi All,

I am a new VTK user and I have written some threaded code to run on some
HPCs, but it seems to be crashing and I can't determine why.  I was hoping
someone here could shed some light for me.  

The code uses boost asio library to create threads and a work queue, and
loops through some thousands of files.  Sometimes it makes it through
thousands without crashing, other times it crashes almost immediately.  The
error is usually 'double free or corruption (fasttop)' the full message is
pasted below, along with a few lines of the backtrace which always implicate
the Close method of a ply file.  

I have never used smart pointers before, so I even re-wrote all the code
with normal pointers and ->Delete() and NULL, but got the same error.  I
even then removed all ->Delete and NULL statements, making them all memory
leaks, and still got the same error.  I have included what should be fully
compilable code below the error message, I hope that is okay, alternatively
I could attach a file or use pastebin, unfortunately I am not sure of the
norm here.

Thanks for any help!


*** glibc detected *** ./myscript: double free or corruption (fasttop):
0x00002aab7ce40110 ***

======= Backtrace: =========
/lib64/libc.so.6(+0x79098)[0x2aaabe510098]
/lib64/libc.so.6(cfree+0x6c)[0x2aaabe5150dc]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkIOPLY-7.0.so.1(_ZN6vtkPLY9ply_closeEP7PlyFile+0x12d)[0x2aaaad02487d]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkIOPLY-7.0.so.1(_ZN12vtkPLYWriter9WriteDataEv+0x4f2)[0x2aaaad02ad02]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkIOCore-7.0.so.1(_ZN9vtkWriter11RequestDataEP14vtkInformationPP20vtkInformationVectorS3_+0x103)[0x2aaabb19f063]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN12vtkExecutive13CallAlgorithmEP14vtkInformationiPP20vtkInformationVectorS3_+0x40)[0x2aaabb410310]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN23vtkDemandDrivenPipeline11ExecuteDataEP14vtkInformationPP20vtkInformationVectorS3_+0x37)[0x2aaabb40a1a7]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN24vtkCompositeDataPipeline11ExecuteDataEP14vtkInformationPP20vtkInformationVectorS3_+0x141)[0x2aaabb407e81]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN23vtkDemandDrivenPipeline14ProcessRequestEP14vtkInformationPP20vtkInformationVectorS3_+0x45f)[0x2aaabb40cf7f]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN32vtkStreamingDemandDrivenPipeline14ProcessRequestEP14vtkInformationPP20vtkInformationVectorS3_+0x1d9)[0x2aaabb4276f9]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN23vtkDemandDrivenPipeline10UpdateDataEi+0x8c)[0x2aaabb40b93c]
/lustre/work1/jbouffar/vtk/vtk-install/lib/libvtkCommonExecutionModel-7.0.so.1(_ZN32vtkStreamingDemandDrivenPipeline6UpdateEi+0x9f)[0x2aaabb42814f]
./myscript(_Z12searchDomainiPc+0x524)[0x423b25]


#include "vtkStructuredPointsReader.h"
#include "vtkSmartPointer.h"
#include "vtkCellData.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkFloatArray.h"
#include "vtkStructuredPoints.h"
#include "vtkCellDataToPointData.h"
#include "vtkMarchingCubes.h"
#include "vtkPLYWriter.h"
#include "vtkInformation.h"
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <iostream>
#include <pthread.h>
#include <thread>
#include <vector>
#include <memory>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <time.h>

using namespace std;

void searchDomain(int d, char* t);

vector<double> x;
vector<float> times;

boost::asio::io_service myService;
boost::thread_group myPool;
boost::asio::io_service::work work(myService);
boost::asio::io_service::strand strand(myService);

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

  struct timespec main_monotonic_start, main_monotonic_finish;
  double main_monotonic_elapsed;
  clock_gettime(CLOCK_MONOTONIC, &main_monotonic_start);
  

  int threads = 30;
  for(int i = 0; i < threads; i++){
    myPool.create_thread(boost::bind(&boost::asio::io_service::run,
&myService));
  }

  int start = 14300;
  int chunks = 2000;
  for(int d = start; d < start + chunks; d++){ 
    myService.post([d,argv] { 
	searchDomain(d, argv[1]);
      });
  }
    
  int stop = 0;
  while(stop == 0){
    sleep(2.0);
    strand.post(strand.wrap([&]() { if(times.size() == chunks) stop = 1; }
));
  }

  clock_gettime(CLOCK_MONOTONIC,&main_monotonic_finish);
  main_monotonic_elapsed = (main_monotonic_finish.tv_sec -
main_monotonic_start.tv_sec);
  main_monotonic_elapsed += (main_monotonic_finish.tv_nsec -
main_monotonic_start.tv_nsec) / 1000000000.0;

  cout << "Total MONOTONIC run time for main function (" << threads << "
threads) with " << chunks << " domain chunks: " <<  main_monotonic_elapsed
<< " s" << endl;

  double totaltime = 0;
  for(float t : times){
    totaltime += t;
  }
  double avgtime = (double)totaltime / (double)times.size();
  cout << "Total compute time for all domain chunks = " << totaltime <<
endl;
  cout << "Average compute time per domain chunk with " << threads << "
threads = " << setprecision(10) << (double)avgtime << endl;
  
  myService.stop();
  myPool.join_all();
  
  return 0;
}

void searchDomain(int d, char* t){

  struct timespec start, finish;
  double elapsed;
  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
    
  stringstream ss;
  ss << "/lustre/work1/apol/H.g6.K2048dns.v4.n16.L256/id" << d << 
"/H.g6.K2048dns.v4.n16.L256-id" << d <<  "." << t << ".vtk";
  string filename = ss.str();

  vtkSmartPointer<vtkStructuredPointsReader> reader =
vtkSmartPointer<vtkStructuredPointsReader>::New();
  reader->SetFileName(filename.c_str());
  reader->ReadAllScalarsOn();
  reader->Update();

  vtkSmartPointer<vtkStructuredPoints> structuredPointData =
reader->GetOutput();
  vtkSmartPointer<vtkCellData> cellData =
structuredPointData->GetCellData();
  vtkSmartPointer<vtkDataArray> scalar0 = cellData->GetScalars("Scalar0");
  vtkSmartPointer<vtkDataArray> density = cellData->GetScalars("Density");
  int result = -1;
  
  vtkSmartPointer<vtkFloatArray> flameArray =
vtkSmartPointer<vtkFloatArray>::New();
  flameArray->SetName("flame");
  
  int nTuples = scalar0->GetNumberOfTuples();
  for(int i = 0; i < nTuples; i++){
    flameArray->InsertNextValue(scalar0->GetComponent(i,1) /
density->GetComponent(i,1));
  }
  
  structuredPointData->GetCellData()->SetScalars(flameArray);
  structuredPointData->GetCellData()->RemoveArray("Scalar0");
  structuredPointData->GetCellData()->RemoveArray("Density");
  
  vtkSmartPointer<vtkCellDataToPointData> cpd =
vtkSmartPointer<vtkCellDataToPointData>::New();
  cpd->SetInputData(structuredPointData);
  cpd->Update();
  
  vtkSmartPointer<vtkMarchingCubes> iso =
vtkSmartPointer<vtkMarchingCubes>::New();
  vtkSmartPointer<vtkDataSet> DataArray = cpd->GetOutput(); 
  iso->SetInputData(DataArray);
  iso->SetValue(0, 0.1574);
  iso->ComputeNormalsOn();
  iso->SetInputArrayToProcess(0, flameArray->GetInformation());
  iso->Update();
  
  
  if((iso->GetOutput())->GetNumberOfPolys() > 0){
    vtkSmartPointer<vtkPolyData> marchingOutput = iso->GetOutput();

    vtkSmartPointer<vtkPLYWriter> plyWriter =
vtkSmartPointer<vtkPLYWriter>::New();  
    
    stringstream outfile;
    outfile << "/lustre/work1/jbouffar/myscript/plyout/" << d << ".ply";
    string outfile_string = outfile.str();
    plyWriter->SetFileName(outfile_string.c_str());
    plyWriter->SetInputData(marchingOutput);
    //strand.post(strand.wrap([&plyWriter]() { plyWriter->Write(); } ));
    plyWriter->Update();
    plyWriter->Write(); 
  }

  clock_gettime(CLOCK_THREAD_CPUTIME_ID,&finish);
  elapsed = (finish.tv_sec - start.tv_sec);
  elapsed += (finish.tv_nsec - start.tv_nsec) / 1000000000.0;

  cout << "Thread running time for domain chunk " << d << ": " << elapsed <<
" (flame found) ----" << endl;

  strand.post(strand.wrap([&]() { times.push_back(elapsed); } ));  

  return;

}

 



--
View this message in context: http://vtk.1045678.n5.nabble.com/double-free-or-corruption-with-vtkPLYWriter-tp5737333.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list