Esempio n. 1
0
        public static void SetupParallelism(ref string[] args)
        {
            //  Set up MPI
            DAVectorUtility.MPI_Environment  = new MPI.Environment(ref args);
            DAVectorUtility.MPI_communicator = Communicator.world;                    //initializing MPI world communicator
            DAVectorUtility.MPI_Rank         = DAVectorUtility.MPI_communicator.Rank; // Rank of this process
            DAVectorUtility.MPI_Size         = DAVectorUtility.MPI_communicator.Size; // Number of MPI Processes

            // Set up MPI
            DAVectorUtility.MPIperNodeCount = DAVectorUtility.MPI_Size / DAVectorUtility.NodeCount;

            if ((DAVectorUtility.MPIperNodeCount * DAVectorUtility.NodeCount) != DAVectorUtility.MPI_Size)
            {
                Exception e = DAVectorUtility.SALSAError("Inconsistent MPI counts Nodes "
                                                         + DAVectorUtility.NodeCount.ToString() + " Size " + DAVectorUtility.MPI_Size.ToString());

                throw (e);
            }

            DAVectorUtility.ParallelPattern = "---------------------------------------------------------\nMachine:"
                                              + MPI.Environment.ProcessorName.ToString() + " " + DAVectorUtility.ThreadCount.ToString()
                                              + "x" + DAVectorUtility.MPIperNodeCount.ToString() + "x" + DAVectorUtility.NodeCount.ToString();
            if (DAVectorUtility.MPI_Rank == 0)
            {
                DAVectorUtility.SALSAPrint(0, DAVectorUtility.ParallelPattern);
            }
        }   // End SetupParallelism
