Пример #1
0
Bool StGermainBase_Init( int* argc, char** argv[] ) {
   char* directory;
   int   tmp;
   
   /* Initialise enough bits and pieces to get IO going */
   BaseFoundation_Init( argc, argv );
   BaseIO_Init( argc, argv );

   /* Write out the copyright message */

   
   Journal_Printf( Journal_Register( DebugStream_Type, "Context" ), "In: %s\n", __func__ );
   tmp = Stream_GetPrintingRank( Journal_Register( InfoStream_Type, "Context" ) );
   Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), 0 );
 
   Stream_Flush( Journal_Register( InfoStream_Type, "Context" ) );
   Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), tmp );
   
   /* Initialise the remaining bits and pieces */
   BaseContainer_Init( argc, argv );
   BaseAutomation_Init( argc, argv );
   BaseExtensibility_Init( argc, argv );
   BaseContext_Init( argc, argv );
   
   /* Add the StGermain path to the global xml path dictionary */
   directory = Memory_Alloc_Array( char, 200, "xmlDirectory" ) ;
   sprintf( directory, "%s%s", LIB_DIR, "/StGermain" );
   XML_IO_Handler_AddDirectory( "StGermain", directory  );
   Memory_Free( directory );
   
   /* Add the plugin path to the global plugin list */
   ModulesManager_AddDirectory( "StGermain", LIB_DIR );
   
   return True;
}
Пример #2
0
int main( int argc, char* argv[] ) {
	TestSuite*	suite;

	/* Initialise MPI, get world info. */
	MPI_Init( &argc, &argv );

	/* Initialise StGermain. */
	BaseFoundation_Init( &argc, &argv );
	BaseIO_Init( &argc, &argv );
	BaseContainer_Init( &argc, &argv );

	/* Create the test suite. */
	suite = TestSuite_New();
	TestSuite_SetProcToWatch( suite, (argc >= 2) ? atoi( argv[1] ) : 0 );
	TestSuite_SetTests( suite, nTests, tests );

	/* Run the tests. */
	TestSuite_Run( suite );

	/* Destroy test suites. */
	FreeObject( suite );

	/* Finalise StGermain. */
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();

	/* Close off MPI */
	MPI_Finalize();

	return MPI_SUCCESS;
}
Пример #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 ) {
		XML_IO_Handler*		io_handler = XML_IO_Handler_New();
		Dictionary*		dictionary = Dictionary_New();
		Dictionary_Index 	index;
		Stream*			stream = Journal_Register( InfoStream_Type, XML_IO_Handler_Type );
		
		/* use the base class functions */
		printf( "\ntest of raw data file:\n" );
		IO_Handler_ReadAllFromFile( io_handler, "data/rawdata.xml", dictionary ); 

		printf( "\ndictionary now contains:\n" );
		printf( "Dictionary:\n" );
		printf( "\tsize: %u\n", dictionary->size );
		printf( "\tdelta: %u\n", dictionary->delta );
		printf( "\tcount: %u\n", dictionary->count );
		printf( "\tentryPtr[0-%u]: {\n", dictionary->count );
		for( index = 0; index < dictionary->count; index++ ) {
			printf( "\t\t" );
			Dictionary_Entry_Print( dictionary->entryPtr[index], stream ); 
			printf( "\n" );
		}
		printf( "\t}\n" );


		/* Dictionary_Entry_Value_SetEncoding( Dictionary_Get( dictionary, "boundary_conditions2" ), RawASCII ); */

		IO_Handler_WriteAllToFile( io_handler, "data/newrawdata.xml", dictionary );
		Stg_Class_Delete( io_handler );
		Stg_Class_Delete( dictionary );
	}

	BaseIO_Finalise();
	BaseFoundation_Finalise();

	/* Close off MPI */
	MPI_Finalize();
	
	return EXIT_SUCCESS;
}
Пример #4
0
int main(int argc, char *argv[])
{
	int			rank;
	int			procCount;
	int			procToWatch;
	Stream*			stream;

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

	BaseFoundation_Init( &argc, &argv );

	RegressionTest_Init( "Base/Foundation/PrimitiveObject" );

	stream = Journal_Register( "info", "myStream" );
	
	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}

	{
		Stg_ObjectList* list;

		list = Stg_ObjectList_New();

		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_UnsignedChar( 'a', "char item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_UnsignedShort( 123, "short item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_UnsignedInt( 456, "int item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_UnsignedLong( 789, "long item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_Char( 'a', "char item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_Short( -123, "short item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_Int( -456, "int item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_Long( -789, "long item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_Float( 1.2f, "float item" ) );
		Stg_ObjectList_Append( list, Stg_PrimitiveObject_New_Double( 2.4, "double item" ) );

		Stg_ObjectList_PrintAllObjects( list, stream );

		Stg_Class_Delete( list );
	}
	
	RegressionTest_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #5
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 );
	BaseContainer_Init( &argc, &argv );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	
	if( rank == procToWatch ) {
		IndexMap*		map;
		Index			idx;
		Stream*			stream;
		
		stream = Journal_Register( Info_Type, "myStream" );
		
		map = IndexMap_New();
		for( idx = 0; idx < 100; idx++ )
			IndexMap_Append( map, idx + 1, 100 - idx );
		
		printf( "List Data:\n" );
		for( idx = 0; idx < 100; idx++ )
			printf( "\tlooking for %d, found %d\n", idx + 1, IndexMap_Find( map, idx + 1 ) );
		
		Stg_Class_Delete( map );
	}
	
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #6
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 );
	BaseContainer_Init( &argc, &argv );

	/* Tell the Journal_Firewall to Clean exit, rather than assert */
	Stream_SetFileBranch( Journal_GetTypedStream( ErrorStream_Type ), stJournal->stdOut );
	stJournal->firewallProducesAssert = False;

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) {
		IndexSet*			is;
		
		printf( "Watching rank: %i\n", rank );
		
		printf( "* Test Construction *\n" );
		is = IndexSet_New( 24 );
		
		printf( "* Test Insertion(Add) over limit *\n" );
		IndexSet_Add( is, 24 );
		printf( "* Shouldn't get here\n" );

		Stg_Class_Delete( is );
	}

	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #7
