/*
 * $Id: Mpi2CommFactory.java,v 1.4 1999/11/28 08:56:00 yamauchi Exp $
 *     (M\pi)^2 : Factory of Mpi2 Communicator 
 *	Copyright 1999 By YAMAUCHI Hitoshi 山内 斉 
 *	@author YAMAUCHI Hitoshi 山内 斉
 *
 * original source mpi2communStandAlone.h mpi2communStandAlone.cc
 *
 * 実際の通信に何を使うかを隠蔽する．
 *
 * 1999年8月 9日(月) 
 */

package jp.ac.tohoku.is.archi.mpi2.net;

import  jp.ac.tohoku.is.archi.mpi2.sysparam.Mpi2Enum;

/**
 * (M\pi)^2 が用いる通信関数群の interface
 */
public final class Mpi2CommFactory {
    /*
     * factory and singleton
     */
    private static Mpi2Communicator mCommunicator = null;
    public  static Mpi2Communicator getInstance()
    {
	if(mCommunicator == null)
	{
	    throw new 
		RuntimeException("Error!:Mpi2CommFactory is not inited.");
	}
	return(mCommunicator);
    }

    /**
     * initialize communicator 
     */
    public static void initCommunicator(int communicatorType)
    {
	if(mCommunicator != null)
	{
	    throw new 
		RuntimeException("Error!:Mpi2CommFactory already inited.");
	}
	switch(communicatorType)
	{
	case Mpi2Enum.MPI2COMM_OnePE:
	    mCommunicator = new Mpi2CommunicatorOnePE();
	    break;
	case Mpi2Enum.MPI2COMM_mpiJavaS1:
	    mCommunicator = new Mpi2CommunicatorMpiJavaS1();
	    break;
	case Mpi2Enum.MPI2COMM_mpiJavaEncoder:
	    mCommunicator = new Mpi2CommunicatorMpiJavaEncoder();
	    break;
	default:
	    throw new 
		RuntimeException("Error!:No such Mpi2Communicator.");
	}
    }
}