Esempio n. 2
0
            //  Note FinalClusterCount, FinalCreatedIndex and FinalHostSpecification ONLY used in UpdateMode 2 and only set in this case
            public void PipelineDistributedBroadcast(double[][] InitialDoubleComponents, double[][] FinalDoubleComponents, int[][] InitialIntegerComponents, int[][] FinalIntegerComponents,
                                                     int[] InitialCreatedIndex, int[] FinalCreatedIndex, int[] InitialHostSpecification, int[] FinalHostSpecification, ref int FinalClusterCount)
            {
                FinalClusterCount = 0;
                if (DAVectorUtility.MPI_Size <= 1)
                {
                    return;
                }

                // Now process distributed clusters
                // Variables for processing createdindex
                int NodeStoragePosition        = -1;
                int TransportedStoragePosition = -1;
                int NodeAccumulationPosition   = -1;
                int ThreadAccumulationPosition = -1;

                //  Place where received data stored
                int FinalDataLocationIndex = -1;

                ++Program.NumberPipelineGroups; // Increment calls of this routine

                int[] DownbySteps      = new int[DAVectorUtility.MPI_Size];
                int[] UpbySteps        = new int[DAVectorUtility.MPI_Size];
                int[] DownbyStepsTotal = new int[DAVectorUtility.MPI_Size];
                int[] UpbyStepsTotal   = new int[2 * DAVectorUtility.MPI_Size];
                for (int PipelineSteps = 0; PipelineSteps < DAVectorUtility.MPI_Size; PipelineSteps++)
                {
                    DownbySteps[PipelineSteps] = 0;
                    UpbySteps[PipelineSteps]   = 0;
                }

                //  Set NumberUp and NumberDown
                for (int ClusterIndirectIndex = 0; ClusterIndirectIndex < InitialArraySize; ClusterIndirectIndex++)
                {
                    int PackedHost = InitialHostSpecification[ClusterIndirectIndex];
                    for (int PipelineSteps = 1; PipelineSteps < DAVectorUtility.MPI_Size; PipelineSteps++)
                    {
                        if (HostRangeProcessing)
                        {
                            int H1 = PackedHost >> ClusteringSolution.PACKINGSHIFT;
                            int H2 = H1 >> ClusteringSolution.PACKINGSHIFT;
                            H1 = H1 & ClusteringSolution.PACKINGMASK;
                            if (H2 > (DAVectorUtility.MPI_Rank + PipelineSteps - 1))
                            {
                                ++UpbySteps[PipelineSteps];
                            }
                            if (H1 < (DAVectorUtility.MPI_Rank - PipelineSteps + 1))
                            {
                                ++DownbySteps[PipelineSteps];
                            }
                        }
                        else
                        {
                            int H = PackedHost & ClusteringSolution.PACKINGMASK;
                            if (H > (DAVectorUtility.MPI_Rank + PipelineSteps - 1))
                            {
                                ++UpbySteps[PipelineSteps];
                            }
                            if (H < (DAVectorUtility.MPI_Rank - PipelineSteps + 1))
                            {
                                ++DownbySteps[PipelineSteps];
                            }
                        }
                    }
                }
                for (int PipelineSteps = 0; PipelineSteps < DAVectorUtility.MPI_Size; PipelineSteps++)
                {
                    UpbyStepsTotal[PipelineSteps] = UpbySteps[PipelineSteps];
                    UpbyStepsTotal[PipelineSteps + DAVectorUtility.MPI_Size] = DownbySteps[PipelineSteps];
                }
                DAVectorUtility.StartSubTimer(DAVectorUtility.MPIREDUCETiming4);
                UpbyStepsTotal = DAVectorUtility.MPI_communicator.Allreduce <int>(UpbyStepsTotal, Operation <int> .Add);
                DAVectorUtility.StopSubTimer(DAVectorUtility.MPIREDUCETiming4);
                for (int PipelineSteps = 0; PipelineSteps < DAVectorUtility.MPI_Size; PipelineSteps++)
                {
                    DownbyStepsTotal[PipelineSteps] = UpbyStepsTotal[PipelineSteps + DAVectorUtility.MPI_Size];
                }


                // Variables Used for Up and Down Sections
                bool Initialstep;
                int  CurrentNode         = DAVectorUtility.MPI_Rank;
                int  ReceivedTotal       = 0;
                int  NumberClustertoSend = 0;
                int  NumberDoubletoSend  = 0;
                int  NumberIntegertoSend = 0;
                int  IsItOK;

                // Process Clusters going Up the Chain
                Initialstep = true;
                int LocalTotal = UpbySteps[1];;
                int StepsUp    = 0;

                while (true)
                {
                    // Decide if ANY node needs to communicate Up
                    ++StepsUp;
                    if (StepsUp >= DAVectorUtility.MPI_Size)
                    {
                        break;
                    }
                    int JobTotal = UpbyStepsTotal[StepsUp];
                    if (JobTotal == 0)
                    {
                        break;
                    }


                    // Some Nodes want to go up the line
                    int SourceProc = MPI.Intercommunicator.Null;
                    int DestProc   = MPI.Intercommunicator.Null;
                    int SourceTag  = 0; // Random Number
                    int DestTag    = 0;
                    SourceProc = DAVectorUtility.MPI_Size - 1;
                    DestProc   = 0;
                    if (CurrentNode != 0)
                    {
                        SourceProc = CurrentNode - 1;
                    }
                    if (CurrentNode != (DAVectorUtility.MPI_Size - 1))
                    {
                        DestProc = CurrentNode + 1;
                    }
                    else
                    {
                        LocalTotal = 0;
                    }
                    MPITransportComponentPacket SendBuffer = new MPITransportComponentPacket(LocalTotal, NumberofDoubleComponents, NumberofIntegerComponents); // Sent Buffer is EXACT size
                    NumberClustertoSend = 0;
                    NumberDoubletoSend  = 0;
                    NumberIntegertoSend = 0;

                    if (LocalTotal > 0)
                    {     // If no data here, just send dummy packet
                        if (Initialstep)
                        { // Construct message to send from Initial Arrays
                            for (int ClusterSendPointer = 0; ClusterSendPointer < InitialArraySize; ClusterSendPointer++)
                            {
                                int PackedHost = InitialHostSpecification[ClusterSendPointer];
                                if (HostRangeProcessing)
                                {
                                    int H2 = PackedHost >> (2 * ClusteringSolution.PACKINGSHIFT);
                                    if (H2 <= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    int H = PackedHost & ClusteringSolution.PACKINGMASK;
                                    if (H <= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                SendBuffer.AssociatedCreatedIndex[NumberClustertoSend] = InitialCreatedIndex[ClusterSendPointer];
                                SendBuffer.ClusterHostRange[NumberClustertoSend]       = InitialHostSpecification[ClusterSendPointer];
                                if (NumberofDoubleComponents > 0)
                                {
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofDoubleComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterDoubleComponents[NumberDoubletoSend] = InitialDoubleComponents[ClusterSendPointer][ComponentIndex];
                                        ++NumberDoubletoSend;
                                    }
                                }
                                if (NumberofIntegerComponents > 0)
                                {
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofIntegerComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterIntegerComponents[NumberIntegertoSend] = InitialIntegerComponents[ClusterSendPointer][ComponentIndex];
                                        ++NumberIntegertoSend;
                                    }
                                }
                                ++NumberClustertoSend;
                                if (NumberClustertoSend >= LocalTotal)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {   // Construct message to send from en passant data
                            for (int ReceivedClusterIndex = 0; ReceivedClusterIndex < ReceivedTotal; ReceivedClusterIndex++)
                            {
                                int PackedHost = TransportComponent.ClusterHostRange[ReceivedClusterIndex];
                                if (HostRangeProcessing)
                                {
                                    int H2 = PackedHost >> (2 * ClusteringSolution.PACKINGSHIFT);
                                    if (H2 <= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    int H = PackedHost & ClusteringSolution.PACKINGMASK;
                                    if (H <= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                SendBuffer.AssociatedCreatedIndex[NumberClustertoSend] = TransportComponent.AssociatedCreatedIndex[ReceivedClusterIndex];
                                SendBuffer.ClusterHostRange[NumberClustertoSend]       = TransportComponent.ClusterHostRange[ReceivedClusterIndex];
                                if (NumberofDoubleComponents > 0)
                                {
                                    int OverallIndex = NumberofDoubleComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofDoubleComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterDoubleComponents[NumberDoubletoSend] = TransportComponent.ClusterDoubleComponents[OverallIndex];
                                        ++NumberDoubletoSend;
                                        ++OverallIndex;
                                    }
                                }
                                if (NumberofIntegerComponents > 0)
                                {
                                    int OverallIndex = NumberofIntegerComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofIntegerComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterIntegerComponents[NumberIntegertoSend] = TransportComponent.ClusterIntegerComponents[OverallIndex];
                                        ++NumberIntegertoSend;
                                        ++OverallIndex;
                                    }
                                }
                                ++NumberClustertoSend;
                                if (NumberClustertoSend >= LocalTotal)
                                {
                                    break;
                                }
                            }
                        }
                    }   // End Case where there is Local Data to Send

                    // Send data in a pipeline forward
                    DAVectorUtility.StartSubTimer(DAVectorUtility.MPISENDRECEIVETiming);
                    DAVectorUtility.MPI_communicator.SendReceive <MPITransportComponentPacket>(SendBuffer, DestProc, DestTag, SourceProc, SourceTag,
                                                                                               out TransportComponent, out DistributedClusteringSolution.MPISecStatus);
                    DAVectorUtility.StopSubTimer(DAVectorUtility.MPISENDRECEIVETiming);

                    ++Program.NumberPipelineSteps;
                    Program.NumberofPipelineClusters += SendBuffer.NumberofClusters;

                    //  Examine Data passed from lower ranked processor
                    //  Set new LocalTotal and Store Data
                    ReceivedTotal = TransportComponent.NumberofClusters;
                    Program.ActualMaxMPITransportBuffer = Math.Max(Program.ActualMaxMPITransportBuffer, ReceivedTotal);
                    LocalTotal = 0; // Count Number of Clusters on next step

                    if (NumberofDoubleComponents != TransportComponent.NumberofDoubleComponents)
                    {
                        Exception e = DAVectorUtility.SALSAError(" Double Components Inconsistent " + NumberofDoubleComponents.ToString() + " " + TransportComponent.NumberofDoubleComponents.ToString()
                                                                 + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad");
                        throw (e);
                    }
                    if (NumberofIntegerComponents != TransportComponent.NumberofIntegerComponents)
                    {
                        Exception e = DAVectorUtility.SALSAError(" Integer Components Inconsistent " + NumberofIntegerComponents.ToString() + " " + TransportComponent.NumberofIntegerComponents.ToString()
                                                                 + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad");
                        throw (e);
                    }

                    if (ReceivedTotal > 0)
                    {
                        for (int ReceivedClusterIndex = 0; ReceivedClusterIndex < ReceivedTotal; ReceivedClusterIndex++)
                        {
                            int PackedHost = TransportComponent.ClusterHostRange[ReceivedClusterIndex];
                            if (HostRangeProcessing)
                            {
                                int H2 = PackedHost >> (2 * ClusteringSolution.PACKINGSHIFT);
                                if (H2 < DAVectorUtility.MPI_Rank)
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported host " + PackedHost.ToString() + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad Up Range");
                                    throw (e);
                                }
                                if (H2 > DAVectorUtility.MPI_Rank)
                                {
                                    ++LocalTotal;
                                }
                            }
                            else
                            {
                                int H = PackedHost & ClusteringSolution.PACKINGMASK;
                                if (H < DAVectorUtility.MPI_Rank)
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported host " + PackedHost.ToString() + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad Up Host");
                                    throw (e);
                                }
                                if (H > DAVectorUtility.MPI_Rank)
                                {
                                    ++LocalTotal;
                                    continue;
                                }
                            }
                            int host         = PackedHost & ClusteringSolution.PACKINGMASK;
                            int CreatedIndex = TransportComponent.AssociatedCreatedIndex[ReceivedClusterIndex];
                            if (UpdateMode < 2)
                            {
                                FinalDataLocationIndex = -1;
                                IsItOK = DistributedClusteringSolution.IndicesperCluster(CreatedIndex, -1, ref NodeStoragePosition, ref TransportedStoragePosition,
                                                                                         ref NodeAccumulationPosition, ref ThreadAccumulationPosition);
                                if (StorageMode == 1)
                                {
                                    FinalDataLocationIndex = NodeStoragePosition;
                                }
                                if (StorageMode == 2)
                                {
                                    FinalDataLocationIndex = TransportedStoragePosition;
                                }
                                if (StorageMode == 3)
                                {
                                    FinalDataLocationIndex = NodeAccumulationPosition;
                                }
                                if ((host == DAVectorUtility.MPI_Rank) && (IsItOK != 0))
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported Created Index " + CreatedIndex.ToString() + " in Rank "
                                                                             + DAVectorUtility.MPI_Rank.ToString() + " Bad with code " + IsItOK.ToString() + " host " + host.ToString() + " Update mode " + UpdateMode.ToString());
                                    throw (e);
                                }
                            }
                            else
                            {   // UpdateMode 2
                                IsItOK = 0;
                                FinalDataLocationIndex = FinalClusterCount;
                                ++FinalClusterCount;
                                FinalCreatedIndex[FinalDataLocationIndex]      = CreatedIndex;
                                FinalHostSpecification[FinalDataLocationIndex] = PackedHost;
                            }
                            if (IsItOK >= 0)
                            {
                                if (FinalDataLocationIndex == -1)
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported Created Index " + CreatedIndex.ToString() + " in Rank "
                                                                             + DAVectorUtility.MPI_Rank.ToString() + " Bad with Storage Mode " + StorageMode.ToString() + " host " + host.ToString() + " Update mode " + UpdateMode.ToString());
                                    throw (e);
                                }

                                if (NumberofDoubleComponents > 0)
                                {
                                    string message            = "";
                                    int    OverallDoubleIndex = NumberofDoubleComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofDoubleComponents; ComponentIndex++)
                                    {
                                        if ((UpdateMode == 0) || (UpdateMode == 2))
                                        {
                                            FinalDoubleComponents[FinalDataLocationIndex][ComponentIndex] = TransportComponent.ClusterDoubleComponents[OverallDoubleIndex];
                                        }
                                        if (UpdateMode == 1)
                                        {
                                            FinalDoubleComponents[FinalDataLocationIndex][ComponentIndex] += TransportComponent.ClusterDoubleComponents[OverallDoubleIndex];
                                        }
                                        message += " * " + TransportComponent.ClusterDoubleComponents[OverallDoubleIndex].ToString("E3") + " " + FinalDoubleComponents[FinalDataLocationIndex][ComponentIndex].ToString("F3");
                                        ++OverallDoubleIndex;
                                    }

                                    /* if (CreatedIndex == 901)
                                     *  DAVectorUtility.SALSAFullPrint(1, "Up901 Transport " + UpdateMode.ToString() + " " + FinalDataLocationIndex.ToString()  + message); */
                                }

                                if (NumberofIntegerComponents > 0)
                                {
                                    int OverallIntegerIndex = NumberofIntegerComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofIntegerComponents; ComponentIndex++)
                                    {
                                        if ((UpdateMode == 0) || (UpdateMode == 2))
                                        {
                                            FinalIntegerComponents[FinalDataLocationIndex][ComponentIndex] = TransportComponent.ClusterIntegerComponents[OverallIntegerIndex];
                                        }
                                        if (UpdateMode == 1)
                                        {
                                            FinalIntegerComponents[FinalDataLocationIndex][ComponentIndex] += TransportComponent.ClusterIntegerComponents[OverallIntegerIndex];
                                        }
                                        ++OverallIntegerIndex;
                                    }
                                }
                            } // End case where location found IsItOK >= 0
                        }     // end Loop over ReceivedClusterIndex
                    }         // End case where ReceivedTotal > 0
                    Initialstep = false;
                }             // End While over MPI pipeline steps for pipeline going UP the chain

                // Process Clusters going Down the Chain
                Initialstep = true;
                int StepsDown = 0;

                LocalTotal = DownbySteps[1];

                while (true)
                {
                    StepsDown++;
                    if (StepsDown >= DAVectorUtility.MPI_Size)
                    {
                        break;
                    }
                    int JobTotal = DownbyStepsTotal[StepsDown];
                    if (JobTotal == 0)
                    {
                        break;
                    }

                    // Some Nodes want to go down the line
                    int SourceProc = MPI.Intercommunicator.Null;
                    int DestProc   = MPI.Intercommunicator.Null;
                    DestProc   = DAVectorUtility.MPI_Size - 1;
                    SourceProc = 0;
                    int SourceTag = 22; // Random Number
                    int DestTag   = 22;
                    if (CurrentNode != 0)
                    {
                        DestProc = CurrentNode - 1;
                    }
                    else
                    {
                        LocalTotal = 0;
                    }
                    if (CurrentNode != (DAVectorUtility.MPI_Size - 1))
                    {
                        SourceProc = CurrentNode + 1;
                    }
                    MPITransportComponentPacket SendBuffer = new MPITransportComponentPacket(LocalTotal, NumberofDoubleComponents, NumberofIntegerComponents); // Sent Buffer is EXACT size
                    NumberClustertoSend = 0;
                    NumberDoubletoSend  = 0;
                    NumberIntegertoSend = 0;

                    if (LocalTotal > 0)
                    {     // If no data here, just send dummy packet
                        if (Initialstep)
                        { // Construct message to send from local accumulation arrays
                            for (int ClusterIndirectIndex = 0; ClusterIndirectIndex < InitialArraySize; ClusterIndirectIndex++)
                            {
                                int PackedHost = InitialHostSpecification[ClusterIndirectIndex];
                                if (HostRangeProcessing)
                                {
                                    int H1 = (PackedHost >> ClusteringSolution.PACKINGSHIFT) & ClusteringSolution.PACKINGMASK;
                                    if (H1 >= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    int H = PackedHost & ClusteringSolution.PACKINGMASK;
                                    if (H >= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                SendBuffer.AssociatedCreatedIndex[NumberClustertoSend] = InitialCreatedIndex[ClusterIndirectIndex];
                                SendBuffer.ClusterHostRange[NumberClustertoSend]       = InitialHostSpecification[ClusterIndirectIndex];
                                if (NumberofDoubleComponents > 0)
                                {
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofDoubleComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterDoubleComponents[NumberDoubletoSend] = InitialDoubleComponents[ClusterIndirectIndex][ComponentIndex];
                                        ++NumberDoubletoSend;
                                    }
                                }
                                if (NumberofIntegerComponents > 0)
                                {
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofIntegerComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterIntegerComponents[NumberIntegertoSend] = InitialIntegerComponents[ClusterIndirectIndex][ComponentIndex];
                                        ++NumberIntegertoSend;
                                    }
                                }
                                ++NumberClustertoSend;
                                if (NumberClustertoSend >= LocalTotal)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {   // Construct message to send from en passant data
                            for (int ReceivedClusterIndex = 0; ReceivedClusterIndex < ReceivedTotal; ReceivedClusterIndex++)
                            {
                                int PackedHost = TransportComponent.ClusterHostRange[ReceivedClusterIndex];
                                if (HostRangeProcessing)
                                {
                                    int H1 = (PackedHost >> ClusteringSolution.PACKINGSHIFT) & ClusteringSolution.PACKINGMASK;
                                    if (H1 >= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    int H = PackedHost & ClusteringSolution.PACKINGMASK;
                                    if (H >= DAVectorUtility.MPI_Rank)
                                    {
                                        continue;
                                    }
                                }
                                SendBuffer.AssociatedCreatedIndex[NumberClustertoSend] = TransportComponent.AssociatedCreatedIndex[ReceivedClusterIndex];
                                SendBuffer.ClusterHostRange[NumberClustertoSend]       = TransportComponent.ClusterHostRange[ReceivedClusterIndex];
                                if (NumberofDoubleComponents > 0)
                                {
                                    int OverallIndex = NumberofDoubleComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofDoubleComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterDoubleComponents[NumberDoubletoSend] = TransportComponent.ClusterDoubleComponents[OverallIndex];
                                        ++NumberDoubletoSend;
                                        ++OverallIndex;
                                    }
                                }
                                if (NumberofIntegerComponents > 0)
                                {
                                    int OverallIndex = NumberofIntegerComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofIntegerComponents; ComponentIndex++)
                                    {
                                        SendBuffer.ClusterIntegerComponents[NumberIntegertoSend] = TransportComponent.ClusterIntegerComponents[OverallIndex];
                                        ++NumberIntegertoSend;
                                        ++OverallIndex;
                                    }
                                }
                                ++NumberClustertoSend;
                                if (NumberClustertoSend >= LocalTotal)
                                {
                                    break;
                                }
                            }
                        } // end en passant data is source of information
                    }     // End Case where there is Local Data to Send

                    // Send data in a pipeline backwards
                    DAVectorUtility.StartSubTimer(DAVectorUtility.MPISENDRECEIVETiming);
                    DAVectorUtility.MPI_communicator.SendReceive <MPITransportComponentPacket>(SendBuffer, DestProc, DestTag, SourceProc, SourceTag, out TransportComponent, out DistributedClusteringSolution.MPISecStatus);;
                    DAVectorUtility.StopSubTimer(DAVectorUtility.MPISENDRECEIVETiming);
                    ++Program.NumberPipelineSteps;
                    Program.NumberofPipelineClusters += SendBuffer.NumberofClusters;

                    //  Examine Data passed from higher ranked processor
                    ReceivedTotal = TransportComponent.NumberofClusters;
                    Program.ActualMaxMPITransportBuffer = Math.Max(Program.ActualMaxMPITransportBuffer, ReceivedTotal);
                    LocalTotal = 0;

                    if (NumberofDoubleComponents != TransportComponent.NumberofDoubleComponents)
                    {
                        Exception e = DAVectorUtility.SALSAError(" Double Components Inconsistent " + NumberofDoubleComponents.ToString() + " " + TransportComponent.NumberofDoubleComponents.ToString()
                                                                 + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad");
                        throw (e);
                    }
                    if (NumberofIntegerComponents != TransportComponent.NumberofIntegerComponents)
                    {
                        Exception e = DAVectorUtility.SALSAError(" Integer Components Inconsistent " + NumberofIntegerComponents.ToString() + " " + TransportComponent.NumberofIntegerComponents.ToString()
                                                                 + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad");
                        throw (e);
                    }

                    if (ReceivedTotal > 0)
                    {
                        for (int ReceivedClusterIndex = 0; ReceivedClusterIndex < ReceivedTotal; ReceivedClusterIndex++)
                        {
                            int PackedHost = TransportComponent.ClusterHostRange[ReceivedClusterIndex];
                            if (HostRangeProcessing)
                            {
                                int H1 = (PackedHost >> ClusteringSolution.PACKINGSHIFT) & ClusteringSolution.PACKINGMASK;
                                if (H1 > DAVectorUtility.MPI_Rank)
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported host " + PackedHost.ToString() + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad Down Range");
                                    throw (e);
                                }
                                if (H1 < DAVectorUtility.MPI_Rank)
                                {
                                    ++LocalTotal;
                                }
                            }
                            else
                            {
                                int H = PackedHost & ClusteringSolution.PACKINGMASK;
                                if (H > DAVectorUtility.MPI_Rank)
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported host " + PackedHost.ToString() + " in Rank " + DAVectorUtility.MPI_Rank.ToString() + " Bad Down Not Range");
                                    throw (e);
                                }
                                if (H < DAVectorUtility.MPI_Rank)
                                {
                                    ++LocalTotal;
                                    continue;
                                }
                            }
                            int host         = PackedHost & ClusteringSolution.PACKINGMASK;
                            int CreatedIndex = TransportComponent.AssociatedCreatedIndex[ReceivedClusterIndex];
                            if (UpdateMode < 2)
                            {
                                FinalDataLocationIndex = -1;
                                IsItOK = DistributedClusteringSolution.IndicesperCluster(CreatedIndex, -1, ref NodeStoragePosition, ref TransportedStoragePosition,
                                                                                         ref NodeAccumulationPosition, ref ThreadAccumulationPosition);
                                if (StorageMode == 1)
                                {
                                    FinalDataLocationIndex = NodeStoragePosition;
                                }
                                if (StorageMode == 2)
                                {
                                    FinalDataLocationIndex = TransportedStoragePosition;
                                }
                                if (StorageMode == 3)
                                {
                                    FinalDataLocationIndex = NodeAccumulationPosition;
                                }
                                if ((host == DAVectorUtility.MPI_Rank) && (IsItOK != 0))
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported Created Index " + CreatedIndex.ToString() + " in Rank "
                                                                             + DAVectorUtility.MPI_Rank.ToString() + " Bad with code " + IsItOK.ToString() + " host " + host.ToString() + " Update mode " + UpdateMode.ToString());
                                    throw (e);
                                }
                            }
                            else
                            {
                                IsItOK = 0;
                                FinalDataLocationIndex = FinalClusterCount;
                                ++FinalClusterCount;
                                FinalCreatedIndex[FinalDataLocationIndex]      = CreatedIndex;
                                FinalHostSpecification[FinalDataLocationIndex] = PackedHost;
                            }
                            if (IsItOK >= 0)
                            {
                                if (FinalDataLocationIndex == -1)
                                {
                                    Exception e = DAVectorUtility.SALSAError(" Transported Created Index " + CreatedIndex.ToString() + " in Rank "
                                                                             + DAVectorUtility.MPI_Rank.ToString() + " Bad with Storage Mode " + StorageMode.ToString() + " host " + host.ToString() + " Update mode " + UpdateMode.ToString());
                                    throw (e);
                                }

                                if (NumberofDoubleComponents > 0)
                                {
                                    string message            = "";
                                    int    OverallDoubleIndex = NumberofDoubleComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofDoubleComponents; ComponentIndex++)
                                    {
                                        if ((UpdateMode == 0) || (UpdateMode == 2))
                                        {
                                            FinalDoubleComponents[FinalDataLocationIndex][ComponentIndex] = TransportComponent.ClusterDoubleComponents[OverallDoubleIndex];
                                        }
                                        if (UpdateMode == 1)
                                        {
                                            FinalDoubleComponents[FinalDataLocationIndex][ComponentIndex] += TransportComponent.ClusterDoubleComponents[OverallDoubleIndex];
                                        }
                                        message += " * " + TransportComponent.ClusterDoubleComponents[OverallDoubleIndex].ToString("E3") + " " + FinalDoubleComponents[FinalDataLocationIndex][ComponentIndex].ToString("F3");
                                        ++OverallDoubleIndex;
                                    }

                                    /* if (CreatedIndex == 901)
                                     *  DAVectorUtility.SALSAFullPrint(1, "Dn901 Transport " + UpdateMode.ToString() + " " + FinalDataLocationIndex.ToString() + message); */
                                }

                                if (NumberofIntegerComponents > 0)
                                {
                                    int OverallIntegerIndex = NumberofIntegerComponents * ReceivedClusterIndex;
                                    for (int ComponentIndex = 0; ComponentIndex < NumberofIntegerComponents; ComponentIndex++)
                                    {
                                        if ((UpdateMode == 0) || (UpdateMode == 2))
                                        {
                                            FinalIntegerComponents[FinalDataLocationIndex][ComponentIndex] = TransportComponent.ClusterIntegerComponents[OverallIntegerIndex];
                                        }
                                        if (UpdateMode == 1)
                                        {
                                            FinalIntegerComponents[FinalDataLocationIndex][ComponentIndex] += TransportComponent.ClusterIntegerComponents[OverallIntegerIndex];
                                        }
                                        ++OverallIntegerIndex;
                                    }
                                }
                            }
                        } // End Loop over Received Clusters
                    }     // End case when data received ReceivedTotal > 0

                    Initialstep = false;
                } // End While over MPI pipeline steps going DOWN the chain
            }     // End PipelineDistributedBroadcast
