Skip to content

Incorrect broadcasting with uninitialized recieving vector (with suitable capacity) #404

@GiovaGa

Description

@GiovaGa

Consider the following (with suitable includes and initializations for MPI):

const int LPF_MPI_AUTO_INITIALIZE = 0;

void grbProgram( const size_t &n, bool &success ) {
	grb::RC rc = grb::SUCCESS;
	const size_t s = grb::spmd<>::pid();
	grb::Vector< int, grb::reference > v ( 10 );
	rc = rc ? rc : grb::resize( v, 10 );
	if( s == 0 ){
		rc = rc ? rc : grb::set( v, 1 );
		assert( grb::nnz( v ) == grb::size( v ));
	}

	rc = rc ? rc : grb::internal::broadcast( v, 0 );
	assert( rc == grb::SUCCESS );
	std::cerr << "Process " << s << ": " << grb::nnz( v ) << " == " << grb::size( v ) << std::endl;
	assert( grb::nnz( v ) == grb::size( v ) );
}


int main( int argc, char ** argv ) {
	// init things...
	grb::Launcher< grb::FROM_MPI > launcher( MPI_COMM_WORLD );

	// note: this exec passes pointers within a single process
	const grb::RC rc = launcher.exec( &grbProgram, n, success, true );
	if( rc != grb::SUCCESS ) {
		std::cerr << "grb::Launcher< FROM_MPI >::exec returns with non-SUCCESS "
			<< "exit code " << grb::toString(rc) << std::endl;
	}
	// ...

This program crashes at the last assert in grbProgram: assert( grb::nnz( v ) == grb::size( v ) );.

The issue seems to be that even though all return codes are grb::SUCCESS the values in v are not correctly written to all the processes. Doing a grb::set( v, 0 ) in all processes resolves the issue (and the values are correctly communicated).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions