[ Skip to the content ]

Institute of Formal and Applied Linguistics Wiki


[ Back to the navigation ]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
grid [2017/09/26 18:18]
popel
grid [2017/09/27 19:10]
popel
Line 1: Line 1:
 ====== ÚFAL Grid Engine (LRC) ====== ====== ÚFAL Grid Engine (LRC) ======
  
-LRC (Linguistic Research Cluster) is a name of ÚFAL's computational grid/cluster, which has (as of 2017/09) about 1600 CPU cores (115 servers + 2 submission heads), with a total 10 TiB of RAM. It uses [[https://en.wikipedia.org/wiki/Oracle_Grid_Engine|(Sun/Oracle/Son of) Grid Engine]] software (SGE) for job scheduling etc.+LRC (Linguistic Research Cluster) is a name of ÚFAL's computational grid/cluster, which has (as of 2017/09) about 1600 CPU cores (115 servers + 2 submission heads), with a total 10 TiB of RAM. It uses [[https://en.wikipedia.org/wiki/Oracle_Grid_Engine|(Sun/Oracle/Son of) Grid Engine]] software (SGE) for job scheduling etc. You can submit many computing tasks (jobs) at once, they will be placed in a queue and once a machine (slot) with the required capabilities (e.g. RAM, number of cores) is available, your job will be executed (scheduled) on this machine. This way we can maximize the usefulness of the computing resources and divide it among users in a fair way.
  
 If you need GPU processing, see a special page about our [[:gpu|GPU cluster called DLL]] (which is actually a subsystem of LRC with independent queue ''gpu.q''). If you need GPU processing, see a special page about our [[:gpu|GPU cluster called DLL]] (which is actually a subsystem of LRC with independent queue ''gpu.q'').
  
 ===== List of Machines ===== ===== List of Machines =====
-The list has been updated 2017/09. All machines have Ubuntu 14.04.+Last update: 2017/09. All machines have Ubuntu 14.04.
 Some machines are at Malá Strana (ground floor, new server room built from Lindat budget), some are at Troja (5 km north-east). Some machines are at Malá Strana (ground floor, new server room built from Lindat budget), some are at Troja (5 km north-east).
 If you need to quickly distinguish which machine is located where, you can use your knowledge of [[https://en.wikipedia.org/wiki/Trojan_War|Trojan war]]-related heroes, ''qhost -q'', or the tables below.  If you need to quickly distinguish which machine is located where, you can use your knowledge of [[https://en.wikipedia.org/wiki/Trojan_War|Trojan war]]-related heroes, ''qhost -q'', or the tables below. 
Line 40: Line 40:
 | sol[6-8]            | Intel               | 2.0 |    8 |   16 | you can ssh here and compute | | sol[6-8]            | Intel               | 2.0 |    8 |   16 | you can ssh here and compute |
  
-**lrc machines** are so called heads of the cluster. **No computation is allowed here** (i.e. no CPU-intensive, disk-intensive or RAM-intensive computationvery simple scripts are OK). You should just ssh to ''lrc1'' or ''lrc2'' and submit your jobs as described bellow.+The two **lrc machines** are so called heads of the cluster. **No computation is allowed here**i.e. no CPU-intensive, disk-intensive nor RAM-intensive computation (very simple scripts are OK). You should just ssh to ''lrc1'' or ''lrc2'' and submit your jobs as described bellow.
  
-Alternatively, you can ssh to one of the **sol machines** and submit jobs from here. It is allow to do computing, which is useful e.g. when you have a script which submits your jobs, but it also collects statistics from the jobs outputs (and possibly submits new jobs conditioned on the statistics). However, The sol machines are relatively slow and may be occupied by your colleagues, so for bigger (longer) tasks, always prefer submission as separate jobs.+Alternatively, you can ssh to one of the **sol machines** and submit jobs from here. It is allowed to compute here, which is useful e.g. when you have a script which submits your jobs, but it also collects statistics from the jobs outputs (and possibly submits new jobs conditioned on the statistics). However, the sol machines are relatively slow and may be occupied by your colleagues, so for bigger (longer) tasks, always prefer submission as separate jobs.
  
 The **pandora machines** are in a special cluster (not accessible from lrc) and queue **ms-guests.q** available for our colleagues from KSVI and for students of [[http://ufal.mff.cuni.cz/courses/npfl102|Data intensive computing]] (see the 2016 handouts if you missed the course). The **pandora machines** are in a special cluster (not accessible from lrc) and queue **ms-guests.q** available for our colleagues from KSVI and for students of [[http://ufal.mff.cuni.cz/courses/npfl102|Data intensive computing]] (see the 2016 handouts if you missed the course).
  
-fronty výpočtů, které se odesílají na výpočetní stroje v clusteru. Na hlavě se nemají pouštět žádné náročné výpočty a naopak na ostatní stroje v clusteru se mají výpočty odesílat výhradně prostřednictvím hlavy. Hlava má 2 procesory Intel Pentium D 3 GHz a 1 GB paměti. Ve skutečnosti existují hlavy dvě - lrc1 a lrc2, které sdílí IP adresu lrc.ufal.hide.ms.mff.cuni.cz. V případě výpadku jedné z hlav, přebírá kontrolu ta druhá.  +===== Installation =====
-Frontovací systém umožňuje:+
  
-  * využít na maximum výpočetní výkon +Add the following line into your '~/.bash_profile'.
-  * poslat mnoho úloh k řešení najednou, úlohy budou ale spuštěny teprve, když na to bude čas +
-  * "spravedlivě" dělit strojový čas mezi zájemce+
  
-===== Jak začít =====+  source /net/projects/SGE/user/sge_profile
  
-Jednou za život musíte provést [[Základní nastavení SGE]]abyste SGE mohli používat.+This detects if you are on one of the cluster machines (including lrc and sol) and sets env variables accordingly. It also prints a status message. 
 +Usuallythis is the first line of your '~/.bash_profile' and the second-and-last line is
  
-===== Ukázka užití SGE =====+  [ -f ~/.bashrc ] && source ~/.bashrc
  
-Tato posloupnost příkazů ukazujejak užít SGE:+===== Basic usage ===== 
 + 
 +Firstyou need to ssh to the cluster head (lrc1 or lrc2) or to one of the sol machines. The full address is ''lrc1.ufal.hide.ms.mff.cuni.cz'', but you can use just ''ssh lrc1'' ("hide" means it is accessible only from the ÚFAL network, not from outside; if working from home/Eduroam, you need to [[internal:remote-access|login/VPN]] to the ÚFAL network first).
  
 <code> <code>
-ssh lrc2 +ssh lrc1 
-  # přihlašte se na hlavu clusteru +echo 'hostname; pwd; echo The second parameter is $2' script.sh 
-echo "hostname; pwdskript.sh +  # prepare a shell script describing your task 
-  # vyrobte skript, který popisuje, co má úloha udělat +qsub -cwd -j y script.sh Hello World 
-qsub -cwd -j y skript.sh +  # This submits your job to the default queue, which is currently ''ms-all.q''
-  # zařaďte úlohu do fronty+  # Usually, there is a free slot, so the job will be scheduled within few seconds
-  # Vlastně stačilo zavolat: qsub skript.sh +  # We have used two handy qsub parameters
-  # Ale dodatečné parametry zařídily+  #  -cwd  ... the script is executed in the current directory (the default is your home
-  #  -cwd  ... skript bude spuštěn v aktuálním adresáři (a nikoli homu) +  #  -j y  ... stdout and stderr outputs are merged and redirected to file (''script.sh.o*''
-  #  -V    ... proměnné z vašeho prostředí budou zkopírovány do prostředí skriptu +  # We have also provided two parameters for our script "Hello" and "World". 
-  #  -j y  ... standardní chybový výstup bude spojen (jako to dělá nohup+  # The qsub prints something like 
-  # Pořadí parametrů **je** důležité, co je za jménem skriptu, to se předává skriptu.+  #   Your job 121144 ("script.sh") has been submitted
 qstat qstat
-qstat -u '*'  +  # This way we inspect all our jobs (both waiting in queue and scheduled, i.e. running). 
-  # Podívejme se, jaké vaše úlohy běží+qstat -u '*' | less 
-  # SGE chvíli čeká, než skript opravdu spustíPro malinké úlohy tedy SGE může představovat +  # This shows jobs of all users. 
-  # zbytečné zpoždění+qstat -j 121144 
-  # -u '*' ukáže úlohy všech uživatelů na clusteri +  # This shows detailed info about the job with this number (if it is still running)
-cat skript.sh.oXXXXX +less script.sh.o* 
-  # vypište si výstup skriptuXXXXX je ID jobu, které bylo přiděleno +  # We can inspect the job's output (in our case stored in script.sh.o121144)
-  # qsubem. Čili druhé poslání do fronty starší log typicky nepřepíše.+  # Hint: if the job is still running, press F in 'less' to simulate 'tail -f'.
 </code> </code>
  
-A takto dopadl výstup našeho skriptu:+The output of our job should look like:
  
 <code> <code>
-Warningno access to tty (Bad file descriptor). +LRC:ubuntu 14.04: 8.1.7a Son of Grid Engine variables set... 
-Thus no job control in this shell. +lucifer5 
-sol2.ufal.hide.ms.mff.cuni.cz +/home/popel/tmp 
-/export/home/bojar+The second parameter is World 
 +======= EPILOG: Tue Sep 26 19:49:05 CEST 2017 
 +== Limits:    
 +== Usage:    cpu=00:00:00, mem=0.00000 GB s, io=0.00000 GB, vmem=N/A, maxvmem=N/
 +== Duration: 00:00:02 (2 s)
 </code> </code>
  
-Další užitečné příkazy a parametry:+Our admins configured the SGE to print some extra info on stderrthe first line and then the epilog. 
 +The ''mem=XY GB s'' means gigabytes of RAM used //times// the duration of the job in seconds, so don't be afraid XY is usually a very high number (unlike in this toy example). 
 +The ''maxvmem'' means the peak virtual memory consumption (which is useful for setting ''h_vmem'', see below).
  
 <code> <code>
-qsub -o LOG.stdout -e LOG.stderr skript.sh +qdel 121144 
-  # když chcete přesměrovat výstup skriptu do určených souborů +  # This way you can delete ("kill") a job with a given numberor comma-or-space separated list of job numbers.
-qsub -S /bin/bash +
-  # když chceteaby skript běžel v bashi +
-qsub -+
-  # když chcete předat proměnné prostředí+
 qdel \* qdel \*
-  # když chcete zrušit všechny své joby (rušit cizí nesmíte)+  # This way you can delete all your jobs. Don't be afraid - you cannot delete others jobs.
 </code> </code>
  
 +===== Rules =====
 +The purpose of these rules is to prevent your jobs to damage the work of your colleagues and to divide the resources among users in a fair way.
  
 +  * Read about our [[internal:linux-network|network]] first (so you know that e.g. reading big data from your home in 200 parallel jobs is not a good idea, but regular cleanup of your data is a good idea). Ask your colleagues (possibly via [[internal:mailing-lists|devel]]) if you are not sure, esp. if you plan to submit jobs with unusual/extreme disk/mem/CPU requirements.
 +  * While your jobs are running (or queued), check your jobs (esp. previously untested setups) and your email (esp. [[internal:mailing-lists|devel]]) regularly. If you really need to leave e.g. for two-week vacation offline, consult it first with it@ufal (whether they can kill your jobs if needed).
 +  * You can ssh to any cluster machine, which can be useful e.g. to diagnose what's happening there (using ''htop'' etc.).
 +  * However, **never execute any computing manually** on a cluster machine where you are sshed (i.e. not via ''qsub'' or ''qrsh''). If you break this rule, your task will take CPU and memory, but the SGE will not know, so it may schedule other users' jobs on the same machine and **their jobs may fail** or run slowly. The sol machines are an exception from this rule.
 +  * For interactive work, you can use ''qrsh'', but please try to end the job (exit with Ctrl+D) once finished with your work, especially if you ask for a lot of memory or CPUs (see below). One semi-permanent qrsh job (with non-extreme CPU/mem requirements) per user is acceptable.
 +  * **Specify the memory and CPU requirements** (if higher than the defaults) and **don't exceed them**.
 +    * If your job needs more than one CPU (on a single machine) for most of the time, reserve the given number of CPU cores (and SGE slots) with <code>qsub -pe smp <number-of-CPU-cores></code> As you can see in [[#List of Machines]], the maximum is 32 cores. If your job needs e.g. up to 110% CPU most of the time and just occasionally 200%, it is OK to reserve just one core (so you don't waste). TODO: when using ''-pe smp -l mf=8G,amf=8G,h_vmem=12G'', which memory limits are per machine and which are per core?
 +    * If you are sure your job needs less than 1GB RAM, then you can skip this. Otherwise, if you need e.g. 8 GiB, you must always use ''qsub'' (or ''qrsh'') with ''-l mem_free=8G''. You should specify also ''act_mem_free'' with the same value and ''h_vmem'' with possibly a slightly bigger value. See [[#memory]] for details. TL;DR: <code>qsub -l mem_free=8G,act_mem_free=8G,h_vmem=12G</code> 
 +  * Be kind to your colleagues. If you are going to submit jobs that effectively occupy more than one fifth of our cluster for more than several hours, check if the cluster is free (with ''qstat -g c'' or ''qstat -u \*'') and/or ask your colleagues if they don't plan to use the cluster intensively in the near future. Note that if you allocate one slot (CPU core) on a machine, but (almost) all its RAM, you have effectively occupied the whole machine and all its cores.
  
  
 +=== Memory ===
  
-===== Pravidla pro správné používání clusteru =====+  * There are three commonly used options for specifying memory requirements: ''mem_free, act_mem_free'' and ''h_vmem''. Each has a different purpose. 
 +  * ''mem_free=1G'' means 1024×1024×1024 bytes, i.e. one [[https://en.wikipedia.org/wiki/Gibibyte|GiB (gibibyte)]]. ''mem_free=1g'' means 1000×1000×1000 bytes, i.e. one gigabyte. Similarly for the other options and other prefixes (k, K, m, M). 
 +  * **mem_free** (or mf) specifies a //consumable resource// tracked by SGE and it affects job scheduling. Each machine has an initial value assigned (slightly lower than the real total physical RAM capacity). When you specify ''qsub -l mem_free=4G'', SGE finds a machine with mem_free >4GB, and subtracts 4GB from it. This limit is not enforced, so if a job exceeds this limit, **it is not automatically killed** and thus the SGE value of mem_free may not represent the real free memory. The default value is 1G. By not using this option and eating more than 1 GiB, you are breaking the rules. 
 +  * **act_mem_free** (or amf) is a ÚFAL-specific option, which specifies the real amount of free memory (at the time of scheduling). You can specify it when submitting a job and it will be scheduled to a machine with at least this amount of memory free. In an ideal world, where no jobs are exceeding their ''mem_free'' requirements, we would not need this options. However, in real world it is recommended to use this option with the same value as ''mem_free'' to protect your job from failing with out-of-memory error (because of naughty jobs of other users). 
 +  * **h_vmem** is equivalent to setting ''ulimit -v'', i.e. it is a hard limit on the size of virtual memory (see RLIMIT_AS in ''man setrlimit''). If your job exceeds this limit, memory allocation fails (i.e., malloc or mmap will return NULL), and your job will probably crash on SIGSEGV. TODO: according to ''man queue_conf'', the job is killed with SIGKILL, not with SIGSEGV. Note that ''h_vmem'' specifies the maximal size of **allocated_memory, not used_memory**, in other words it is the VIRT column in ''top'', not the RES column. SGE does not use this parameter in any other way. Notably, job scheduling is not affected by this parameter and therefore there is no guarantee that there will be this amount of memory on the chosen machine. The problem is that some programs (e.g. Java with the default setting) allocate much more (virtual) memory than they actually use in the end. If we want to be ultra conservative, we should set ''h_vmem'' to the same value as ''mem_free''. If we want to be only moderately conservative, we should specify something like h_vmem=1.5*mem_free, because some jobs will not use the whole mem_free requested, but still our job will be killed if it allocated much more than declared. The default effectively means that your job has no limits. 
 +  * It is recommended to **profile your task first**, so you can estimate reasonable memory requirements before submitting many jobs with the same task (varying in parameters which do not affect memory consumption). So for the first time, declare mem_free with much more memory than expected and ssh to a given machine and check ''htop'' (sum all processes of your job) or (if the job is done quickly) check the epilog. When running other jobs of this type, set ''mem_free'' (and ''act_mem_free'' and ''h_vmem'') so you are not wasting resources, but still have some reserve. 
 +  * **s_vmem** is similar to ''h_vmem'', but instead of SIGSEGV/SIGKILL, the job is sent a SIGXCPU signal which can be caught by the job and exit gracefully before it is killed. So if you need it, set ''s_vmem'' to a lower value than ''h_vmem'' and implement SIGXCPU handling and cleanup.
  
-Základní pravidlo, které musíme všichni ctít, aby SGE plnilo svou úlohu dobře: 
  
-  * Nespouštět úlohy ručně. (O ručně spuštěných úlohách SGE nemá informaci, klidně na daný uzel pošle ještě další úlohy z fronty.) +===== Advanced usage =====
-    * Interaktivní shell se dá získat příkazem ''qrsh'' (přičemž specifikujete požadavky na zdroje stejně jako u ''qsub''+
- +
-Další doporučení: +
-  * Pokud možno používat ''nice''+
-      *  Dotaz: jak se kombinuje ''nice'' s ''qsub''em? SGE je snad nyní nastaveno tak, že vše bude nicenuté. Každopádně je dobré do submitovaného skriptu na začátek napsat ''renice 10 $$''+
-  * Uklízet po sobě lokální data, protože jinak si tam už nikdo nic užitečného nepustí. +
-  * Vyhnout se hodně divokému paralelnímu přístupu ke sdíleným diskům. NFS server to pak nepěkně zpomalí pro všechny. Distribuujte tedy i data. +
-  * Informovat SGE, kolik paměti úloha žere, aby na strojích nedošla paměť (a používat "hard" limit, kdy SGE úlohu zabije, pokud rezervovanou paměť překročí): <code>qsub -hard -l mem_free=8G -l act_mem_free=8G -l h_vmem=8G</code> +
- +
- +
-Víc pravidel není. +
- +
-===== Slušné chování ===== +
- +
-Pokud chci spouštět úlohy, které poběží dlouhou dobu (hodiny, dny), nepustím je všechny najednou, aby cluster mohli využívat i ostatní. +
- +
-===== Triky a opentlení ===== +
- +
- +
-==== ~bojar/tools/shell/qsubmit ==== +
- +
-qsubmit je jako qsub, ale příjemnější: +
- +
-  * nemusíte vyrábět skript, vyrobí ho sám (pozn.: nemusíte vyrábět skript, když použijete přepínač ''-b y''+
-  * nemusíte připisovat ''-cwd -j y -S /bin/bash''+
  
 +  * <code>qsub -o LOG.stdout -e LOG.stderr</code>
 +    redirect std{out,err} to separate files with given names
 +    
 <code> <code>
-~bojar/tools/shell/qsubmit "bashovy_prikaz < prismeruj > presmeruj 2> atd..." +qsub -S /bin/bash 
-</code>  +  # Choose the interpreter of your scriptI think ''/bin/bash'' is now (2017/09the default (but it used to be ''csh''). 
- +qsub -v PATH 
-lépe funguje ''~{stepanek,pajas}/bin/qcmd'' (nemusí se kvotovat parametry, správně počítá čas běhu...) +  # export a given environment variable from the current shell to the job 
- +qsub -V 
-==== ~zeman/bin/qsub.csh ==== +  # export all environment variables 
- +man qsub qstat qhold queue_conf sge_types complex 
-Podobná věc pro ''tcsh''. Pokud bychom chtěli použít přesměrování standardního vstupu a výstupu, musíme ho dát do uvozovek nebo apostrofů, protože jinak se o něm ''qsub.csh'' nedozví, do skriptu k odeslání to neopíše a naopak jeho standardní vstup a výstup bude přesměrován. V přesměrování i v případných dalších argumentech, kde se vyskytují cesty k souborům, je vhodné použít úplné cesty. Pozor také na to, aby šlo o soubory a složky viditelné z celé sítě (tedy ne ve vašem ''/mnt/h/tmp'', například). +  # Find out all the gory details which are missing hereYou'll have to do it one anyway:-). 
- +</code>
-<code tcsh>setenv SCRIPTFILE /tmp/`basename $1`.$$.csh +
-echo $* > $SCRIPTFILE +
-echo $* +
-echo qsub -cwd -V -S /bin/tcsh -m e $SCRIPTFILE +
-qsub -cwd -V -S /bin/tcsh -m e $SCRIPTFILE +
-qstat -u '*' +
-rm $SCRIPTFILE</code> +
- +
-Příklad spuštění: +
- +
-<code>qsub.csh $PARSER/train.pl "< $cesta/${xx}train.csts > $cesta/${xx}.1.stat"</code> +
- +
-(Kdybych místo uvozovek použil apostrofy, nerozbalily by se mi proměnnéPrvní argument (název skriptu) klidně mohl být v uvozovkách spolu s přesměrováním. Dal jsem ho ven jen proto, že potom ''qsub.csh'' podle něj pojmenuje job ve frontě.) +
- +
- +
- +
- +
- +
-==== TectoMTdevel/tools/cluster_utils/qrunblocks ==== +
- +
-Jako ''$BRUNBLOCKS'', ale spouští úlohy na gridu (bez pomoci [[internal:jtred]]u). +
- +
-   qrunblocks filelist blocks +
- +
-Skript zadanou hromádku souboru rozdělí do ''-''''-jobs'' jobů. Každý job na gridu pak projede své soubory danou sekvencí bloků. +
- +
-Soubory možno zadat filelistem, nebo pomocí ''-''''-glob'' (stručně ''-g''). Bloky možno vyjmenovat v jednom argumentu, nebo načíst ze souboru pomocí ''--blocksfile SOUBOR''+
- +
-Je nutné buď zadat ''-''''-tmt-root CESTA'', nebo mít nastaven ''$TMT_ROOT'' podle inicializace TectoMT. +
- +
-Parametr ''-E'' zpusobí, že se jobům z aktuálního prostředí procedí všechny proměnné ''TMT_PARAM_*'' (čili např. model parseru ap.). Případně je pomocí ''-e'' možné vyjmenovat některé (další) ručně. +
- +
-Parametr ''-''''-sync'' způsobí, že skript navíc bude (pasivně) čekat, až všechny joby skončí. +
- +
-Výstup každého jobu jde do vlastního logu, ''JOBNAME.o123456''. Pokud JOBNAME nezadáte (parametr ''-N''), užije se defaultní ''qrunblocks''+
- +
-Parametr ''-''''-join'' způsobí, že se STDOUT všech kousků (ve správném pořadí) sebere a vypíše na hlavní STDOUT (''-''''-join'' implikuje ''-''''-sync''). Při spojování se také dělá důkladný test exitstatusů, takže ''qrunblocks'' končí úspěchem jen tehdy, když všechny joby uspěly.+
  
-Bez ''-''''-sync'' nebo ''-''''-join'' nezbývánež kontrolovatjestli logy jednotlivých jobů na konci nemají napsáno:  ''Status: FAILED''.+  * By default, all the resource requirements (specified with ''-l'') and queue requirements (specified with ''-q'') are //hard//, i.e. your job won't be scheduled unless they can be fulfilled. You can use **''-soft''** to mark all following requirements as nice-to-have. And with **''-hard''** you can switch back to hard requirements. 
 +  * If you often run (ad-hoc) bash commands via ''qsub'', check two alternative qsub wrappers ''~bojar/tools/shell/qsubmit'' or ''~stepanek/bin/qcmd''which allow you to enter the command on command line without creating any temp script files. The wrappers have also other features (some qsub options have changed default values). ''qcmd'' is older, but unlike ''qsubmit'' it has POD documentation, correct time computation and you don't need to quote the command.
  
 ===== Monitorování úloh ===== ===== Monitorování úloh =====
Line 292: Line 253:
 </code> </code>
  
-===== Synchronizace úloh (v Perlu) ===== 
- 
-Pokud chci paralelizovat část úlohy (zde ''muj_skript.pl''), obvykle potřebuju po provedení paralelní části posbírat výsledky a hlavně počkat na dokončení všech paralelních větví. Jak na to jednoduše: 
- 
-  * Obalím svůj skript pro běh na gridu – vytvořím ''obaleno.sh'': 
-    <code> 
-#!/bin/bash 
-. /net/projects/SGE/user/sge_profile >/dev/null 
- 
-qrsh -cwd -V -p -50 -l mf=5g -now no 'renice 10 $$ >/dev/null; ./muj_skript.pl $@' 
-</code> 
-  * Ve svém hlavním skriptu ho pak zavolám a posbírám výsledky: 
-    <code> 
-use FileHandle; 
-use IPC::Open2; 
-use threads; 
-use threads::shared; 
-my @threads; 
-my @results; 
-share(@results); 
-for (@inputs)   { 
-    my $t = async { 
-        my $reader; my $writer; 
-        my $pid = open2($reader, $writer, "./obaleno.sh " . $parametry); # Pustime ulohu na gridu 
-        die "Failed to open bipipe" if !$pid; 
-        $writer->autoflush(1); # Muzem zavolat, ale v gridu NEFUNGUJE!!! 
-        print $writer "$_\n" or die; # Poslem uloze v gridu vstup 
-        $writer->close(); # Dulezite, viz o 2 radky vyse 
-        for (<$reader>   { # Posbirame vysledky 
-            chomp; 
-            { 
-               lock @results; 
-               push @results, $_; 
-            } 
-        } 
-        waitpid $pid, 0; # Pockame s ukoncenim vlakna na ukonceni ulohy v gridu 
-        return $? >> 8; # Pokusime se ziskat navratovou hodnotu (netestoval jsem) 
-    }; 
-    push @threads, $t; 
-} 
-for (@threads)  { # Pockame, az to vsichni dodelaji 
-    die "Child exited with non-zero exit code" if $_->join(); 
-} 
-</code> 
- 
-Poznámky:  
-  * Pokud lze všechno předat parametry, nemusí se otevírat obousměrná roura a situace bude jednodušší 
-  * Pokud ''muj_skript.pl'' začne psát na výstup dřív, než přečetl všechen vstup, dojde k deadlocku. Lze vyřešit obalením příkazy ''cat'' v ''obaleno.sh''. 
-  * Celý příklad je k vidění v Czengu od V.N. 

[ Back to the navigation ] [ Back to the content ]