Esempio n. 3
0
        }   // End ReadDataFromFile

        public static void Read3DDataFromFile(string fname, int VectorSize, int StartPointPosition)
        {
            char[] _sep = new[] { ' ', ',', '\t' };

            int FirstPointPosition      = 0;
            int TotalNumberPointstoRead = 0;

            TotalNumberPointstoRead = DAVectorUtility.PointCount_Global;

            int MinSplitSize = StartPointPosition + VectorSize;

            bool   success          = false;
            string line             = " Unset";
            int    CountLinesinFile = 0;

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep);
                            if (splits.Length < MinSplitSize)
                            {
                                DAVectorUtility.SALSAPrint(0, "Count " + CountLinesinFile.ToString() + " Illegal data length on Point file " + splits.Length.ToString()
                                                           + " " + MinSplitSize.ToString() + " " + line);
                                continue;
                            }   // Skip header lines
                            double junk;
                            if (!Double.TryParse(splits[StartPointPosition], out junk))
                            {
                                continue;   // Skip header lines
                            }
                            if (CountLinesinFile < FirstPointPosition)
                            {
                                CountLinesinFile += 1;
                                continue;
                            }

                            int ActualPointPosition = CountLinesinFile - FirstPointPosition;
                            if (StartPointPosition >= 0)
                            {
                                Program.FullPoint3DPosition[ActualPointPosition][0] = double.Parse(splits[StartPointPosition]);
                                Program.FullPoint3DPosition[ActualPointPosition][1] = double.Parse(splits[StartPointPosition + 1]);
                                if (VectorSize > 2)
                                {
                                    for (int VectorIndex = 2; VectorIndex < VectorSize; VectorIndex++)
                                    {
                                        Program.FullPoint3DPosition[ActualPointPosition][VectorIndex] = double.Parse(splits[VectorIndex + StartPointPosition]);
                                    }
                                }
                            }

                            ++ActualPointPosition;
                            ++CountLinesinFile;
                            if (CountLinesinFile >= (FirstPointPosition + TotalNumberPointstoRead))
                            {
                                break;
                            }
                        }
                    }
                    if (CountLinesinFile != (FirstPointPosition + TotalNumberPointstoRead))
                    {
                        Exception e = DAVectorUtility.SALSAError("Illegal count on Points file " + fname + " Rank " + DAVectorUtility.MPI_Rank.ToString()
                                                                 + " Lines in File " + CountLinesinFile.ToString() + " Number to Read " + TotalNumberPointstoRead.ToString());
                        throw (e);
                    }
                    success = true;
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed reading Points data " + DAVectorUtility.MPI_Rank.ToString() + " " + CountLinesinFile.ToString() + " Start "
                                  + FirstPointPosition.ToString() + " Number " + TotalNumberPointstoRead.ToString() + " " + line + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File read error " + fname);
                throw (e);
            }
        } // End Read3DDataFromFile