0
int main( int argc, char* argv[] ) {
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	Stream* stream;

	Stg_ObjectList* directories;
	PluginLoader* plugin;

	/* 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 );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );
	BaseExtensibility_Init( &argc, &argv );

	/* creating a stream */
	stream =  Journal_Register( Info_Type, __FILE__ );

	directories = Stg_ObjectList_New();
	Stg_ObjectList_PointerAppend( directories, StG_Strdup(LIB_DIR), "default dir", 0, 0, 0 );
	
	plugin = PluginLoader_NewLocal( "LocalPlugin", directories );

	Journal_Firewall( plugin != NULL, stream, "Failed!\n" );

	Journal_Printf( stream, "PluginLoader_GetName(): %s\n", PluginLoader_GetName( plugin ) );
	Print( plugin, stream );

	Stg_Class_Delete( plugin );
	Stg_Class_Delete( directories );
	
	BaseExtensibility_Finalise();
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();

	/* Close off MPI */
	MPI_Finalize();
                                                                                                                                    

	return 0;
}
Пример #8
0
int main(int argc, char *argv[])
{
	int			rank;
	int			procCount;
	int			procToWatch;
	Stream*			stream;

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

	BaseFoundation_Init( &argc, &argv );

	stream = Journal_Register( "info", "myStream" );
	
	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}

	if ( rank == procToWatch ) {
		NamedObject_Register* reg = NamedObject_Register_New();
	
		NamedObject_Register_Add( reg, TestObject_New( "a" ) );
		NamedObject_Register_Add( reg, TestObject_New( "b" ) );
		NamedObject_Register_Add( reg, TestObject_New( "c" ) );
		NamedObject_Register_Add( reg, TestObject_New( "d" ) );
		NamedObject_Register_Add( reg, TestObject_New( "e" ) );
	
		Print( reg, stream );

		Journal_Printf( stream, "Index of \"b\": %d\n", NamedObject_Register_GetIndex( reg, "b" ) );
		Print( NamedObject_Register_GetByName( reg, "d" ), stream );
		Print( NamedObject_Register_GetByIndex( reg, 2 ), stream );
	}

	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #9
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 );
	BaseContainer_Init( &argc, &argv );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	
	if( rank == procToWatch ) {
		List*			list;
		Index			idx;
		Stream*			stream;
		
		stream = Journal_Register( Info_Type, "myStream" );
		
		list = List_New( sizeof(unsigned) );
		for( idx = 0; idx < 100; idx++ ) {
			List_Resize( list, List_Size( list ) + 1 );
			List_ElementAt( list, unsigned, idx ) = 100 - idx;
		}
		
		Print( list, stream );
		
		printf( "List Data:\n" );
		for( idx = 0; idx < 100; idx++ )
			printf( "\telements[%d]: %d\n", idx, List_ElementAt( list, unsigned, idx ) );
		
		Stg_Class_Delete( list );
	}
