diff inst/import_ufl_Functional.m @ 255:072aee55bb75

Import UFL in a parallel-safe fashion
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Wed, 30 Jul 2014 18:09:13 +0200
parents e3f57f92fa66
children 61830a4f9ab9
line wrap: on
line diff
--- a/inst/import_ufl_Functional.m	Sat Jul 26 19:38:23 2014 +0200
+++ b/inst/import_ufl_Functional.m	Wed Jul 30 18:09:13 2014 +0200
@@ -26,33 +26,38 @@
 ## @end deftypefn
 function import_ufl_Functional (var_prob)
 
-  if nargin != 1
-    error ("import_ufl_Functional: wrong number of input parameters.");
-  elseif ! ischar (var_prob)
-    error ("import_ufl_Functional: first argument is not a valid string");
+  if (is_master_node ())
+    if nargin != 1
+      error ("import_ufl_Functional: wrong number of input parameters.");
+    elseif ! ischar (var_prob)
+      error ("import_ufl_Functional: first argument is not a valid string");
+    endif
+
+    if (check_hash (var_prob) || ! check_oct_files (var_prob, "Functional"))
+      n = length (mfilename ("fullpath")) - length (mfilename());
+      path = strtrunc(mfilename ("fullpath"), n);
+
+      private = fullfile (path, "include/");
+      output = generate_fun (var_prob);
+      output += generate_makefile (var_prob, private);
+      if output != 0
+        error ("Compilation failed");
+      else
+        [output, textfile] = system (sprintf ("make -f Makefile_%s fun", var_prob));
+        if output != 0
+          display (text);
+          error ("Compilation failed");
+        endif
+        [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob));
+        if output != 0
+          display (text);
+          error ("Compilation failed");
+        endif
+        save_hash (var_prob);
+      endif
+    endif
   endif
 
-  if (check_hash (var_prob) || ! check_oct_files (var_prob, "Functional"))
-    n = length (mfilename ("fullpath")) - length (mfilename());
-    path = strtrunc(mfilename ("fullpath"), n);
+  barrier ();
 
-    private = fullfile (path, "include/");
-    output = generate_fun (var_prob);
-    output += generate_makefile (var_prob, private);
-    if output != 0
-      error ("Compilation failed");
-    else
-      [output, textfile] = system (sprintf ("make -f Makefile_%s fun", var_prob));
-      if output != 0
-        display (text);
-        error ("Compilation failed");
-      endif
-      [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob));
-      if output != 0
-        display (text);
-        error ("Compilation failed");
-      endif
-      save_hash (var_prob);
-    endif
-  endif
 endfunction