Esempio n. 4
0
        }   // End ReadDataFromFile

        public static void ReadDataFromFile(string fname, int ClusterPosition, int[] InitialPointAssignment, int StartPointPosition)
        {
            char[] _sep = new[] { ' ', ',', '\t' };

            int FirstPointPosition      = 0;
            int TotalNumberPointstoRead = 0;

            FirstPointPosition      = DAVectorUtility.PointStart_Process;
            TotalNumberPointstoRead = DAVectorUtility.PointCount_Process;

            int MinSplitSize = ClusterPosition + 1;

            if (StartPointPosition >= 0)
            {
                MinSplitSize = Math.Max(MinSplitSize, StartPointPosition + Program.ParameterVectorDimension);
            }

            bool   success          = false;
            string line             = " Unset";
            int    CountLinesinFile = 0;
            string stringtest       = "";

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep, StringSplitOptions.RemoveEmptyEntries);
                            if (splits.Length < MinSplitSize)
                            {
                                DAVectorUtility.SALSAPrint(0, "Count " + CountLinesinFile.ToString() + " Illegal data length on Point file " + splits.Length.ToString()
                                                           + " " + MinSplitSize.ToString() + " " + line);
                                continue;
                            }   // Skip header lines
                            double junk;
                            if (!Double.TryParse(splits[StartPointPosition], out junk))
                            {
                                continue;   // Skip header lines
                            }
                            if (CountLinesinFile < FirstPointPosition)
                            {
                                CountLinesinFile += 1;
                                continue;
                            }

                            int ActualPointPosition = CountLinesinFile - FirstPointPosition;
                            int label = 0;
                            if (StartPointPosition >= 0)
                            {
                                stringtest = "0 *" + splits[StartPointPosition];
                                Program.PointPosition[ActualPointPosition][0] = double.Parse(splits[StartPointPosition]);
                                stringtest = "1 *" + splits[StartPointPosition + 1];
                                Program.PointPosition[ActualPointPosition][1] = double.Parse(splits[StartPointPosition + 1]);
                                if (Program.ParameterVectorDimension > 2)
                                {
                                    for (int VectorIndex = 2; VectorIndex < Program.ParameterVectorDimension; VectorIndex++)
                                    {
                                        stringtest = VectorIndex.ToString() + " *" + splits[StartPointPosition + VectorIndex];
                                        Program.PointPosition[ActualPointPosition][VectorIndex] = double.Parse(splits[VectorIndex + StartPointPosition]);
                                    }
                                }
                            }
                            if (ClusterPosition >= 0)
                            {
                                if (!Int32.TryParse(splits[ClusterPosition], out label))
                                {
                                    label = 1;
                                }
                                InitialPointAssignment[ActualPointPosition] = label - 1;
                            }

                            ++ActualPointPosition;
                            ++CountLinesinFile;
                            if (CountLinesinFile >= (FirstPointPosition + TotalNumberPointstoRead))
                            {
                                break;
                            }
                        }
                    }
                    if (CountLinesinFile != (FirstPointPosition + TotalNumberPointstoRead))
                    {
                        Exception e = DAVectorUtility.SALSAError("Illegal count on Points file " + fname + " Rank " + DAVectorUtility.MPI_Rank.ToString()
                                                                 + " Lines in File " + CountLinesinFile.ToString() + " Number to Read " + TotalNumberPointstoRead.ToString());
                        throw (e);
                    }
                    success = true;
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(stringtest + "* Failed reading Points data " + DAVectorUtility.MPI_Rank.ToString() + " " + CountLinesinFile.ToString() + " Start "
                                  + FirstPointPosition.ToString() + " Number " + TotalNumberPointstoRead.ToString() + " " + line + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File read error " + fname);
                throw (e);
            }
        }   // End ReadDataFromFile
