Hi, I don't see any easy reason for the code not to work, but I think it is excessively complex. I would suggest you start with a minimal example and work from the ground up. For instance:
1. Your for(int i=index;i<(index+1);i++) loop is useless. I suppose this comes already from a simplification of other code, but makes your example difficult to understand. 2. Start by removing all the registration code from your function and add things back again progressively in order to see where the problem appears. 3. Declare const all your global variables (you don't seem to modify them, but let the compiler take care of that for you). 4. Test what happens if you use one single thread. Finally, if you have access to a compiler supporting c++11 (gcc 4.8 for instance) you could use the standard c++ library tools for concurrent programming (threads, mutexes, futures, etc.): http://en.cppreference.com/w/cpp/thread http://www.baptiste-wicht.com/2012/03/cpp11-concurrency-part1-start-threads/ http://www.codeproject.com/Articles/540912/Cplusplus-11-Threads-Make-your-multitasking-life-e wijuk pruksuriya <[email protected]> wrote: > > Thank Jordi > > This is my code. > > #define NUM_THREADS 8 > #define ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1; > > unsigned int col = 7; > unsigned int row = 5; > > string folder = "../../Sample/300_sample/"; > const string filetype = ".jpg"; > > string dataSet [35] = > {"input1","input2","input3","input4","input5","input6","input7", > "input11","input12","input13","input14","input15","input16","input17", > "input21","input22","input23","input24","input25","input26","input27", > "input31","input32","input33","input34","input35","input36","input37", > "input41","input42","input43","input44","input45","input46","input47" > }; > > const char * outputImageFilename; > const char * outputTransformationFilename; > > unsigned int octaves; > unsigned int scales; > float threshold; > float ratio; > double secondOrderThreshold; > bool useBackMatching; > > const unsigned int Dimension = 2; > > struct thread_data{ > int thread_id; > char *message; > }; > > void *calTransformPipeline(void *threadarg) > { > > typedef double RealType; > typedef unsigned char OutputPixelType; > > typedef otb::Image<RealType, Dimension> ImageType; > typedef otb::Image<OutputPixelType, Dimension> OutputImageType; > > typedef itk::VariableLengthVector<RealType> RealVectorType; > typedef itk::PointSet<RealVectorType, Dimension> PointSetType; > > typedef itk::AffineTransform<RealType, Dimension> AffineTransformType; > > typedef otb::ImageToSIFTKeyPointSetFilter<ImageType, PointSetType> > ImageToSIFTKeyPointSetFilterType; > typedef otb::ImageToSURFKeyPointSetFilter<ImageType, PointSetType> > ImageToSURFKeyPointSetFilterType; > > typedef itk::Statistics::EuclideanDistance<RealVectorType> DistanceType; > typedef otb::KeyPointSetsMatchingFilter<PointSetType, DistanceType> > EuclideanDistanceMatchingFilterType; > > typedef PointSetType::PointType PointType; > typedef std::pair<PointType, PointType> MatchType; > typedef std::vector<MatchType> MatchVectorType; > typedef EuclideanDistanceMatchingFilterType::LandmarkListType > LandmarkListType; > > typedef PointSetType::PointsContainer PointsContainerType; > typedef PointsContainerType::Iterator PointsIteratorType; > typedef PointSetType::PointDataContainer PointDataContainerType; > typedef PointDataContainerType::Iterator PointDataIteratorType; > > typedef otb::ImageFileReader<ImageType> ReaderType; > > typedef itk::Point<double, 2> MyPointType; > typedef otb::LeastSquareAffineTransformEstimator<MyPointType> EstimatorType; > > ReaderType::Pointer fixedReader = ReaderType::New(); > ReaderType::Pointer movingReader = ReaderType::New(); > PointSetType::Pointer imgDomainPoint = PointSetType::New(); > > ImageType::IndexType destinationIndexList[4][6]; > > struct thread_data *my_data; > > my_data = (struct thread_data *) threadarg; > > int index = my_data->thread_id; > > string fixedfname; > string movingfname; > > for(int i=index;i<(index+1);i++){ > > ImageType::IndexType destinationIndex; > ImageType::IndexType transformationIndex; > ImageType::IndexType destinationRowIndex; > ImageType::IndexType transformationRowIndex; > > PointSetType::Pointer imgDomainPointOld = PointSetType::New(); > > destinationIndex[0] = 0; > destinationIndex[1] = 0; > > transformationIndex[0] = 0; > transformationIndex[1] = 0; > > destinationRowIndex[0] = 0; > destinationRowIndex[1] = 0; > > transformationRowIndex[0] = 0; > transformationRowIndex[1] = 0; > > for(int j=0;j<6;j++){ > > fixedfname = dataSet[j+(i*col)]; > movingfname = dataSet[j+1+(i*col)]; > > std::cerr << "[" << fixedfname << "," << movingfname << "]" << > std::endl; > > fixedReader->SetFileName(folder+fixedfname+filetype); > > movingReader->SetFileName(folder+movingfname+filetype); > > ImageToSURFKeyPointSetFilterType::Pointer filter1 = > ImageToSURFKeyPointSetFilterType::New(); > ImageToSURFKeyPointSetFilterType::Pointer filter2 = > ImageToSURFKeyPointSetFilterType::New(); > > EuclideanDistanceMatchingFilterType::Pointer euclideanMatcher = > EuclideanDistanceMatchingFilterType::New(); > > if(j!=0){ > > filter2->SetInput(movingReader->GetOutput()); > filter2->SetOctavesNumber(octaves); > filter2->SetScalesNumber(scales); > > std::cout << filter2->GetNumberOfThreads() << std::endl; > > euclideanMatcher->SetInput1(imgDomainPointOld); > euclideanMatcher->SetInput2(filter2->GetOutput()); > > imgDomainPointOld = filter2->GetOutput(); > > }else{ > filter1->SetInput(fixedReader->GetOutput()); > filter1->SetOctavesNumber(octaves); > filter1->SetScalesNumber(scales); > > std::cout << filter1->GetNumberOfThreads() << std::endl; > > filter2->SetInput(movingReader->GetOutput()); > filter2->SetOctavesNumber(octaves); > filter2->SetScalesNumber(scales); > > std::cout << filter2->GetNumberOfThreads() << std::endl; > > imgDomainPointOld = filter2->GetOutput(); > euclideanMatcher->SetInput1(filter1->GetOutput()); > euclideanMatcher->SetInput2(filter2->GetOutput()); > } > > euclideanMatcher->SetDistanceThreshold(secondOrderThreshold); > euclideanMatcher->SetUseBackMatching(useBackMatching); > euclideanMatcher->SetNumberOfThreads(1); > euclideanMatcher->Update(); > > LandmarkListType::Pointer landmarkList; > landmarkList = euclideanMatcher->GetOutput(); > > EstimatorType::Pointer estimator = EstimatorType::New(); > > for (LandmarkListType::Iterator it = landmarkList->Begin(); > it != landmarkList->End(); ++it){ > estimator->AddTiePoints(it.Get()->GetPoint1(), > it.Get()->GetPoint2()); > } > > estimator->Compute(); > > transformationIndex[0] = estimator->GetOffset()[0]; > transformationIndex[1] = estimator->GetOffset()[1]; > destinationIndex[0] = destinationIndex[0]-transformationIndex[0]; > destinationIndex[1] = destinationIndex[1]-transformationIndex[1]; > > destinationIndexList[i][j]= destinationIndex; > > } > } > pthread_exit(NULL); > } > > int main(int argc, char* argv[]) > { > > if (argc != 10) > { > std::cerr << "Usage: " << argv[0]; > std::cerr << > " fixedFileName movingFileName resamplingImageFileName transfofname octaves > scales threshold ratio secondOrderThreshold useBackMatching" > << std::endl; > return EXIT_FAILURE; > } > > folder = argv[1]; > outputImageFilename = argv[2]; > > octaves = atoi(argv[4]); > scales = atoi(argv[5]); > threshold = atof(argv[6]); > ratio = atof(argv[7]); > secondOrderThreshold = atof(argv[8]); > useBackMatching = atoi(argv[9]); > > pthread_t threads[NUM_THREADS]; > struct thread_data td[NUM_THREADS]; > int rc; > int i; > > cout <<"main() : creating thread, " << 0 << endl; > td[0].thread_id = 1; > td[0].message = "This is message"; > > rc = pthread_create(&threads[0], NULL, calTransformPipeline, (void > *)&td[0]); > > cout <<"main() : creating thread, " << 1 << endl; > td[1].thread_id = 2; > td[1].message = "This is message"; > > rc = pthread_create(&threads[1], NULL, calTransformPipeline, (void > *)&td[1]); > > if (rc){ > cout << "Error:unable to create thread," << rc << endl; > exit(-1); > } > > pthread_exit(NULL); > > return EXIT_SUCCESS; > } > > เมื่อ วันพฤหัสบดีที่ 6 กุมภาพันธ์ ค.ศ. 2014, 16 นาฬิกา 4 นาที 12 วินาที > UTC+7, Jordi Inglada เขียนว่า: > > wijuk pruksuriya <[email protected]> > wrote: > > > > I have problem about Update() pipeline in pthread. > > > > rc = pthread_create(&threads[0], NULL, calTransformPipeline, (void > *)&td[0]); // first thread > > > > rc = pthread_create(&threads[1], NULL, calTransformPipeline, (void > *)&td[1]); // second thread > > > > calTransformPipeline() is function to calculate affine-transform (like > a EstimateAffineTransformationExample). but when I use pthread is error > Segmentation fault (core dumped). > > > > *if second thread not use update() it will ok. > > > > first time I think because of OTB use auto mutithread. therefore, I set > ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1 but It still didn't work. > > > > Hi, > > Can you give some more details like the signature of calTransformPipeline > or what td[] look like? > > Have you got any shared variables between the threads? > > Jordi > > -- > -- > Check the OTB FAQ at > http://www.orfeo-toolbox.org/FAQ.html > > You received this message because you are subscribed to the Google > Groups "otb-users" group. > To post to this group, send email to > otb-users-/[email protected] > To unsubscribe from this group, send email to > otb-users+unsubscribe-/[email protected] > For more options, visit this group at > http://groups.google.com/group/otb-users?hl=en > --- > You received this message because you are subscribed to the Google Groups > "otb-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to > otb-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > For more options, visit https://groups.google.com/groups/opt_out. -- -- Check the OTB FAQ at http://www.orfeo-toolbox.org/FAQ.html You received this message because you are subscribed to the Google Groups "otb-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/otb-users?hl=en --- You received this message because you are subscribed to the Google Groups "otb-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
