Ejemplo n.º 1
0
Stg_ComponentFactory* stgMainInitFromXML( char* xmlInputFilename, MPI_Comm communicator, void* _context ) {
   Dictionary*           dictionary = NULL;
   Dictionary*           sources = NULL;
   Bool                  result;
   XML_IO_Handler*       ioHandler;
   Stg_ComponentFactory* cf;

   dictionary = Dictionary_New();
   sources = Dictionary_New();
   ioHandler = XML_IO_Handler_New();
   result = IO_Handler_ReadAllFromFile( ioHandler, xmlInputFilename, dictionary, sources );

   /* In case the user has put any journal configuration in the XML, read here. */
   Journal_ReadFromDictionary( dictionary );
   cf = stgMainConstruct( dictionary, sources, communicator, _context );

   /* now dereference aliases */
   DictionaryUtils_AliasDereferenceDictionary( dictionary );
   /* 
    * We don't need the XML IO handler again (however don't delete the dictionary as it's 
    * 'owned' by the context from hereon.
    */
   Stg_Class_Delete( ioHandler );
   Stg_Class_Delete( sources );

   return cf;
}
void SwarmOutputSuite_TestSwarmOutput( SwarmOutputSuiteData* data ) {
   int procToWatch = data->nProcs > 1 ? 1 : 0;

   if( data->rank == procToWatch ) {
      Dictionary*                dictionary;
      Dictionary*                componentDict;
      Stg_ComponentFactory*      cf;
      DomainContext*             context;
      char                       input_file[PCU_PATH_MAX];
      Swarm*                     swarm;
      SwarmOutput*               swarmOutput;
      SpaceFillerParticleLayout* particleLayout;

      pcu_filename_input( "testSwarmOutput.xml", input_file );
      cf = stgMainInitFromXML( input_file, data->comm, NULL );
      context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
      dictionary = context->dictionary;

      Journal_ReadFromDictionary( dictionary );
      stgMainBuildAndInitialise( cf  );

      ContextEP_Append( context, AbstractContext_EP_Dt, SwarmOutputSuite_Dt );
      ContextEP_Append( context, AbstractContext_EP_Step, SwarmOutputSuite_MoveParticles );

      componentDict = Dictionary_GetDictionary( dictionary, "components" );
      assert( componentDict );

      AbstractContext_Dump( context );
      Stg_Component_Execute( context, 0, False );

      particleLayout = (SpaceFillerParticleLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"particleLayout" );
      swarmOutput = (SwarmOutput* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarmOutput" );
      swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );

      pcu_check_true( particleLayout->isConstructed && particleLayout->isBuilt && particleLayout->isInitialised );
      pcu_check_true( swarmOutput->isConstructed && swarmOutput->isBuilt && swarmOutput->isInitialised );
      pcu_check_true( swarm->isConstructed && swarm->isBuilt && swarm->isInitialised  );

      pcu_check_streq( swarm->name, swarmOutput->swarm->name );

      stgMainDestroy( cf );
   }
}
Ejemplo n.º 3
0
int main( int argc, char* argv[] ) {
    MPI_Comm CommWorld;
    int rank;
    int numProcessors;
    int procToWatch;

    /* Initialise MPI, get world info */
    MPI_Init( &argc, &argv );
    MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
    MPI_Comm_size( CommWorld, &numProcessors );
    MPI_Comm_rank( CommWorld, &rank );

    BaseFoundation_Init( &argc, &argv );
    BaseIO_Init( &argc, &argv );

    if( argc >= 2 ) {
        procToWatch = atoi( argv[1] );
    }
    else {
        procToWatch = 0;
    }
    if( rank == procToWatch )
    {
        Stream* infoTest1;
        Stream* infoTest2;
        Stream* debugTest1;
        Stream* debugTest2;
        Stream* dumpTest1;
        Stream* dumpTest2;
        Stream* newTest1;
        Stream* newTest2;

        Stream* fileTest1;
        Stream* fileTest2;

        Stream* propTest1;
        Stream* propTest2;

        Dictionary* dictionary = Dictionary_New();
        XML_IO_Handler* io_handler = XML_IO_Handler_New();

        infoTest1 = Journal_Register( Info_Type, "test1" );
        infoTest2 = Journal_Register( Info_Type, "test2" );
        debugTest1 = Journal_Register( Debug_Type, "test1" );
        debugTest2 = Journal_Register( Debug_Type, "test2" );
        dumpTest1 = Journal_Register( Dump_Type, "test1" );
        dumpTest2 = Journal_Register( Dump_Type, "test2" );

        IO_Handler_ReadAllFromFile( io_handler, "data/journal.xml", dictionary );

        Journal_ReadFromDictionary( dictionary );

        newTest1 = Journal_Register( Info_Type, "test1.new1" );
        newTest2 = Journal_Register( Info_Type, "test1.new2" );

        Journal_Printf( infoTest1, "infoTest1\n" );
        Journal_Printf( infoTest2, "infoTest2\n" );
        Journal_Printf( debugTest1, "debugTest1\n" );
        Journal_Printf( debugTest2, "debugTest2\n" );
        Journal_Printf( dumpTest1, "dumpTest1\n" );
        Journal_Printf( dumpTest2, "dumpTest2\n" );
        Journal_PrintfL( newTest1, 3, "newTest1\n" );
        Journal_PrintfL( newTest1, 4, "newTest1\n" );
        Journal_Printf( newTest2, "newTest2\n" );

        fileTest1 = Journal_Register( "newtype", "hello" );
        fileTest2 = Journal_Register( "newtype", "other" );

        Journal_Printf( fileTest1, "yay!" );
        Journal_Printf( fileTest2, "double yay!" );

        propTest1 = Journal_Register( Info_Type, "propertiestest1" );
        propTest2 = Journal_Register( Info_Type, "propertiestest2" );

        Print( propTest1, infoTest1 );
        Print( propTest2, infoTest1 );

        Stg_Class_Delete( io_handler );
        Stg_Class_Delete( dictionary );
    }

    BaseIO_Finalise();
    BaseFoundation_Finalise();

    /* Close off MPI */
    MPI_Finalize();

    return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
/* Main */
int main( int argc, char* argv[] ) {
	MPI_Comm			CommWorld;
	int				rank;
	int				numProcessors;
	int				procToWatch;
	Dictionary*			dictionary;
	Dictionary*			componentDict;
	XML_IO_Handler*			ioHandler;
	char*				filename;
	Snac_Context*			snacContext;
	int				tmp;

	/* Initialise MPI, get world info */
	MPI_Init( &argc, &argv );
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size( CommWorld, &numProcessors );
	MPI_Comm_rank( CommWorld, &rank );
	if( argc >= 3 ) {
		procToWatch = atoi( argv[2] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) printf( "Watching rank: %i\n", rank );
	
	if (!Snac_Init( &argc, &argv )) {
		fprintf(stderr, "Error initialising StGermain, exiting.\n" );
		exit(EXIT_FAILURE);
	}
	
	/* Snac's init message */
	tmp = Stream_GetPrintingRank( Journal_Register( InfoStream_Type, "Context" ) );
	Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), 0 );
	Journal_Printf( /* DO NOT CHANGE OR REMOVE */
		Journal_Register( InfoStream_Type, "Context" ), 
		"Snac. Copyright (C) 2003-2005 Caltech, VPAC & University of Texas.\n" );
	Stream_Flush( Journal_Register( InfoStream_Type, "Context" ) );
	Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), tmp );
	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */
	
	
	/* Create the dictionary, and some fixed values */
	dictionary = Dictionary_New();
	Dictionary_Add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) );
	Dictionary_Add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( numProcessors ) );
	
	/* Read input */
	ioHandler = XML_IO_Handler_New();
	if( argc >= 2 ) {
		filename = strdup( argv[1] );
	}
	else {
		filename = strdup( "input.xml" );
	}
	if ( False == IO_Handler_ReadAllFromFile( ioHandler, filename, dictionary ) )
	{
		fprintf( stderr, "Error: Snac couldn't find specified input file %s. Exiting.\n", filename );
		exit( EXIT_FAILURE );
	}
	Journal_ReadFromDictionary( dictionary );

	snacContext = Snac_Context_New( 0.0f, 0.0f, sizeof(Snac_Node), sizeof(Snac_Element), CommWorld, dictionary );
	if( rank == procToWatch ) Dictionary_PrintConcise( dictionary, snacContext->verbose );


	/* Construction phase -----------------------------------------------------------------------------------------------*/
	Stg_Component_Construct( snacContext, 0 /* dummy */, &snacContext, True );
	
	/* Building phase ---------------------------------------------------------------------------------------------------*/
	Stg_Component_Build( snacContext, 0 /* dummy */, False );
	
	/* Initialisaton phase ----------------------------------------------------------------------------------------------*/
	Stg_Component_Initialise( snacContext, 0 /* dummy */, False );
	if( rank == procToWatch ) Context_PrintConcise( snacContext, snacContext->verbose );
	
	/* Step the context solver */
	Stg_Component_Execute( snacContext, 0 /* dummy */, False );
	
	/* Stg_Class_Delete stuff */
	Stg_Component_Destroy( snacContext, 0 /* dummy */, False );
	Stg_Class_Delete( snacContext );
	free( filename );
	Stg_Class_Delete( ioHandler );
	
	Stg_Class_Delete( dictionary );
	
	/* Close off frameworks */
	Snac_Finalise();
	MPI_Finalize();
	
	return 0; /* success */
}
Ejemplo n.º 5
0
int
BMI_Initialize (const char *config_file, BMI_Model ** handle)
{

    BMI_Model          *self;

	MPI_Comm           CommWorld;
	int                rank;
	int                numProcessors;
	int                procToWatch;
	char*              filename;

    if (!handle)
        return BMI_FAILURE;
    
    self = malloc( sizeof(BMI_Model) );

	/* Initialise MPI, get world info */
	MPI_Init( NULL, NULL ); 	/* MPI_Init( &argc, &argv ); */
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size( CommWorld, &numProcessors );
	MPI_Comm_rank( CommWorld, &rank );
    
    /* Hardwire the process to watch to 0. 
       Note that it doesn't have to be 0 when multiple processrs are used. */ 
    procToWatch = 0;
#if 0
	if( argc >= 3 ) {
		procToWatch = atoi( argv[2] );
	}
	else {
		procToWatch = 0;
	}
#endif
	if( rank == procToWatch ) printf( "Watching rank: %i\n", rank );
	
	/* if (!Snac_Init( &argc, &argv )) { */
	if (!Snac_Init( NULL, NULL )) {
		fprintf(stderr, "Error initialising StGermain, exiting.\n" );
		exit(EXIT_FAILURE);
	}
	
	/* Snac's init message */
    {
        int tmp	= Stream_GetPrintingRank( Journal_Register( InfoStream_Type, "Context" ) );
        Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), 0 );
        Journal_Printf( /* DO NOT CHANGE OR REMOVE */
                       Journal_Register( InfoStream_Type, "Context" ), 
                       "Snac. Copyright (C) 2003-2005 Caltech, VPAC & University of Texas.\n" );
        Stream_Flush( Journal_Register( InfoStream_Type, "Context" ) );
        Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), tmp );
    }

    /* Ensures copyright info always come first in output */
	MPI_Barrier( CommWorld );
    
	
	/* Create the dictionary, and some fixed values */
    /* Hardwirred to the one-processor scenario for now. */
	self->dictionary = Dictionary_New();
	Dictionary_Add( self->dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( 0 ) );
	Dictionary_Add( self->dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( 1 ) );
	
	/* Read input */
	self->ioHandler = XML_IO_Handler_New();
    filename = strdup( config_file );
	if ( False == IO_Handler_ReadAllFromFile( self->ioHandler, filename, self->dictionary ) )
        {
            fprintf( stderr, "Error: Snac couldn't find specified input file %s. Exiting.\n", filename );
            exit( EXIT_FAILURE );
        }
	Journal_ReadFromDictionary( self->dictionary );
    free( filename );
    
    /* This is the handle to the SNAC's model data. */
	self->snacContext = Snac_Context_New( 0.0f, 0.0f, sizeof(Snac_Node), sizeof(Snac_Element), CommWorld, self->dictionary );
	if( rank == procToWatch ) Dictionary_PrintConcise( self->dictionary, self->snacContext->verbose );
    
	/* Construction phase -----------------------------------------------------------------------------------------------*/
	Stg_Component_Construct( self->snacContext, 0 /* dummy */, &(self->snacContext), True );
	
	/* Building phase ---------------------------------------------------------------------------------------------------*/
	Stg_Component_Build( self->snacContext, 0 /* dummy */, False );
	
	/* Initialisaton phase ----------------------------------------------------------------------------------------------*/
	Stg_Component_Initialise( self->snacContext, 0 /* dummy */, False );
	if( rank == procToWatch ) Context_PrintConcise( self->snacContext, self->snacContext->verbose );

    /* pass the pointer to Snac_Context to handle */
    *handle = self;
   
    return BMI_SUCCESS;
}