Esempio n. 5
0
        }   // End AnalyzeDataFromFile

        //  Readvectors = 0 Normal
        //  Readvectors = 1 Read points changing cluster labels
        //  Readvectors = 2 Read Cluster Centers
        public static void ReadDataFromFile(string fname, int ReadVectorsOption)
        {
            char[] _sep = new[] { ' ', '\t' };

            int FirstPointPosition      = 0;
            int TotalNumberPointstoRead = 0;

            if (ReadVectorsOption <= 1)
            {
                FirstPointPosition      = DAVectorUtility.PointStart_Process;
                TotalNumberPointstoRead = DAVectorUtility.PointCount_Process;
            }
            int BeginLabel = 0;

            if (ReadVectorsOption == 1)
            {
                BeginLabel = ParallelClustering.RunningSolution.Ncent_Global - 1;
            }

            int MinSplitSize  = Program.ParameterVectorDimension + 3;
            int SplitPosition = 1 + Program.ParameterVectorDimension;
            int LabelPosition = 4 + Program.ParameterVectorDimension;

            if (Program.InputFileType == 1)
            {
                MinSplitSize  = 5;
                SplitPosition = 4;
                LabelPosition = 4;
            }

            bool   success                = false;
            string line                   = " Unset";
            int    CountLinesinFile       = 0;
            int    CurrentLocalPointtoUse = 0;

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep);
                            if (splits.Length < MinSplitSize)
                            {
                                Exception e = DAVectorUtility.SALSAError("Count " + CountLinesinFile.ToString() + "Illegal data length on Point file " + splits.Length.ToString()
                                                                         + " " + MinSplitSize.ToString() + " " + line);
                                throw (e);
                            }
                            int Charge = -101;
                            if (!Int32.TryParse(splits[SplitPosition], out Charge))
                            {
                                continue;
                            }
                            if (Program.SelectedInputLabel >= 0)
                            {
                                if (Charge != Program.SelectedInputLabel)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (ReadVectorsOption >= 2)
                                {
                                    if (Charge != -Program.SelectedInputLabel)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (Charge == -Program.SelectedInputLabel)
                                    {
                                        continue;
                                    }
                                }
                            }
                            if ((ReadVectorsOption <= 0) && (CountLinesinFile < FirstPointPosition))
                            {
                                CountLinesinFile += Program.Replicate;
                                continue;
                            }

                            int ActualPointPosition = 0;
                            if (ReadVectorsOption == 0)
                            {
                                ActualPointPosition = CountLinesinFile - FirstPointPosition;
                            }

                            else if (ReadVectorsOption == 1)
                            {
                                double CurrentLineY0 = double.Parse(splits[1]);
                                bool   enditall      = false;
                                bool   endinputline  = false;
                                while (true)
                                {
                                    if (CurrentLocalPointtoUse >= TotalNumberPointstoRead)
                                    {
                                        enditall = true;
                                        break;
                                    }
                                    double CurrentPointY0 = Program.PointPosition[CurrentLocalPointtoUse][0];
                                    if (CurrentLineY0 < (CurrentPointY0 - 0.000001))
                                    {
                                        endinputline = true;
                                        break;
                                    }
                                    if (CurrentLineY0 > (CurrentPointY0 + 0.000001))
                                    {
                                        ++CurrentLocalPointtoUse;
                                        continue;
                                    }
                                    else
                                    {
                                        if (Math.Abs(Program.PointPosition[CurrentLocalPointtoUse][1] - double.Parse(splits[2])) > 0.00001)
                                        {
                                            ++CurrentLocalPointtoUse;
                                            continue;
                                        }
                                        if (Program.PointLabel[CurrentLocalPointtoUse] != 0)
                                        {
                                            Exception e = DAVectorUtility.SALSAError(fname + " Position " + (CurrentLocalPointtoUse + FirstPointPosition).ToString()
                                                                                     + " Inconsistent Cluster Number " + Program.PointLabel[CurrentLocalPointtoUse].ToString()
                                                                                     + " Y0 " + Program.PointPosition[CurrentLocalPointtoUse][0].ToString("F5") + " " + line);
                                            throw (e);
                                        }
                                        ActualPointPosition = CurrentLocalPointtoUse;
                                        ++CurrentLocalPointtoUse;
                                        break;
                                    }
                                }
                                if (endinputline)
                                {
                                    continue;
                                }
                                if (enditall)
                                {
                                    break;
                                }
                            }
                            for (int CountReplicas = 0; CountReplicas < Program.Replicate; CountReplicas++)
                            {
                                double label;
                                if (ReadVectorsOption >= 2)
                                {
                                    ParallelClustering.RunningSolution.Y_k_i_[ParallelClustering.RunningSolution.Ncent_Global][0] = double.Parse(splits[1]);
                                    ParallelClustering.RunningSolution.Y_k_i_[ParallelClustering.RunningSolution.Ncent_Global][1] = double.Parse(splits[2]);
                                    if (Program.ParameterVectorDimension > 2)
                                    {
                                        for (int VectorIndex = 2; VectorIndex < Program.ParameterVectorDimension; VectorIndex++)
                                        {
                                            ParallelClustering.RunningSolution.Y_k_i_[ParallelClustering.RunningSolution.Ncent_Global][VectorIndex] = double.Parse(splits[VectorIndex + 1]);
                                        }
                                    }
                                    ++ParallelClustering.RunningSolution.Ncent_Global;
                                }
                                else
                                {
                                    if (ReadVectorsOption == 0)
                                    {
                                        Program.PointPosition[ActualPointPosition][0]   = double.Parse(splits[1]);
                                        Program.PointPosition[ActualPointPosition][1]   = double.Parse(splits[2]);
                                        Program.PointOriginalIndex[ActualPointPosition] = int.Parse(splits[0]);
                                        if (Program.ParameterVectorDimension > 2)
                                        {
                                            for (int VectorIndex = 2; VectorIndex < Program.ParameterVectorDimension; VectorIndex++)
                                            {
                                                Program.PointPosition[ActualPointPosition][VectorIndex] = double.Parse(splits[VectorIndex + 1]);
                                            }
                                        }
                                    }
                                    if (!Double.TryParse(splits[LabelPosition], out label))
                                    {
                                        label = 0.0;
                                    }
                                    Program.PointLabel[ActualPointPosition] = (int)(label + 0.001);
                                    if (Program.PointLabel[ActualPointPosition] != 0)
                                    {
                                        Program.PointLabel[ActualPointPosition] += BeginLabel;
                                    }
                                }
                                ++ActualPointPosition;
                            }
                            CountLinesinFile += Program.Replicate;
                            if ((ReadVectorsOption <= 0) && (CountLinesinFile >= (FirstPointPosition + TotalNumberPointstoRead)))
                            {
                                break;
                            }
                        }
                    }
                    if ((ReadVectorsOption <= 0) && (CountLinesinFile != (FirstPointPosition + TotalNumberPointstoRead)))
                    {
                        Exception e = DAVectorUtility.SALSAError("Illegal count on Points file " + fname + " Rank " + DAVectorUtility.MPI_Rank.ToString()
                                                                 + " Lines in File " + CountLinesinFile.ToString() + " Number to Read " + TotalNumberPointstoRead.ToString());
                        throw (e);
                    }
                    success = true;
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed reading Points data " + DAVectorUtility.MPI_Rank.ToString() + " " + CountLinesinFile.ToString() + " Start "
                                  + FirstPointPosition.ToString() + " Number " + TotalNumberPointstoRead.ToString() + " " + line + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File read error " + fname);
                throw (e);
            }
        }   // End ReadDataFromFile
