Skip to content

Scalar string variables in SSC #2561

Closed
Closed
@franzpoeschel

Description

Describe the bug
SSC will not always read scalar string variables correctly, often returning an empty string instead. Furthermore, if only writing scalar (string?) variables in a step, the SSC engine will crash.

To Reproduce
This example writes three variables from rank 0 and reads them on rank 1. firststring and secondstring are scalar strings, someothertype is an int array.

#include <adios2.h>
#include <iostream>
#include <mpi.h>
#include <string>
#include <vector>

int
main( int argsc, char ** argsv )
{
    MPI_Init( &argsc, &argsv );
    int global_mpi_rank, global_mpi_size;
    MPI_Comm_rank( MPI_COMM_WORLD, &global_mpi_rank );
    MPI_Comm_size( MPI_COMM_WORLD, &global_mpi_size );

    int local_mpi_rank, local_mpi_size;
    int color = global_mpi_rank < 2 ? global_mpi_rank : MPI_UNDEFINED;
    MPI_Comm local_comm;
    MPI_Comm_split( MPI_COMM_WORLD, color, local_mpi_rank, &local_comm );
    MPI_Comm_rank( local_comm, &local_mpi_rank );
    MPI_Comm_size( local_comm, &local_mpi_size );

    std::string engine_type = "ssc";

    adios2::ADIOS adios{ local_comm };
    adios2::IO IO = adios.DeclareIO( "IO" );
    IO.SetEngine( engine_type );

#define PUT_INT true

    switch( color )
    {
        case 0:
        {
            // write
            adios2::Engine engine = IO.Open( "stream", adios2::Mode::Write );
            engine.BeginStep();
#if PUT_INT
            auto othervariable = IO.DefineVariable< int >(
                "someothertype", { 10 }, { 0 }, { 10 } );
            std::vector< int > v( 10, 1234 );
            engine.Put( othervariable, v.data() );
#endif
            auto var1 = IO.DefineVariable< std::string >( "firststring" );
            auto var2 = IO.DefineVariable< std::string >( "secondstring" );
            std::string firststring = "firststring";
            std::string secondstring = "secondstring";
            engine.Put( var1, firststring );
            engine.Put( var2, secondstring );
            engine.EndStep();
            engine.Close();
        }
        break;
        case 1:
        {
            // read
            adios2::Engine engine = IO.Open( "stream", adios2::Mode::Read );
            engine.BeginStep();
            auto var1 = IO.InquireVariable< std::string >( "firststring" );
            auto var2 = IO.InquireVariable< std::string >( "secondstring" );
            std::string firststring;
            std::string secondstring;
            engine.Get( var1, firststring );
            engine.Get( var2, secondstring );
#if PUT_INT
            auto othervariable = IO.InquireVariable< int >( "someothertype" );
            std::vector< int > v( 10 );
            engine.Get( othervariable, v.data() );
#endif
            engine.EndStep();

            std::cout << " First Variable:\t" << firststring
                      << "\nSecond Variable:\t" << secondstring << std::endl;
#if PUT_INT
            std::cout << "Int variable:\t" << v[ 0 ] << std::endl;
#endif
            engine.Close();
        }
        break;
        case MPI_UNDEFINED:
            break;
    }

    MPI_Finalize();
}

Output:

 First Variable:
Second Variable:
Int variable:   1234

Output if setting #define PUT_INT false:

 First Variable:
Second Variable:
terminate called after throwing an instance of 'nlohmann::detail::type_error'
  what():  [json.exception.type_error.305] cannot use operator[] with a string argument with number

Expected behavior
Setting the engine to sst gives the expected output:

 First Variable:        firststring
Second Variable:        secondstring
Int variable:   1234

Desktop (please complete the following information):

  • OS/Platform: Ubuntu 20.10
  • Build c++ (Ubuntu 10.2.0-13ubuntu1) 10.2.0, current master (commit hash 7854b5fcb34d1fe7a346261a291460fe47e2987e)

Additional context
Scalar string variables will not always fail to read values correctly in SSC. When I tried SSC for openPMD, one scalar string variable was read incorrectly (the first one, to be precise). All subsequent ones were read correctly. In this example however, both scalar strings seem to behave wrongly.

Following up
Was the issue fixed? Please report back.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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