SPModel: src/main.c Source File
VPAC - Computational Software Development
Main | SPModel | StGermain FrameWork |
Main Page | Alphabetical List | Class List | Directories | File List | Class Members | File Members

main.c

Go to the documentation of this file.
00001 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00002 **
00003 ** Copyright (C), 2004, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
00004 **
00005 ** Authors:
00006 **  Ogar R. Widjaja, Computational Scientist, VPAC.
00007 **  Raquibul Hassan, Software Engineer, VPAC. (raq@vpac.org)
00008 **  Keith Hsuan, Computational Scientist, VPAC (keith@vpac.org)
00009 **  William F. Appelbe, Director, VPAC. (bill@vpac.org)
00010 **  Stevan M. Quenette, Senior Software Engineer, VPAC. (steve@vpac.org)
00011 **  Patrick D. Sunter, Software Engineer, VPAC. (patrick@vpac.org)
00012 **
00013 ** This file may be distributed under the terms of the VPAC Public License
00014 ** as defined by VPAC of Australia and appearing in the file
00015 ** LICENSE.VPL included in the packaging of this file.
00016 **
00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019 **
00020 */
00036 #include <mpi.h>
00037 #include <StGermain/StGermain.h>
00038 #ifdef HAVE_SDL
00039     #include <SDL/SDL.h>
00040 #endif
00041 #include "SPModel/SPModel.h"
00042 
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <string.h>
00046 
00047 int main (int argc, char **argv)
00048 {
00049     MPI_Comm            CommWorld;
00050     int             rank;
00051     int             numProcessors;
00052     int             procToWatch;
00053     Dictionary*         dictionary;
00054     Dictionary*         componentDict;
00055     XML_IO_Handler*         ioHandler;
00056     char*               filename;
00057     SPModel_Context*        spmodelContext;
00058     
00059     /* Initialise MPI, get world info */
00060     MPI_Init( &argc, &argv );
00061     MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
00062     MPI_Comm_size( CommWorld, &numProcessors );
00063     MPI_Comm_rank( CommWorld, &rank );
00064     if( argc >= 3 ) {
00065         procToWatch = atoi( argv[2] );
00066     }
00067     else {
00068         procToWatch = 0;
00069     }
00070     if( rank == procToWatch ) printf( "Watching rank: %i\n", rank );
00071     
00072     
00073     if (!StGermain_Init( &argc, &argv )) {
00074         fprintf(stderr, "Error initialising StGermain, exiting.\n" );
00075         exit(EXIT_FAILURE);
00076     }
00077     if (!SPModel_Init( &argc, &argv )) {
00078         fprintf(stderr, "Error initialising SPModel, exiting.\n" );
00079         exit(EXIT_FAILURE);
00080     }
00081     
00082     /* Create the dictionary, and some fixed values */
00083     dictionary = Dictionary_New();
00084     Dictionary_Add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) );
00085     Dictionary_Add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( numProcessors ) );
00086     
00087     /* Read input */
00088     ioHandler = XML_IO_Handler_New();
00089     if( argc >= 2 ) {
00090         filename = strdup( argv[1] );
00091     }
00092     else {
00093         filename = strdup( "input.xml" );
00094     }
00095     if ( False == IO_Handler_ReadAllFromFile( ioHandler, filename, dictionary ) )
00096     {
00097         fprintf( stderr, "Error: SPModel couldn't find specified input file %s. Exiting.\n", filename );
00098         exit( EXIT_FAILURE );
00099     }
00100     Journal_ReadFromDictionary( dictionary );
00101     
00102     componentDict = Dictionary_GetDictionary( dictionary, "components" );
00103 
00104     if ( componentDict == NULL ) {
00105         componentDict = Dictionary_New();
00106     }
00107     
00108     spmodelContext = SPModel_Context_New( "context", 0.0f, 0.0f, CommWorld, dictionary );
00109     
00110     spmodelContext->CF = Stg_ComponentFactory_New( dictionary, componentDict, spmodelContext->register_Register );
00111     LiveComponentRegister_Add( spmodelContext->CF->LCRegister, (Stg_Component*) spmodelContext );
00112     
00113     if ( True == Dictionary_GetBool_WithDefault( dictionary, "showJournalStatus", False ) ) {
00114         Journal_PrintConcise(); 
00115     }       
00116     
00117     Context_Build( spmodelContext );
00118     
00119     Context_Initialise( spmodelContext );
00120     
00121     PluginsManager_Load( spmodelContext->plugins, spmodelContext, dictionary );
00122     
00123     PluginsManager_ConstructPlugins( spmodelContext->plugins, spmodelContext->CF ); 
00124     
00125     Context_Run( spmodelContext );
00126     
00127     Stg_Class_Delete( spmodelContext );
00128     StGermain_Finalise();
00129     MPI_Finalize();
00130     
00131     return 0; /* success */
00132 }