Esempio n. 6
0
        }   // End ReadLabelsFromFile

        // read point data from file to memory
        // OutputFileType = 0 Harvard Format Cosmic Index mz RT Charge Peptide Peptide.id Mclust Medea
        // OutputFileType = 1 Ingest output file:   Index mz RT  0.0 Cluster#
        public static void AnalyzeDataFromFile(string fname)
        {
            char[] _sep      = new[] { ' ', '\t' };
            int    Maxcounts = 200;

            int[] CountLabels = new int[Maxcounts];
            for (int ChargeIndex = 0; ChargeIndex < Maxcounts; ChargeIndex++)
            {
                CountLabels[ChargeIndex] = 0;
            }
            int MinSplitSize  = Program.ParameterVectorDimension + 3;
            int SplitPosition = 1 + Program.ParameterVectorDimension;

            if (Program.InputFileType == 1)
            {
                MinSplitSize  = 5;
                SplitPosition = 4;
            }
            bool success = false;
            int  count   = 0;

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    string line;
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep);
                            if (splits.Length < MinSplitSize)
                            {
                                Exception e = DAVectorUtility.SALSAError("Count " + count.ToString() + "Illegal data length on Point file " + splits.Length.ToString()
                                                                         + " " + MinSplitSize.ToString() + " " + line);
                                throw (e);
                            }
                            int Charge = -101;
                            if (!Int32.TryParse(splits[SplitPosition], out Charge))
                            {
                                continue;
                            }
                            if ((Program.SelectedInputLabel < 0) && (Charge == -Program.SelectedInputLabel))
                            {
                                continue;
                            }
                            int position = 1 + Charge;
                            position = Math.Max(0, position);
                            position = Math.Min(Maxcounts - 1, position);
                            ++CountLabels[position];
                            count++;
                        }
                    }
                    success = true;
                    if (Program.SelectedInputLabel >= 0)
                    {
                        DAVectorUtility.PointCount_Global = CountLabels[1 + Program.SelectedInputLabel];
                    }
                    else
                    {
                        DAVectorUtility.PointCount_Global = 0;
                        for (int selection = 0; selection < Maxcounts; selection++)
                        {
                            DAVectorUtility.PointCount_Global += CountLabels[selection];
                        }
                    }
                    DAVectorUtility.SALSAPrint(1, "File Analyzed " + fname + " Total " + count.ToString());
                    string label = "Charge";
                    if (Program.InputFileType == 1)
                    {
                        label = "Cluster";
                    }
                    if (CountLabels[0] > 0)
                    {
                        DAVectorUtility.SALSAPrint(1, "Negative " + label + "s " + CountLabels[0].ToString());
                    }
                    for (int LabelIndex = 1; LabelIndex < (Maxcounts - 1); LabelIndex++)
                    {
                        if (CountLabels[LabelIndex] > 0)
                        {
                            DAVectorUtility.SALSAPrint(1, label + " " + (LabelIndex - 1).ToString() + " Count " + CountLabels[LabelIndex].ToString());
                        }
                    }
                    if (CountLabels[Maxcounts - 1] > 0)
                    {
                        DAVectorUtility.SALSAPrint(1, "Overflow " + label + "s " + CountLabels[Maxcounts - 1].ToString());
                    }
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed reading Points data" + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File Analyze error " + fname);
                throw (e);
            }
        }   // End AnalyzeDataFromFile
