1 /* 2 * Copyright 2023 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.mindspore.lite.demo; 18 19 import java.util.ArrayList; 20 import java.io.*; 21 22 public class MainExec { main(String[] args)23 public static void main(String[] args) { 24 String pkgClassPath = "path to the project jar file"; 25 String msClassPath = "path to mindspore-lite-java.jar file"; 26 String classPaths = pkgClassPath + ":" + msClassPath; 27 String configPath = "path to the model config file"; 28 String firstMainModelPath = "path to the first mindir main model"; 29 String firstIncModelPath = "path to the first mindir incremental model"; 30 String secondMainModelPath = "path to the second mindir main model"; 31 String secondIncModelPath = "path to the second mindir incremental model"; 32 String firstDeviceId = "4"; 33 String secondDeviceId = "5"; 34 String firstRankId = "0"; 35 String secondRankId = "1"; 36 String[] command1 = {"java", "-classpath", classPaths, "com.mindspore.lite.demo.Main", firstMainModelPath, 37 firstIncModelPath, firstDeviceId, firstRankId, configPath}; 38 String[] command2 = {"java", "-classpath", classPaths, "com.mindspore.lite.demo.Main", secondMainModelPath, 39 secondIncModelPath, secondDeviceId, secondRankId, configPath}; 40 ProcessBuilder pb1 = new ProcessBuilder().command(command1).redirectOutput(ProcessBuilder.Redirect.INHERIT); 41 ProcessBuilder pb2 = new ProcessBuilder().command(command2).redirectOutput(ProcessBuilder.Redirect.INHERIT); 42 pb1.redirectErrorStream(true); 43 pb2.redirectErrorStream(true); 44 ArrayList<ProcessBuilder> processBuilders = new ArrayList<>(); 45 ArrayList<Process> processes = new ArrayList<>(); 46 processBuilders.add(pb1); 47 processBuilders.add(pb2); 48 for (ProcessBuilder pb : processBuilders) { 49 try { 50 Process p = pb.start(); 51 processes.add(p); 52 } catch (Exception e) { 53 e.printStackTrace(); 54 } 55 } 56 57 for (Process p : processes) { 58 try { 59 p.waitFor(); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 } 64 System.out.println("All processes execute done!"); 65 } 66 } 67