Exemple #1
0
static void Conclusion( void )
{
    StatProg();
    if( ProgSw & PS_ERROR ) {
        PurgeAll();
    }
    CloseLst();
}
Exemple #2
0
//__________________________________________________________________________________
void mpiOptimizerLoop (int rank, int size)
{
	long		 senderID = 0;
			
	ReportWarning (_String ("MPI Node:") & (long)rank & " is ready for MPIParallelOptimizer tasks");
				
	if (mpiPartitionOptimizer)
		ReportWarning (_String("MPI Partitions mode"));
	
	//printf ("Node %d waiting for a string\n", rank);
	_String* theMessage = MPIRecvString (-1,senderID);
	while (theMessage->sLength)
	{
		if (theMessage->beginswith ("#NEXUS"))
		{
			ReadDataSetFile (nil,true,theMessage);
			if (likeFuncNamesList.lLength!=1)
			{
				_String errMsg ("Malformed MPI likelihood function paraller optimizer startup command. No valid LF has been defined.n\n\n");
				FlagError (errMsg);
				break;						
			}
			
			// send back the list of independent variables
			
			_LikelihoodFunction * theLF = (_LikelihoodFunction*)likeFuncList (0);
			
			if (mpiParallelOptimizer && theLF->GetCategoryVars().lLength)
			{
				_String errMsg ("Likelihood functions spawned off to slave MPI nodes can't have category variables.n\n\n");
				FlagError (errMsg);
				break;						
			}
			
			_SimpleList* ivl = & theLF->GetIndependentVars();
			
			_String		 variableSpec (128L, true);
			
			(variableSpec) << LocateVar(ivl->lData[0])->GetName();

			for (long kk = 1; kk < ivl->lLength; kk++)
			{
				(variableSpec) << ';';
				(variableSpec) << LocateVar(ivl->lData[kk])->GetName();	
			}
			
			ReportWarning 		  (variableSpec);
			MPISendString		  (variableSpec,senderID);
			theLF->PrepareToCompute();
			theLF->MPI_LF_Compute (senderID, mpiPartitionOptimizer);
			theLF->DoneComputing();
			PurgeAll (true);
		}
		DeleteObject (theMessage);
		theMessage = MPIRecvString (-1,senderID);
	}	
	DeleteObject (theMessage);		
}
Exemple #3
0
//__________________________________________________________________________________
void mpiOptimizerLoop (int rank, int size)
{
    long		 senderID = 0;

    ReportWarning (_String ("[MPI] Node:") & (long)rank & " is ready for MPIParallelOptimizer tasks");

    if (hyphyMPIOptimizerMode == _hyphyLFMPIModePartitions)
        ReportWarning ("[MPI] MPI Partitions mode");

    //printf ("Node %d waiting for a string\n", rank);
    _String* theMessage = MPIRecvString (-1,senderID);
    while (theMessage->sLength)
    {
        if (theMessage->beginswith ("#NEXUS"))
        {
            //ReportWarning (*theMessage);
            ReadDataSetFile (nil,true,theMessage);
            if (likeFuncNamesList.lLength!=1)
            {
                FlagError ("[MPI] Malformed MPI likelihood function paraller optimizer startup command. Exactly ONE valid LF must be defined.n\n\n");
                break;
            }

            // send back the list of independent variables

            _LikelihoodFunction * theLF = (_LikelihoodFunction*)likeFuncList (0);
            if (hyphyMPIOptimizerMode == _hyphyLFMPIModeREL && theLF->CountObjects (4))
            {
                FlagError (_String("[MPI] Likelihood functions spawned off to slave MPI nodes can't have category variables.n\n\n"));
                break;
            }

            _SimpleList* ivl = & theLF->GetIndependentVars();
            _String		 variableSpec (128L, true);

            (variableSpec) << LocateVar(ivl->lData[0])->GetName();

            for (long kk = 1; kk < ivl->lLength; kk++)
            {
                (variableSpec) << ';';
                (variableSpec) << LocateVar(ivl->lData[kk])->GetName();
            }
            variableSpec.Finalize();
            ReportWarning 		  (_String("[MPI] Sending back the following variable list\n") & variableSpec);
            MPISendString		  (variableSpec,senderID);
            theLF->PrepareToCompute();
            theLF->MPI_LF_Compute (senderID, !(hyphyMPIOptimizerMode == _hyphyLFMPIModeREL ||
                                               hyphyMPIOptimizerMode  == _hyphyLFMPIModeSiteTemplate));
            theLF->DoneComputing();
            PurgeAll (true);
        }
        DeleteObject (theMessage);
        theMessage = MPIRecvString (-1,senderID);
    }
    DeleteObject (theMessage);
}
Exemple #4
0
_THyPhyString * _THyPhy::ExecuteBF (const char * buffer, bool doPurge)
{
    if (doPurge) {
        PurgeAll            (true);    // cleanup results of previous analysis
    }
    _String             commandString (buffer);

    if (commandString.beginswith ("#NEXUS"),false) {
        lastNexusDataMatrix = ReadDataSetFile (nil, 2, &commandString);
        commandString = nexusBFBody;
    }

    _ExecutionList      compiledCode  (commandString);

    ApplyPreferences    ();

    DeleteObject        ((_String*)errors);
    DeleteObject        ((_String*)warnings);
    DeleteObject        ((_String*)textout);

    errors              = new _String (128L,true);
    warnings            = new _String (128L,true);
    textout             = new _String (128L,true);

    askFID              = compiledCode.ExecuteAndClean (0x7ffffff,&_tHYPHYAskFor);
    _PMathObj bfReturn  = compiledCode.GetResult ();

    ((_String*)errors)->Finalize();
    ((_String*)warnings)->Finalize();
    ((_String*)textout)->Finalize();

    if (currentResultHolder->sData) {
        free (currentResultHolder->sData);
        currentResultHolder->sData = nil;
    }
    if (bfReturn) {
        _String * serializedReturn   = (_String*) bfReturn->toStr();
        currentResultHolder->sData   = serializedReturn->sData;
        serializedReturn->sData      = nil;
        currentResultHolder->sLength = serializedReturn->sLength;
    }
    return currentResultHolder;
}
clResourcesManager::~clResourcesManager()
{
	FLoaderThread->Exit( true );
	delete( FLoaderThread );

	Env->Logger->Log( L_LOG, "Resources total loading time:" );
	Env->Logger->Log( L_LOG, "         Waveforms: " + LStr::ToStr( FTime_Waveforms, 1 ) );
	Env->Logger->Log( L_LOG, "   Shader programs: " + LStr::ToStr( FTime_ShaderPrograms, 1 ) );
	Env->Logger->Log( L_LOG, "            Images: " + LStr::ToStr( FTime_Images, 1 ) );
	Env->Logger->Log( L_LOG, "         Materials: " + LStr::ToStr( FTime_Materials, 1 ) );
	Env->Logger->Log( L_LOG, "            Meshes: " + LStr::ToStr( FTime_Meshes, 1 ) );
	Env->Logger->Log( L_LOG, "     Render states: " + LStr::ToStr( FTime_RenderStates, 1 ) );
	Env->Logger->Log( L_LOG, "        Animations: " + LStr::ToStr( FTime_Animations, 1 ) );

	Env->Console->UnRegisterCommand( "PreCache",         Utils::Bind( &clResourcesManager::PreCacheC,   this ) );
	Env->Console->UnRegisterCommand( "ReCache",          Utils::Bind( &clResourcesManager::ReCacheC,    this ) );
	Env->Console->UnRegisterCommand( "ReCacheNew",       Utils::Bind( &clResourcesManager::ReCacheNewC, this ) );

	PurgeAll();
}
Exemple #6
0
//__________________________________________________________________________________
void mpiNormalLoop    (int rank, int size, _String & baseDir)
{
    long         senderID = 0;

    ReportWarning ("[MPI] Entered mpiNormalLoop");

    _String* theMessage     = MPIRecvString (-1,senderID),  // listen for messages from any node
             * resStr        = nil;

    while (theMessage->sLength) {
        setParameter    (mpiNodeID,    (_Parameter)rank);
        setParameter    (mpiNodeCount, (_Parameter)size);

        //ReportWarning (*theMessage);
        DeleteObject (resStr);
        resStr       = nil;
        if (theMessage->startswith (mpiLoopSwitchToOptimize) ) {
            hyphyMPIOptimizerMode   = theMessage->Cut(mpiLoopSwitchToOptimize.sLength,-1).toNum();

            ReportWarning           (_String("[MPI] Switched to mpiOptimizer loop with mode ") & hyphyMPIOptimizerMode);
            MPISendString           (mpiLoopSwitchToOptimize,senderID);
            mpiOptimizerLoop        (rank,size);
            ReportWarning           ("[MPI] Returned from mpiOptimizer loop");
            hyphyMPIOptimizerMode   = _hyphyLFMPIModeNone;
            pathNames               && & baseDir;
        } else if ( theMessage->Equal (&mpiLoopSwitchToBGM) ) {
            ReportWarning       ("[MPI] Received signal to switch to mpiBgmLoop");
            MPISendString       (mpiLoopSwitchToBGM, senderID); // feedback to source to confirm receipt of message
            mpiBgmLoop          (rank, size);
            ReportWarning       ("[MPI] Returned from mpiBgmLoop");
        } else {
            if (theMessage->beginswith ("#NEXUS")) {
                _String             msgCopy (*theMessage);
                ReportWarning       ("[MPI] Received a function to optimize");
                ReadDataSetFile     (nil,true,theMessage);
                ReportWarning       ("[MPI] Done with the optimization");
                _Variable*          lfName = FetchVar(LocateVarByName(MPI_NEXUS_FILE_RETURN));

                if (lfName) {
                    resStr = (_String*)(lfName->Compute()->toStr());
                } else {
                    _FString        *lfID = (_FString*)FetchObjectFromVariableByType (&lf2SendBack, STRING);

                    if (!lfID) {
                        FlagError (_String("[MPI] Malformed MPI likelihood function optimization request - did not specify the LF name to return in variable ") & lf2SendBack & ".\n\n\n" );
                        break;
                    }

                    long f = likeFuncNamesList.Find (lfID->theString);

                    if (f<0) {
                        FlagError ("[MPI] Malformed MPI likelihood function optimization request - LF name to return did not refer to a well-defined likelihood function.\n\n\n");
                        break;
                    }
                    _Parameter      pv;
                    checkParameter (shortMPIReturn, pv ,0);
                    resStr       = (_String*)checkPointer(new _String (1024L,true));
                    ((_LikelihoodFunction*)likeFuncList (f))->SerializeLF(*resStr,pv>0.5?_hyphyLFSerializeModeShortMPI:_hyphyLFSerializeModeLongMPI);
                    resStr->Finalize();
                }
            } else {
                _ExecutionList exL (*theMessage);
                _PMathObj res = exL.Execute();
                resStr = res?(_String*)res->toStr():new _String ("0");
            }

            checkPointer (resStr);
            MPISendString(*resStr,senderID);

            _Parameter      keepState = 0.0;
            checkParameter  (preserveSlaveNodeState, keepState, 0.0);

            if (keepState < 0.5) {
                PurgeAll (true);
                pathNames && & baseDir;
            }
        }
        DeleteObject (theMessage);
        theMessage = MPIRecvString (-1,senderID);
    }
    /*MPISendString(empty,senderID);*/
    DeleteObject (resStr);
    DeleteObject (theMessage);
}
Exemple #7
0
//__________________________________________________________________________________
void mpiNormalLoop    (int rank, int size, _String & baseDir)
{
	long		 senderID = 0;
	
	ReportWarning ("Entered mpiNormalLoop");

	_String* theMessage = MPIRecvString (-1,senderID),	// listen for messages from any node
			* resStr	= nil,
			_bgmSwitch ("_BGM_SWITCH_"),
			css("_CONTEXT_SWITCH_MPIPARTITIONS_");
				
	while (theMessage->sLength)
	{
		setParameter    (mpiNodeID, (_Parameter)rank);
		setParameter	(mpiNodeCount, (_Parameter)size);
		//ReportWarning (*theMessage);
		DeleteObject (resStr);
		resStr = nil;
		if (theMessage->Equal (&css) )
		{
			mpiPartitionOptimizer = true;
			ReportWarning ("Switched to mpiOptimizer loop");
			MPISendString(css,senderID);
			mpiOptimizerLoop (rank,size);
			ReportWarning ("Returned from mpiOptimizer loop");
			mpiPartitionOptimizer = false;
			pathNames && & baseDir;
		}
		else if ( theMessage->Equal (&_bgmSwitch) )
		{
			ReportWarning ("Received signal to switch to mpiBgmLoop");
			MPISendString (_bgmSwitch, senderID);	// feedback to source to confirm receipt of message
			mpiBgmLoop (rank, size);
			ReportWarning ("Returned from mpiBgmLoop");
		}
		else
		{
			if (theMessage->beginswith ("#NEXUS"))
			{
				_String		msgCopy (*theMessage);
				ReportWarning ("Received a function to optimize");
				ReadDataSetFile (nil,true,theMessage);
				ReportWarning ("Done with the optimization");
				_Variable*  lfName = FetchVar(LocateVarByName(MPI_NEXUS_FILE_RETURN));
				
				if (lfName)
				{
					resStr = (_String*)(lfName->Compute()->toStr());
				}
				else
				{
					long		f = LocateVarByName (lf2SendBack);
					if (f>=0)
						lfName = FetchVar(f);
											
					if (!(lfName&&(lfName->ObjectClass()==STRING)))
					{
						_String errMsg ("Malformed MPI likelihood function optimization request - missing LF name to return.\n\n\n");
						errMsg = errMsg & msgCopy;
						FlagError (errMsg);
						break;
					}
					
					f = likeFuncNamesList.Find (((_FString*)lfName->Compute())->theString);
					if (f<0)
					{
						_String errMsg ("Malformed MPI likelihood function optimization request - invalid LF name to return.\n\n\n");
						errMsg = errMsg & msgCopy;
						FlagError (errMsg);
						break;				
					}
					_Parameter pv;
					checkParameter (shortMPIReturn, pv ,0);
					resStr = new _String (1024L,true);
					checkPointer (resStr);
					((_LikelihoodFunction*)likeFuncList (f))->SerializeLF(*resStr,pv>0.5?5:2);
					resStr->Finalize();
				}
			}
			else
			{
				_ExecutionList exL (*theMessage);
				/*printf ("Received:\n %s\n", ((_String*)exL.toStr())->sData);*/
				_PMathObj res = exL.Execute();
				resStr = res?(_String*)res->toStr():new _String ("0");
			}
				
			checkPointer (resStr);
			DeleteObject (theMessage);
			MPISendString(*resStr,senderID);

			_Parameter 	   	keepState = 0.0;
			checkParameter  (preserveSlaveNodeState, keepState, 0.0);
			
			if (keepState < 0.5)
			{
				PurgeAll (true);
				pathNames && & baseDir;		
			}
		}
		theMessage = MPIRecvString (-1,senderID);		
	}
	/*MPISendString(empty,senderID);*/
	DeleteObject (resStr);
	DeleteObject (theMessage);	
}
Exemple #8
0
//__________________________________________________________________________________
int main (int argc, char* argv[])
{
	mainArgCount = argc - 1;
	
	
	#ifdef	__HYPHYMPI__
		  int 		   rank, 
		  			   size;
		  			   			   			 
		  MPI_Init	   (&argc, &argv);
		  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
		  MPI_Comm_size(MPI_COMM_WORLD, &size);
		  
		  setParameter  (mpiNodeID,    (_Parameter)rank);
		  setParameter	(mpiNodeCount, (_Parameter)size);
		  _hy_mpi_node_rank = rank;
		  
		  if (rank == 0)
		  {
			  mpiNodesThatCantSwitch.Populate (size,1,0);		  	
			/* {
				  char hostname[256];
				  gethostname(hostname, sizeof(hostname));
				  printf("PID %d on %s ready for attach\n", getpid(), hostname);
				  fflush(stdout);
				  //getchar ();
			  }	*/	
#endif
	
	
	//for (long k=0; k<NSIG; k++)
	//{
	//	signal(k, &hyphyBreak);
	//}
	
	#ifdef	__HYPHYMPI__
		  }
	#endif
	
	char 	curWd[4096],
		    dirSlash = GetPlatformDirectoryChar ();
	getcwd (curWd,4096);

	_String baseDir (curWd), 
			argFile;
		

	baseDir=baseDir & dirSlash;
	pathNames&& &baseDir;
	
	baseDirectory = baseDir;
	baseArgDir	  = baseDirectory;
	
	_ExecutionList ex;
			
#ifdef _OPENMP
	systemCPUCount = omp_get_max_threads();
#endif
	
#ifdef _MINGW32_MEGA_
	{
		char pid[16];
		snprintf (pid,16,"%u", GetCurrentProcessId());
		
		_String pipeName = _String("\\\\.\\pipe\\MEGAPipe") & pid;
		printf ("Pipe name = %s\n", pipeName.sData);
		if ((_HY_MEGA_Pipe = CreateFile(pipeName.sData, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
		{
			char* lpMsgBuf;
			FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER | 
				FORMAT_MESSAGE_FROM_SYSTEM |
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				GetLastError(),
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR) &lpMsgBuf,
				0, NULL );
			FlagError (_String("Failed to create a pipe named '") & pipeName & "' to send data from HyPhy to MEGA. Error: "&lpMsgBuf);
		}
	}
#endif	
	
	for (long i=1; i<argc;i++)
	{
		_String thisArg (argv[i]);
		if (thisArg.sData[0]=='-')
		{
			ProcessConfigStr (thisArg);
		}
		else
			if (thisArg.beginswith ("BASEPATH="))
			{
				baseArgDir = thisArg.Cut(9,-1);
				if (baseArgDir.sLength)
				{
					if (baseArgDir.sData[baseArgDir.sLength-1]!=dirSlash)
						baseArgDir = baseArgDir&dirSlash;
						
					baseDirectory = baseArgDir;
				}
			}
			else
				if (thisArg.beginswith ("USEPATH="))
				{
					baseDir 			= thisArg.Cut(8,-1);
					errorFileName 		= baseDir & errorFileName;
					messageFileName 	= baseDir & messageFileName;
					pathNames.Delete 	(0);
					pathNames&& 		&baseDir;
				}
				else
					#ifdef __MP__
					if (thisArg.beginswith ("CPU="))
					{
						_String cpus = thisArg.Cut(4,-1);
						systemCPUCount = cpus.toNum();
						if (systemCPUCount<1)
							systemCPUCount = 1;
						pthread_setconcurrency (systemCPUCount+1);
					}
					else
					#endif
				argFile = thisArg;
	}
	
  	GlobalStartup();

	if (calculatorMode)
	{
		printf ("\nHYPHY is running in calculator mode. Type 'exit' when you are finished.\n");
		while (ExpressionCalculator()) ;
		return 0;
	}
	
	if (pipeMode)
	{
		_String bfIn (stdin);
		_ExecutionList exIn (bfIn);
		exIn.Execute();
		GlobalShutdown();
		return 0;
	}
	
	// try to read the preferences
	_String		prefFile (curWd);
	prefFile = prefFile & '/' & prefFileName;
	FILE	 * testPrefFile = fopen (prefFile.sData,"r");
	if (!testPrefFile)
	{
		prefFile = baseArgDir & prefFileName;
		testPrefFile = fopen (prefFile.sData,"r");
	}
	if (testPrefFile)
	{		
		fclose(testPrefFile);
		ReadBatchFile (prefFile,ex);
		ex.Execute();
		ex.Clear();
	}
	//printf ("Node %d before mpiParallelOptimizer\n", rank);
	#ifdef __HYPHYMPI__
		if (rank>0)
		{
			//if (mpiParallelOptimizer || mpiPartitionOptimizer)
			//	mpiOptimizerLoop (rank, size);
			//else
			mpiNormalLoop (rank, size, baseDir);
			/*argFile = "SHUTDOWN_CONFIRM";
			MPISendString (argFile, senderID);*/
		}
		else
		{
	#endif
	if (!argFile.sLength)
	{	
		long selection = -2;
		if (!updateMode)
			selection = DisplayListOfChoices();

		if (selection == -1)
		{			
			dialogPrompt = "Batch file to run:";
			_String fStr (ReturnDialogInput (true));
			if (logInputMode)
			{
				_String tts = loggedFileEntry&fStr;
				loggedUserInputs && & tts;
			}
			
			PushFilePath (fStr);
			ReadBatchFile (fStr,ex);
		}
		else
		{
			_String templ;

			if (selection >= 0)
			    templ = baseArgDir &"TemplateBatchFiles" & dirSlash;
			else
			  	templ = baseArgDir & "TemplateBatchFiles" & dirSlash & "WebUpdate.bf";				
			
			if (selection >= 0)
				templ= templ&*(_String*)(*(_List*)availableTemplateFiles(selection))(2);

			PushFilePath (templ);
			ReadBatchFile (templ,ex);
		}
	}
	else
	{
#ifndef __MINGW32__
		if (argFile.sData[0] != '/')
			argFile		  = baseDirectory & argFile;
#else
		if (argFile.sData[1] != ':') // not an absolute path 
			argFile		  = baseDirectory & argFile;		
#endif
		PushFilePath  (argFile);
		ReadBatchFile (argFile,ex);
	}
	
	ex.Execute();
	
	if (usePostProcessors && (!updateMode))
	{
		ReadInPostFiles();
		printf ("\n\n**********Continue with result processing (y/n)?");
		_String c_str (StringFromConsole());
	
		if (logInputMode)
			loggedUserInputs && & c_str;

		if (c_str.getChar(0) !='n' && c_str.getChar(0)!='N' )
		{
			long choice = DisplayListOfPostChoices();
			while (choice != -1)
			{
				_ExecutionList postEx;
				argFile = *(_String*)(*(_List*)availablePostProcessors(choice-1))(1);
				PushFilePath (argFile);
				ReadBatchFile (argFile, postEx);
				postEx.Execute();	
				PopFilePath ();
				printf ("\n\n**********Continue with result processing (y/n)?");

				c_str = StringFromConsole();
				if (logInputMode)
					loggedUserInputs && & c_str;

				if (c_str.getChar(0)=='n' || c_str.getChar(0)=='N' ) 
					break;
				
				choice = DisplayListOfPostChoices();				
			}
		}
	}
	#ifdef __HYPHYMPI__
	}
	ReportWarning				(_String ("Node ") & (long)rank & " is shutting down\n");
	#endif
	
	
#ifdef _MINGW32_MEGA_
	if (_HY_MEGA_Pipe != INVALID_HANDLE_VALUE)
		CloseHandle (_HY_MEGA_Pipe);
#endif
	
	PurgeAll					(true);
	GlobalShutdown				();
	
	#ifdef __HYPHYMPI__
		if (rank == 0)
			printf ("\n\n");			
	#endif
	
}
Exemple #9
0
void _THyPhy::ClearAll (void)
{
    PurgeAll(true);
}
CountingBangRunner::~CountingBangRunner()
{
	PurgeAll();
}