int main( int argc, char* argv[] ) {
	Dictionary* dictionary;
	Stream* stream;
	
	MPI_Init( &argc, &argv );
	BaseFoundation_Init( &argc, &argv );
	BaseIO_Init( &argc, &argv );
	stream = Journal_Register (Info_Type, "myStream");
	Stream_RedirectFile( stream, "dictionaryOutput.dat" );

	dictionary = Dictionary_New();

	Dictionary_ReadAllParamFromCommandLine( dictionary, argc, argv );
	Print( dictionary, stream );
	
	Stg_Class_Delete( dictionary );
	
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	MPI_Finalize();
	
	return EXIT_SUCCESS;
}
Пример #11
0
int main( int argc, char* argv[] )
{
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	int procToWatch;
	
	Stream* stream;

	double**	complex2d;

	Index x1 = 5;
	Index y1[] = { 1, 2, 3, 4, 5 };


	Index i, j;

	/* 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 );
	
	stream = Journal_Register ( "info", "MyInfo" );
	
	if( argc >= 2 )
	{
		procToWatch = atoi( argv[1] );
	}
	else
	{
		procToWatch = 0;
	}
	if( rank == procToWatch )
	{
		Journal_Printf( stream,  "Watching rank: %i\n", rank );
	}

	Journal_Printf( stream, "2D Complex\n" );
	complex2d = Memory_Alloc_2DComplex_Unnamed( double, x1, y1 );
	
	/* write */
	for (i = 0; i < x1; ++i)
	{
		for (j = 0; j < y1[i]; ++j)
		{
			complex2d[i][j] = i + (double)(j / 10.0);
		}
	}
	
	/* read */
	for (i = 0; i < x1; ++i)
	{
		for (j = 0; j < y1[i]; ++j)
		{
			Journal_Printf( stream, "%lf ", complex2d[i][j] );
		}
		Journal_Printf( stream, "\n" );
	}
	
	
	Memory_Free( complex2d );

	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();

	return 0; /* success */
}
Пример #12
0
int main( int argc, char *argv[] ) {
	int		rank;
	int		procCount;
	int		procToWatch;
	Stream*		stream;
	
	/* Initialise MPI, get world info */
	MPI_Init( &argc, &argv );
	MPI_Comm_size( MPI_COMM_WORLD, &procCount );
	MPI_Comm_rank( MPI_COMM_WORLD, &rank );
	
	BaseFoundation_Init( &argc, &argv );

	RegressionTest_Init( "Base/Automation/Stg_Component" );
	
	BaseIO_Init( &argc, &argv );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );

	stream = Journal_Register( Info_Type, __FILE__ );
	
	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) {
		Stg_ComponentMeta* metaTest;

		XML_IO_Handler* io;
		Dictionary* allDict;
		Dictionary* compDict;

		CompositeVC* vc;
		
		Journal_Printf( stream, "%s\n", Stg_Component_GetMetadata() );

		metaTest = Stg_Component_CreateMeta( "blah", Variable_Type );
		Stg_Class_Print( metaTest, stream );
		Stg_Class_Delete( metaTest );

		allDict = Dictionary_New();
		io = XML_IO_Handler_New();
		IO_Handler_ReadAllFromFile( io, "data/metatest.xml", allDict );
		compDict = Dictionary_GetDictionary( allDict, "components" );
		vc = CompositeVC_DefaultNew( "vc" );	
		
		metaTest = Stg_Component_Validate( vc, CompositeVC_Type, compDict );
		Stg_Class_Print( metaTest, stream );
		Stg_Class_Delete( metaTest );

		Stg_Class_Delete( io );
		Stg_Class_Delete( compDict );
	}

	
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();

	RegressionTest_Finalise();
	
	BaseFoundation_Finalise();

	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #13
