Konstantin Ladutenko 6 years ago
commit
73936dde81
7 changed files with 163 additions and 0 deletions
  1. 26 0
      create_hpc_bat.lsf
  2. 49 0
      hpc.bat
  3. 6 0
      hpc_curdir_check.lsf
  4. 20 0
      hpc_file_check.lsf
  5. 17 0
      hpc_get_hostname.lsf
  6. 20 0
      hpc_scan_paths.lsf
  7. 25 0
      hpc_try_path.lsf

+ 26 - 0
create_hpc_bat.lsf

@@ -0,0 +1,26 @@
+slash = "/";
+if (operatingsystem == "windows") {slash = "\\";}
+rootdir = pwd;
+######################################################
+# Get local hostname
+if (operatingsystem == "windows") {
+    hpc_get_hostname; # variables input: rootdir; output: hostname or break;
+} else { hostname = "test";}
+#######################################################
+fname = rootdir+slash+hostname+"exec.bat";
+if (fileexists(fname)){rm(fname);}
+
+paths_string = rootdir+endl;  # paths are separated by a new line symbol
+hpc_scan_paths; #input: paths_string with initial path;
+#output: paths_string with all paths;
+#can change working directory
+cd(rootdir);
+paths = splitstring(paths_string,endl);
+for(i=1:length(paths)) {
+    if (paths{i} != ""){
+        curdir = paths{i};
+        hpc_curdir_check; # input: curdir, fname; output: none or break;
+    }
+}
+write(fname,"exit /b 0");
+cd(rootdir);

+ 49 - 0
hpc.bat

@@ -0,0 +1,49 @@
+@echo off
+REM run on hpc
+
+setlocal EnableDelayedExpansion
+set "startTime=%time: =0%"
+
+REM path %path%;
+REM"C:\Program Files\Lumerical\FDTD\bin\fdtd-engine" -t 32 template-dipole-on-sphere-on-surf-z.fsp
+
+echo Write hostname to temp folder file
+set host=%COMPUTERNAME%
+echo %host% > %TEMP%\hostname.txt
+
+echo Preinit exec.bat
+echo exit /b 1 > %host%exec.bat
+
+echo Before loop
+:loop
+REM random timeout 10 seconds
+    echo random wait
+    set /a timeout=%RANDOM% * 11 / 32768
+    start /wait timeout %timeout%
+    echo %TEMP% > temppath.txt
+    echo execute Lumerical script
+    "C:\Program Files\Lumerical\FDTD\bin\fdtd-solutions" -nw -run create_hpc_bat.lsf
+    echo Run local exec.bat                                
+    call %host%exec.bat
+if !errorlevel! gtr 0 goto loop
+
+echo after loop
+
+REM mpiexec -n 16 python Si_cylinder_on_Al2O3_substrate.py
+REM python Si_cylinder_on_Al2O3_substrate.py
+
+
+set "endTime=%time: =0%"
+
+
+
+rem Get elapsed time:
+set "end=!endTime:%time:~8,1%=%%100)*100+1!"  &  set "start=!startTime:%time:~8,1%=%%100)*100+1!"
+set /A "elap=((((10!end:%time:~2,1%=%%100)*60+1!%%100)-((((10!start:%time:~2,1%=%%100)*60+1!%%100)"
+
+rem Convert elapsed time to HH:MM:SS:CC format:
+set /A "cc=elap%%100+100,elap/=100,ss=elap%%60+100,elap/=60,mm=elap%%60+100,hh=elap/60+100"
+
+echo Start:    %startTime%
+echo End:      %endTime%
+echo Elapsed:  %hh:~1%%time:~2,1%%mm:~1%%time:~2,1%%ss:~1%%time:~8,1%%cc:~1%

+ 6 - 0
hpc_curdir_check.lsf

@@ -0,0 +1,6 @@
+cd(curdir);
+files = splitstring(dir,endl);
+for(i=1:length(files)) {
+    file_to_check = files{i};
+    hpc_file_check; # input variables: file_to_check, fname, curdir; output: none or break
+}

+ 20 - 0
hpc_file_check.lsf

@@ -0,0 +1,20 @@
+slash = "/";
+if (operatingsystem == "windows") {slash = "\\";}
+
+if(fileextension(file_to_check) == "fsp") {
+    lockfile =  file_to_check+".lock";
+    if (!fileexists(lockfile)){
+        load(file_to_check);
+        status = layoutmode;
+        if (status == 1) {
+            write(fname,"IF EXIST \""+curdir+slash+lockfile+"\" exit /b 1");
+            write(fname,"copy /y NUL "+curdir+slash+lockfile+" >NUL");
+            write(fname,"\"C:\Program Files\Lumerical\FDTD\bin\fdtd-engine\" -t 32 "+curdir+slash+files{i});
+            write(fname,"echo del "+curdir+slash+lockfile);
+            write(fname,"del "+curdir+slash+lockfile);
+            write(fname,"exit /b 1");
+            if (operatingsystem == "windows") {break;}
+            ?"==wrote bat for fsp== "+file_to_check;
+        }
+    }
+}

+ 17 - 0
hpc_get_hostname.lsf

@@ -0,0 +1,17 @@
+if (fileexists("temppath.txt")) {
+    temppath = read("temppath.txt");
+    len = length(temppath);
+    temppath = substring(temppath,1,len-2);
+    cd(temppath);
+    if (fileexists("hostname.txt")) {
+        hostname = read("hostname.txt");
+        len = length(hostname);
+        hostname = substring(hostname,1,len-2);
+        cd(rootdir);
+    } else {
+        cd(rootdir);
+        break;
+    }
+} else {
+    break;
+}

+ 20 - 0
hpc_scan_paths.lsf

@@ -0,0 +1,20 @@
+isNewPath = true;
+for (0; isNewPath; 0) {
+    isNewPath = false;
+    paths = splitstring(paths_string,endl);
+    for(i=1:length(paths)) {
+        if (paths{i} != ""
+        and paths{i} != "."
+        and paths{i} != ".."
+        #        and findstring(paths{i},"result")== -1
+        ) {
+            #? "root path to check: "+        paths{i};
+            cd(paths{i});
+            files = splitstring(dir,endl);
+            for(i=1:length(files)) {
+                path_to_check = files{i};
+                hpc_try_path;
+            }
+        }
+    }
+}

+ 25 - 0
hpc_try_path.lsf

@@ -0,0 +1,25 @@
+slash = "/";
+if (operatingsystem == "windows") {slash = "\\";}
+
+if (path_to_check != ""
+and path_to_check != "."
+and path_to_check != ".."
+and findstring(path_to_check,"result")== -1
+) {
+    errMsg = "";
+    tmp_curdir = pwd;
+    try {
+        cd(path_to_check);
+        cd(tmp_curdir);
+    } catch(errMsg);
+    if (errMsg == "") {
+        full_path = tmp_curdir+slash+path_to_check;
+        #?"--> test --> "+full_path;
+        if ( findstring(paths_string, full_path+endl) == -1) {
+            #?"adding";
+            isNewPath = true;
+            paths_string = paths_string + full_path+endl;
+        }
+    }
+    
+}