Esempio n. 7
0
        public static void ReadLabelsFromFile(string fname)
        {
            char[] _sep = new[] { ' ', '\t' };

            int MinSplitSize        = 8;
            int SplitPosition       = 3;
            int MedeaPosition       = 7;
            int GoldenIDPosition    = 5;
            int MclustPosition      = 6;
            int GoldenLabelPosition = 4;

            bool success = false;
            int  count   = 0;

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    string line;
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep);
                            if (splits.Length < MinSplitSize)
                            {
                                Exception e = DAVectorUtility.SALSAError("Count " + count.ToString() + "Illegal data length on Point file " + splits.Length.ToString()
                                                                         + " " + MinSplitSize.ToString() + " " + line);
                                throw (e);
                            }
                            int Charge = -101;
                            if (!Int32.TryParse(splits[SplitPosition], out Charge))
                            {
                                continue;
                            }
                            if (Charge != Program.SelectedInputLabel)
                            {
                                continue;
                            }
                            int OKinteger = -1;
                            if (!Int32.TryParse(splits[GoldenIDPosition], out OKinteger))
                            {
                                OKinteger = -1;
                            }
                            Program.GoldenPeaks.PointstoClusterIDs[count] = OKinteger;
                            GoldenExamination.GoldenID[count]             = OKinteger;
                            GoldenExamination.GoldenLabel[count]          = splits[GoldenLabelPosition];
                            GoldenExamination.PeakPosition[count][0]      = double.Parse(splits[1]);
                            GoldenExamination.PeakPosition[count][1]      = double.Parse(splits[2]);

                            OKinteger = 0;
                            if (!Int32.TryParse(splits[MclustPosition], out OKinteger))
                            {
                                double tryagain = 0.0;
                                if (!Double.TryParse(splits[MclustPosition], out tryagain))
                                {
                                    Exception e = DAVectorUtility.SALSAError("Count " + count.ToString() + "Illegal Mclust value on Point file " + splits.Length.ToString()
                                                                             + " " + line);
                                    throw (e);
                                }
                                OKinteger = (int)Math.Floor(tryagain + 0.001);
                            }
                            Program.MclustClusters.PointstoClusterIDs[count] = OKinteger;

                            OKinteger = 0;
                            if (!Int32.TryParse(splits[MedeaPosition], out OKinteger))
                            {
                                double tryagain = 0.0;
                                if (!Double.TryParse(splits[MedeaPosition], out tryagain))
                                {
                                    Exception e = DAVectorUtility.SALSAError("Count " + count.ToString() + "Illegal Medea value on Point file " + splits.Length.ToString()
                                                                             + " " + line);
                                    throw (e);
                                }
                                OKinteger = (int)Math.Floor(tryagain + 0.001);
                            }
                            Program.MedeaClusters.PointstoClusterIDs[count] = OKinteger;
                            count++;
                        }
                    }
                    success = true;
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed reading Points data" + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File Analyze error " + fname);
                throw (e);
            }
            Program.GoldenPeaks.setup();
            Program.MclustClusters.setup();
            Program.MedeaClusters.setup();
        }   // End ReadLabelsFromFile