0
int main(int argc, char *argv[])
{
	int			rank;
	int			procCount;
	int			procToWatch;
	Stream*			stream;

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

	BaseFoundation_Init( &argc, &argv );

	RegressionTest_Init( "Base/Foundation/ObjectList" );

	stream = Journal_Register( "info", "myStream" );
	
	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}

	if ( rank == procToWatch ) {
		Index  nTestValues = 7;
		double testValues[] = {
			0.0,
			3.4562e-30,
			9.7324,
			97.654,
			104.321,
			-13762.1,
			0.0043253 };
		double tolerances[] = {
			1e-40,
			1e-40,
			1e-12,
			1e-12,
			1e-12,
			1e-12,
			1e-12 };
		double expectedRoundedToDecPlaces[7][4] = {
			{ 0.0, 0.0, 0.0, 0.0 },
			{ 0.0, 0.0, 0.0, 0.0 },
			{ 10., 9.7, 9.73, 9.732 },
			{ 98., 97.7, 97.65, 97.654 },
			{ 104., 104.3, 104.32, 104.321 },
			{ -13762., -13762.1, -13762.10, -13762.100 },
			{ 0.,    0.0, 0.00, 0.004 } };
		double expectedRoundedToSigFigs[7][4] = {
			{ 0.0, 0.0, 0.0, 0.0 },
			{ 0.0, 3e-30, 3.5e-30, 3.46e-30 },
			{ 0., 10, 9.7, 9.73 },
			{ 0., 100, 98, 97.7 },
			{ 0., 100, 100, 104 },
			{ 0., -10000, -14000, -13800 },
			{ 0., 0.004, 0.0043, 0.00433 } };
		double roundedValue;
		double errorMargin;
		Index testValue_I;
		Index nDecPlaces;
		Index nSigFigs;
		
		TestLMS( stream, "Acrobat", "BOAT", True );
		TestLMS( stream, "Abracadabra", "Yabbadabbadoo", True );
		TestLMS( stream, "Abracadabra", "Yabbadabbadoo", False );
		TestLMS( stream, "Python", "PythonShape", False );
		
		TestIsStringNumeric( stream, "nan" );
		TestIsStringNumeric( stream, "567" );
		TestIsStringNumeric( stream, "1.0e90" );
		TestIsStringNumeric( stream, "1e90e80" );
		TestIsStringNumeric( stream, ".asdfasdf" );
		TestIsStringNumeric( stream, ".0032" );
		TestIsStringNumeric( stream, ".0032.00" );
		
		TestIsStringEmpty( stream, "\t \n" );
		TestIsStringEmpty( stream, "asdf" );
		TestIsStringEmpty( stream, "    " );
		TestIsStringEmpty( stream, "    \n" );
		TestIsStringEmpty( stream, "  sdf  \n" );

		printf("\nTesting rounding to certain number of decimal places:\n");
		for ( testValue_I = 0; testValue_I < nTestValues; testValue_I++ ) {
			for ( nDecPlaces = 0; nDecPlaces <=3; nDecPlaces++ ) {
				roundedValue = StG_RoundDoubleToNDecimalPlaces(
					testValues[testValue_I], nDecPlaces );
				errorMargin = fabs( roundedValue -
					expectedRoundedToDecPlaces[testValue_I][nDecPlaces] );

				if ( errorMargin <= tolerances[testValue_I] ) {
					printf( "Value %8g rounded to %u dec places was within "
						"tolerance of expected value %8g.\n",
						testValues[testValue_I], nDecPlaces,
						expectedRoundedToDecPlaces[testValue_I][nDecPlaces] );
				}
				else {
					printf( "Value %8g rounded to %u dec places was not within "
						"tolerance of expected value %8g.\n",
						testValues[testValue_I], nDecPlaces,
						expectedRoundedToDecPlaces[testValue_I][nDecPlaces] );
					printf( "(error margin was %.8g)\n", errorMargin );
				}
			}
		}

		printf("\nTesting rounding to certain number of significant figures:\n");
		for ( testValue_I = 0; testValue_I < nTestValues; testValue_I++ ) {
			for ( nSigFigs = 1; nSigFigs <=3; nSigFigs++ ) {
				roundedValue = StG_RoundDoubleToNSigFigs(
					testValues[testValue_I], nSigFigs );
				errorMargin = fabs( roundedValue -
					expectedRoundedToSigFigs[testValue_I][nSigFigs] );
				if ( errorMargin <= tolerances[testValue_I] ) {
					printf( "Value %8g rounded to %u sig. figures was within "
						"tolerance of expected value %8g.\n",
						testValues[testValue_I], nSigFigs,
						expectedRoundedToSigFigs[testValue_I][nSigFigs] );
				}
				else {
					printf( "Value %8g rounded to %u sig. figures was not within "
						"tolerance of expected value %8g.\n",
						testValues[testValue_I], nSigFigs,
						expectedRoundedToSigFigs[testValue_I][nSigFigs] );
					printf( "(error margin was %.8g)\n", errorMargin );
				}
			}
		}
	}

	RegressionTest_Finalise();

	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #14
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* myInfo;
		Stream* myDebug;		
		Stream* myDump;
		Stream* myError;
		
		Stream* allNew;

		myInfo = Journal_Register( Info_Type, "MyInfo" );
		myDebug = Journal_Register( Debug_Type, "MyDebug" );
		myDump = Journal_Register( Dump_Type, "MyDump" );
		myError = Journal_Register( Error_Type, "MyError" );
		
		allNew = Journal_Register( "My own stream", "allNew" );
		
		printf( "TEST: \"HELLO\" should appear\n" );
		Journal_Printf( myInfo, "%s\n", "HELLO" );
		printf( "TEST: \"WORLD\" should NOT appear\n" );
		Journal_Printf( myDebug, "%s\n", "HELLO" );
		printf( "TEST: \"HELLO\" should NOT appear\n" );
		Journal_Printf( myDump, "%s\n", "HELLO" );
		printf( "TEST: \"WORLD\" should NOT appear\n" );
		Journal_Printf( myError, "%s\n", "HELLO" );

		printf( "Turning off myInfo\n" );
		Journal_Enable_NamedStream( Info_Type, "MyInfo" , False );
		
		printf( "TEST: \"HELLO\" should NOT appear\n" );
		Journal_Printf( myInfo, "%s\n", "HELLO" );

		printf( "Turning on Dump\n"  );
		Journal_Enable_TypedStream( Dump_Type, True );
		Journal_Enable_NamedStream( Dump_Type, "MyDump", True );
		
		printf( "TEST: \"HELLO\" should appear\n" );
		Journal_Printf( myDump, "%s\n", "HELLO" );
		
		printf( "Turning off Journal\n" );
		stJournal->enable = False;

		printf( "TEST: \"HELLO\" should NOT appear\n" );		
		Journal_Printf( myDump, "%s\n", "HELLO" );
		
		stJournal->enable = True;
		
		Journal_Enable_NamedStream( Info_Type, "MyInfo", True );
		
		printf( "TEST: DPrintf\n" );
		Journal_DPrintf( myInfo, "DPrintf\n" );	
	}

	Memory_Print();
	
	BaseIO_Finalise();

	BaseFoundation_Finalise();

	/* Close off MPI */
	MPI_Finalize();
	
	return EXIT_SUCCESS;
}
int main( int argc, char* argv[] ) {
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	int procToWatch;
	Dictionary* dictionary;
	AbstractContext* abstractContext;
	
	/* 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 );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );
	BaseExtensibility_Init( &argc, &argv );
	BaseContext_Init( &argc, &argv );
	stream = Journal_Register (Info_Type, "myStream");

	/* Redirect the error stream to stdout, so we can check warnings
	appear correctly */
	Stream_SetFileBranch( Journal_GetTypedStream( ErrorStream_Type ), stJournal->stdOut );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) Journal_Printf( (void*) stream, "Watching rank: %i\n", rank );

	/* Read input */
	dictionary = Dictionary_New();
	dictionary->add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) );
	dictionary->add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( numProcessors ) );
	
	/* Build the context */
	abstractContext = _AbstractContext_New( 
		sizeof(AbstractContext), 
		"TestContext", 
		MyDelete, 
		MyPrint, 
		NULL,
		NULL, 
		NULL, 
		_AbstractContext_Build, 
		_AbstractContext_Initialise, 
		_AbstractContext_Execute, 
		_AbstractContext_Destroy, 
		"context", 
		True, 
		MySetDt, 
		0, 
		10, 
		CommWorld, 
		dictionary );

	/* add hooks to existing entry points */
	ContextEP_Append( abstractContext, AbstractContext_EP_Dt, MyDt );

	if( rank == procToWatch ) {
		Stream* stream = Journal_Register( InfoStream_Type, AbstractContext_Type );
		Stg_Component_Build( abstractContext, 0 /* dummy */, False );
		Stg_Component_Initialise( abstractContext, 0 /* dummy */, False );
		Context_PrintConcise( abstractContext, stream );
		Stg_Component_Execute( abstractContext, 0 /* dummy */, False );
		Stg_Component_Destroy( abstractContext, 0 /* dummy */, False );
	}
	
	/* Stg_Class_Delete stuff */
	Stg_Class_Delete( abstractContext );
	Stg_Class_Delete( dictionary );
	
	BaseContext_Finalise();
	BaseExtensibility_Finalise();
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #16
0
int main( int argc, char* argv[] )
{
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	int procToWatch;
	
	Stream* stream;

	double*		one2d;
	Index i, j;

	/* 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 );
	
	stream = Journal_Register ( "info", "MyInfo" );
	
	if( argc >= 2 )
	{
		procToWatch = atoi( argv[1] );
	}
	else
	{
		procToWatch = 0;
	}
	if( rank == procToWatch )
	{
		Journal_Printf( stream,  "Watching rank: %i\n", rank );
	}

	Journal_Printf( stream, "2D as 1D\n" );
	one2d = Memory_Alloc_2DArrayAs1D_Unnamed( double, 3, 2 );

	Memory_Print();

	/* write */	
	for ( i = 0; i < 3; ++i )
	{
		for ( j = 0; j < 2; ++j )
		{
			Memory_Access2D( one2d, i, j, 2 ) = i + (j / 10.0);
		}
	}

	/* read */
	for ( i = 0; i < 3; ++i )
	{
		for ( j = 0; j < 2; ++j )
		{
			Journal_Printf( stream, "%lf ", Memory_Access2D( one2d, i, j, 2 ) );
		}
		Journal_Printf( stream, "\n" );
	}

	one2d = Memory_Realloc_2DArrayAs1D( one2d, double, 3, 2, 4, 4 );

	Memory_Print();

	/* read again */
	for ( i = 0; i < 3; ++i )
	{
		for ( j = 0; j < 2; ++j )
		{
			Journal_Printf( stream, "%lf ", Memory_Access2D( one2d, i, j, 4 ) );
		}
		Journal_Printf( stream, "\n" );
	}
	
	/* write */	
	for ( i = 0; i < 4; ++i )
	{
		for ( j = 0; j < 4; ++j )
		{
			Memory_Access2D( one2d, i, j, 4 ) = i + (j / 10.0);
		}
	}

	/* read */
	for ( i = 0; i < 4; ++i )
	{
		for ( j = 0; j < 4; ++j )
		{
			Journal_Printf( stream, "%lf ", Memory_Access2D( one2d, i, j, 4 ) );
		}
		Journal_Printf( stream, "\n" );
	}


	Memory_Free( one2d );

	Memory_Print();

	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();

	return 0; /* success */
}
Пример #17
0
int main( int argc, char* argv[] ) {
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	int procToWatch;
	EntryPoint* entryPoint;
	Stream* stream;
	double  result;
	
	/* 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 );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );
	BaseExtensibility_Init( &argc, &argv );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	
	/* creating a stream */
	stream =  Journal_Register( InfoStream_Type, "myStream" );
	Stream_SetPrintingRank( stream, procToWatch );
	
	Journal_Printf( stream, "Watching rank: %i\n", rank );
	
	/* Get Maximum of Values */
	entryPoint = EntryPoint_New( testEpName, EntryPoint_Maximum_VoidPtr_CastType );
	EP_Append( entryPoint, Return1 );
	EP_Append( entryPoint, Return89 );
	EP_Append( entryPoint, ReturnNeg43 );
	EP_Append( entryPoint, ReturnZero );
	result = ((EntryPoint_Maximum_VoidPtr_CallCast*) entryPoint->run)( entryPoint, stream );
	Journal_PrintDouble( stream, result );
	Stg_Class_Delete( entryPoint );

	/* Get Minimum of Values */
	entryPoint = EntryPoint_New( testEpName, EntryPoint_Minimum_VoidPtr_CastType );
	EP_Append( entryPoint, Return1 );
	EP_Append( entryPoint, Return89 );
	EP_Append( entryPoint, ReturnNeg43 );
	EP_Append( entryPoint, ReturnZero );
	result = ((EntryPoint_Minimum_VoidPtr_CallCast*) entryPoint->run)( entryPoint, stream );
	Journal_PrintDouble( stream, result );
	Stg_Class_Delete( entryPoint );	

	BaseExtensibility_Finalise();
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();

	return 0; /* success */
}
Пример #18
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;
}
Пример #19
0
int main( int argc, char* argv[] ) {
	
	Stream*				stream = NULL;
	Dictionary*			dictionary;
	Dictionary_Entry_Value*		tmpVal0;
	Dictionary_Entry_Value*		tmpVal1; 
	
	MPI_Init( &argc, &argv );
	BaseFoundation_Init( &argc, &argv );
	BaseIO_Init( &argc, &argv );
	stream = Journal_Register (Info_Type, "myStream");

	dictionary = Dictionary_New();

	tmpVal0 = Dictionary_Entry_Value_NewStruct();
	tmpVal1 = Dictionary_Entry_Value_NewStruct();
	Dictionary_Entry_Value_AddMember( tmpVal1, "name", Dictionary_Entry_Value_FromString( "bill" ) );
	Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 1.0f ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 );
	tmpVal1 = Dictionary_Entry_Value_NewList();
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "bottom" ) );
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "top" ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 );
	Dictionary_Add( dictionary, "one", tmpVal0 );
	
	tmpVal0 = Dictionary_Entry_Value_NewStruct();
	tmpVal1 = Dictionary_Entry_Value_NewStruct();
	Dictionary_Entry_Value_AddMember( tmpVal1, "new_name", Dictionary_Entry_Value_FromString( "frank" ) );
	Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 2.0f ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 );
	tmpVal1 = Dictionary_Entry_Value_NewList();
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "left" ) );
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "right" ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 );
	Dictionary_AddMerge( dictionary, "one", tmpVal0, Dictionary_MergeType_Append );
	
	Print( dictionary, stream );
	Stg_Class_Delete( dictionary );
	
	dictionary = Dictionary_New();
	
	tmpVal0 = Dictionary_Entry_Value_NewStruct();
	tmpVal1 = Dictionary_Entry_Value_NewStruct();
	Dictionary_Entry_Value_AddMember( tmpVal1, "name", Dictionary_Entry_Value_FromString( "bill" ) );
	Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 1.0f ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 );
	tmpVal1 = Dictionary_Entry_Value_NewList();
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "bottom" ) );
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "top" ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 );
	Dictionary_Add( dictionary, "one", tmpVal0 );
	
	tmpVal0 = Dictionary_Entry_Value_NewStruct();
	tmpVal1 = Dictionary_Entry_Value_NewStruct();
	Dictionary_Entry_Value_AddMember( tmpVal1, "new_name", Dictionary_Entry_Value_FromString( "frank" ) );
	Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 2.0f ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 );
	tmpVal1 = Dictionary_Entry_Value_NewList();
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "left" ) );
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "right" ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 );
	Dictionary_AddMerge( dictionary, "one", tmpVal0, Dictionary_MergeType_Merge );
	
	Print( dictionary, stream );
	Stg_Class_Delete( dictionary );
	
	dictionary = Dictionary_New();
	
	tmpVal0 = Dictionary_Entry_Value_NewStruct();
	tmpVal1 = Dictionary_Entry_Value_NewStruct();
	Dictionary_Entry_Value_AddMember( tmpVal1, "name", Dictionary_Entry_Value_FromString( "bill" ) );
	Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 1.0f ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 );
	tmpVal1 = Dictionary_Entry_Value_NewList();
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "bottom" ) );
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "top" ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 );
	Dictionary_Add( dictionary, "one", tmpVal0 );
	
	tmpVal0 = Dictionary_Entry_Value_NewStruct();
	tmpVal1 = Dictionary_Entry_Value_NewStruct();
	Dictionary_Entry_Value_AddMember( tmpVal1, "new_name", Dictionary_Entry_Value_FromString( "frank" ) );
	Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 2.0f ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 );
	tmpVal1 = Dictionary_Entry_Value_NewList();
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "left" ) );
	Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "right" ) );
	Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 );
	Dictionary_AddMerge( dictionary, "one", tmpVal0, Dictionary_MergeType_Replace );
	
	Print( dictionary, stream );
	Stg_Class_Delete( dictionary );
	
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	MPI_Finalize();
	
	return EXIT_SUCCESS;
}
Пример #20
0
int main( int argc, char* argv[] ) {
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	int procToWatch;
	Dictionary* dictionary;
	AbstractContext* abstractContext;
	
	/* 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 );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );
	BaseExtensibility_Init( &argc, &argv );
	BaseContext_Init( &argc, &argv );
	
	stream =  Journal_Register( InfoStream_Type, "myStream" );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) Journal_Printf( (void*) stream, "Watching rank: %i\n", rank );
	
	/* Read input */
	dictionary = Dictionary_New();
	
	/* Build the context */
	abstractContext = _AbstractContext_New( 
		sizeof(AbstractContext), 
		"TestContext", 
		MyDelete, 
		MyPrint, 
		NULL,
		NULL, 
		NULL, 
		_AbstractContext_Build, 
		_AbstractContext_Initialise, 
		_AbstractContext_Execute, 
		_AbstractContext_Destroy, 
		"context", 
		True, 
		MySetDt, 
		0, 
		10, 
		CommWorld, 
		dictionary );

	/* add hooks to existing entry points */
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Build, MyBuild );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Initialise, MyInitialConditions );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Solve, MySolve );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Dt, MyDt );

	if( rank == procToWatch ) {
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->_size: %lu\n", 
			abstractContext->entryPoint_Register->_size );
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->count: %u\n", 
			abstractContext->entryPoint_Register->count );
	}
	
	ContextEP_Append( abstractContext, AbstractContext_EP_Solve, MySolve2 );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Initialise, MyInitialConditions2 ); 

	if( rank == procToWatch ) {
		stream = Journal_Register( InfoStream_Type, AbstractContext_Type );
		AbstractContext_PrintConcise( abstractContext, stream );
		
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->_size: %lu\n", 
			abstractContext->entryPoint_Register->_size );
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->count: %u\n", 
			abstractContext->entryPoint_Register->count );
	}

	/* Run the context */
	if( rank == procToWatch ) {
		Stg_Component_Build( abstractContext, 0 /* dummy */, False );
		Stg_Component_Initialise( abstractContext, 0 /* dummy */, False );
		Stg_Component_Execute( abstractContext, 0 /* dummy */, False );
		Stg_Component_Destroy( abstractContext, 0 /* dummy */, False );
	}
	
	/* Stg_Class_Delete stuff */
	Stg_Class_Delete( abstractContext );
	Stg_Class_Delete( dictionary );
	
	BaseContext_Finalise();
	BaseExtensibility_Finalise();
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Пример #21
0
int main( int argc, char* argv[] ) {
	MPI_Comm			CommWorld;
	int				rank;
	int				numProcessors;
	int				procToWatch;
	int **keys;
	
	MaxHeap *heap;
	int i = 0;
	Stream *myStream = NULL;
	
	/* 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 );
	BaseContainer_Init( &argc, &argv );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	
	if( rank == procToWatch ) {
		
		myStream = Journal_Register( InfoStream_Type, "LinkedListStream" );
		data = Memory_Alloc_Array_Unnamed( int, NUM_DATA );
		keys = Memory_Alloc_Array_Unnamed( int*, NUM_INITIAL_DATA );
		
		Journal_Printf( myStream, "\nCreating the Heap\n" );
		for(i=0; i<NUM_INITIAL_DATA; i++){
			data[i] = i;
			keys[i] = &(data[i]);
		}
		
		heap = MaxHeap_New(
					(void**)(keys), sizeof(int),
					NUM_INITIAL_DATA,
					keySwap,
					compareFunction,
					extendArray );

		Journal_Printf( myStream, "\nPrinting the Heap\n" );
		Stg_Class_Print( heap, myStream );
		
		Journal_Printf( myStream, "\nInserting more entries into the Heap\n" );
		for( i=50; i<NUM_DATA; i++ ){
			data[i] = i;
			MaxHeap_Insert( heap, &(data[i]) );
		}
		
		Journal_Printf( myStream, "\nPrinting the Heap\n" );
		Stg_Class_Print( heap, myStream );
		
		Journal_Printf( myStream, "\nExtracting all the entries in the Heap\n" );
		for( i=0; i<NUM_DATA; i++ ){
			printf( "Heap Max %d\n", *(int*)MaxHeap_Extract( (_Heap*)heap ) );
		}
		
		Journal_Printf( myStream, "\nPrinting the Heap\n" );
		Stg_Class_Print( heap, myStream );
	
		Journal_Printf( myStream, "\nDeleting the Heap\n" );
		Stg_Class_Delete( (void*)heap );
		
		Memory_Free( data );
	}