public static void RunOnCluster(BaseController Controller)
        {
            if ((!(BaseActions.FileSave(Controller))))
            {
                return;
            }

            StatusStrip StatusBar = (StatusStrip)Controller.MainForm.Controls.Find("StatusStrip1", true)[0];

            ProgressBar       = (ToolStripProgressBar)StatusBar.Items[0];
            ProgressLabel     = (ToolStripStatusLabel)StatusBar.Items[1];
            StatusBar.Visible = true;

            try {
                UIBits.ClusterForm F = new UIBits.ClusterForm();
                if (F.ShowDialog() == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    F.SaveSettings();

                    List <string> FilesToRun = new List <string>();
                    if (F.runThisSimulation && !string.IsNullOrEmpty(Controller.ApsimData.FileName))
                    {
                        FilesToRun.Add(Controller.ApsimData.FileName);
                    }
                    else if (!F.runThisSimulation && !string.IsNullOrEmpty(F.FolderOfFiles))
                    {
                        Utility.FindFiles(F.FolderOfFiles, "*.apsim", ref FilesToRun);
                    }

                    if ((FilesToRun.Count > 0))
                    {
                        CondorJob c = new CondorJob();
                        c.NiceUser = F.NiceUser;
                        c.arch     = 0;
                        if (F.archIsUnix)
                        {
                            c.arch |= Configuration.architecture.unix;
                        }
                        if (F.archIsWin32)
                        {
                            c.arch |= Configuration.architecture.win32;
                        }

                        c.SelfExtractingExecutableLocation = F.sfxLocation;
                        if (!Directory.Exists(F.OutputFolder))
                        {
                            Directory.CreateDirectory(F.OutputFolder);
                        }
                        c.DestinationFolder = F.OutputFolder;
                        c.numberSimsPerJob  = F.simsPerJobNumber;
                        c.useSingleCPU      = F.useSingleCPU;

                        c.Go(FilesToRun, UpdateProgress);

                        MessageBox.Show("Your job has been placed in your dropbox folder. Your outputs will appear adjacent.", "For your information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            Cursor.Current    = Cursors.Default;
            StatusBar.Visible = false;
        }
示例#2
0
    /// <summary>
    /// Command line entry point.
    /// Usage:
    /// Run any number of simulations in any combination of .apsim|.con|.sim files
    ///   BundleApsim.exe  <file1> <dir1> <file2> ....
    ///
    /// Makes zip file just like the GUI's "Run On Cluster" button
    ///
    /// Arguments that are not files or "key=value" pairs are ignored
    /// </summary>
    static int Main(string[] args)
    {
        Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-au");
        try
        {
            Dictionary <string, string> Macros = new Dictionary <string, string>();

            // Parse the command line.
            if (args.Length == 0)
            {
                return(Usage());
            }

            string[] FileNames = null;
            for (int i = 0; i < args.Length; i++)
            {
                string[] x = Utility.realNamesOfFiles(args[i]);
                if (x != null && x.Length > 0)
                {
                    for (int j = 0; j < x.Length; ++j)
                    {
                        if (File.Exists(x[j]) &&
                            (Path.GetExtension(x[j]).ToLower() == ".apsim" ||
                             Path.GetExtension(x[j]).ToLower() == ".sim"))
                        {
                            int l = FileNames == null ? 0 : FileNames.Length;
                            Array.Resize(ref FileNames, l + 1);
                            FileNames[l] = x[j];
                        }
                    }
                }
                else
                {
                    int pos = args[i].IndexOf('=');
                    if (pos > 0)
                    {
                        string name  = args[i].Substring(0, pos).Replace("\"", "");
                        string value = args[i].Substring(pos + 1).Replace("\"", "");
                        Macros.Add(name, value);
                    }
                    else
                    {
                        Console.WriteLine("Dont know what to make of \"" + args[i] + "\"");
                    }
                }
            }

            if (FileNames == null)
            {
                throw new Exception("No files specified on the command line.");
            }

            string simulationSFX = Configuration.Instance.Setting("ClusterSimulationSFX");
            if (Macros.ContainsKey("simulationSFX"))
            {
                simulationSFX = Macros["simulationSFX"];
            }

            bool archWindows; bool.TryParse(Configuration.Instance.Setting("ClusterArchWindows"), out archWindows);
            if (Macros.ContainsKey("archWindows"))
            {
                archWindows = bool.Parse(Macros["archWindows"]);
            }

            bool archUnix; bool.TryParse(Configuration.Instance.Setting("ClusterArchUnix"), out archUnix);
            if (Macros.ContainsKey("archUnix"))
            {
                archUnix = bool.Parse(Macros["archUnix"]);
            }

            int simsPerJob; Int32.TryParse(Configuration.Instance.Setting("ClusterSimsPerJob"), out simsPerJob);
            if (Macros.ContainsKey("simsPerJob"))
            {
                simsPerJob = Int32.Parse(Macros["simsPerJob"]);
            }

            string outputFolder = Configuration.Instance.Setting("ClusterOutputFolder");
            if (Macros.ContainsKey("outputFolder"))
            {
                outputFolder = Macros["outputFolder"];
            }

            bool useSingleCPU; bool.TryParse(Configuration.Instance.Setting("ClusterUseSingleCPU"), out useSingleCPU);
            if (Macros.ContainsKey("useSingleCPU"))
            {
                useSingleCPU = bool.Parse(Macros["useSingleCPU"]);
            }

            bool niceUser = true;
            if (Macros.ContainsKey("niceUser"))
            {
                niceUser = bool.Parse(Macros["niceUser"]);
            }

            // Run
            CondorJob c = new CondorJob();
            c.NiceUser = niceUser;
            c.arch     = 0;
            if (archUnix)
            {
                c.arch |= Configuration.architecture.unix;
            }
            if (archWindows)
            {
                c.arch |= Configuration.architecture.win32;
            }

            c.SelfExtractingExecutableLocation = simulationSFX;
            if (!Directory.Exists(outputFolder))
            {
                outputFolder = ".";
            }
            c.DestinationFolder = outputFolder;
            c.numberSimsPerJob  = simsPerJob;
            c.useSingleCPU      = useSingleCPU;

            c.Go(FileNames.ToList(), UpdateProgress);
        }
        catch (Exception err)
        {
            Console.WriteLine(err.Message);
            return(1);
        }
        return(0);
    }