Loading Documentation/Examples/Algorithms/Segments/SegmentsExample_General.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -35,7 +35,9 @@ void SegmentsExample() /*** * Print the data managed by the segments. */ std::cerr << data << std::endl; auto fetch = [=] __cuda_callable__ ( IndexType globalIdx ) -> double { return data_view[ globalIdx ]; }; printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl; /*** Loading src/TNL/Algorithms/Segments/SegmentsPrinting.h +36 −2 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ template< typename Segments, typename Fetch > struct SegmentsPrinter { SegmentsPrinter( const Segments& segments, Fetch& fetch ) SegmentsPrinter( const Segments& segments, Fetch&& fetch ) : segments( segments ), fetch( fetch ) {} std::ostream& print( std::ostream& str ) const Loading @@ -71,6 +71,8 @@ struct SegmentsPrinter for( IndexType localIdx = 0; localIdx < segmentSize; localIdx++ ) { aux.forAllElements( [=] __cuda_callable__ ( IndexType elementIdx, double& v ) mutable { //printf( "####### localIdx = %d, globalIdx = %d \n", localIdx, view.getGlobalIndex( segmentIdx, localIdx ) ); //v = view.getGlobalIndex( segmentIdx, localIdx ); v = fetch( view.getGlobalIndex( segmentIdx, localIdx ) ); } ); auto value = aux.getElement( 0 ); Loading @@ -87,7 +89,7 @@ struct SegmentsPrinter const Segments& segments; Fetch& fetch; Fetch fetch; }; template< typename Segments, Loading @@ -97,6 +99,38 @@ std::ostream& operator<<( std::ostream& str, const SegmentsPrinter< Segments, Fe return printer.print( str ); } template< typename Segments, typename Fetch > std::ostream& printSegments( const Segments& segments, Fetch&& fetch, std::ostream& str ) { using IndexType = typename Segments::IndexType; using DeviceType = typename Segments::DeviceType; using ValueType = decltype( fetch( IndexType() ) ); TNL::Containers::Array< ValueType, DeviceType, IndexType > aux( 1 ); auto view = segments.getConstView(); for( IndexType segmentIdx = 0; segmentIdx < segments.getSegmentsCount(); segmentIdx++ ) { str << "Seg. " << segmentIdx << ": [ "; auto segmentSize = segments.getSegmentSize( segmentIdx ); //std::cerr << "Segment size = " << segmentSize << std::endl; for( IndexType localIdx = 0; localIdx < segmentSize; localIdx++ ) { aux.forAllElements( [=] __cuda_callable__ ( IndexType elementIdx, double& v ) mutable { //printf( "####### localIdx = %d, globalIdx = %d \n", localIdx, view.getGlobalIndex( segmentIdx, localIdx ) ); v = fetch( view.getGlobalIndex( segmentIdx, localIdx ) ); //v = view.getGlobalIndex( segmentIdx, localIdx ); } ); auto value = aux.getElement( 0 ); str << value; if( localIdx < segmentSize - 1 ) str << ", "; } str << " ] " << std::endl; } return str; } } // namespace Segments } // namespace Algorithms } // namespace TNL Loading
Documentation/Examples/Algorithms/Segments/SegmentsExample_General.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -35,7 +35,9 @@ void SegmentsExample() /*** * Print the data managed by the segments. */ std::cerr << data << std::endl; auto fetch = [=] __cuda_callable__ ( IndexType globalIdx ) -> double { return data_view[ globalIdx ]; }; printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl; /*** Loading
src/TNL/Algorithms/Segments/SegmentsPrinting.h +36 −2 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ template< typename Segments, typename Fetch > struct SegmentsPrinter { SegmentsPrinter( const Segments& segments, Fetch& fetch ) SegmentsPrinter( const Segments& segments, Fetch&& fetch ) : segments( segments ), fetch( fetch ) {} std::ostream& print( std::ostream& str ) const Loading @@ -71,6 +71,8 @@ struct SegmentsPrinter for( IndexType localIdx = 0; localIdx < segmentSize; localIdx++ ) { aux.forAllElements( [=] __cuda_callable__ ( IndexType elementIdx, double& v ) mutable { //printf( "####### localIdx = %d, globalIdx = %d \n", localIdx, view.getGlobalIndex( segmentIdx, localIdx ) ); //v = view.getGlobalIndex( segmentIdx, localIdx ); v = fetch( view.getGlobalIndex( segmentIdx, localIdx ) ); } ); auto value = aux.getElement( 0 ); Loading @@ -87,7 +89,7 @@ struct SegmentsPrinter const Segments& segments; Fetch& fetch; Fetch fetch; }; template< typename Segments, Loading @@ -97,6 +99,38 @@ std::ostream& operator<<( std::ostream& str, const SegmentsPrinter< Segments, Fe return printer.print( str ); } template< typename Segments, typename Fetch > std::ostream& printSegments( const Segments& segments, Fetch&& fetch, std::ostream& str ) { using IndexType = typename Segments::IndexType; using DeviceType = typename Segments::DeviceType; using ValueType = decltype( fetch( IndexType() ) ); TNL::Containers::Array< ValueType, DeviceType, IndexType > aux( 1 ); auto view = segments.getConstView(); for( IndexType segmentIdx = 0; segmentIdx < segments.getSegmentsCount(); segmentIdx++ ) { str << "Seg. " << segmentIdx << ": [ "; auto segmentSize = segments.getSegmentSize( segmentIdx ); //std::cerr << "Segment size = " << segmentSize << std::endl; for( IndexType localIdx = 0; localIdx < segmentSize; localIdx++ ) { aux.forAllElements( [=] __cuda_callable__ ( IndexType elementIdx, double& v ) mutable { //printf( "####### localIdx = %d, globalIdx = %d \n", localIdx, view.getGlobalIndex( segmentIdx, localIdx ) ); v = fetch( view.getGlobalIndex( segmentIdx, localIdx ) ); //v = view.getGlobalIndex( segmentIdx, localIdx ); } ); auto value = aux.getElement( 0 ); str << value; if( localIdx < segmentSize - 1 ) str << ", "; } str << " ] " << std::endl; } return str; } } // namespace Segments } // namespace Algorithms } // namespace TNL