﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3334	ParModelica: failure using parallel function	Gustaf Thorslund	Mahder Alemseged Gebremedhin	"Suppose we had a small testcase where a parallel function was called from within a parfor-loop. Suppose the testcase looked something like the following:
{{{#!mo
package ParFuncTest
  constant Integer globalSizes = 10;
  constant Integer localSizes = 2;
  constant Integer elements = 10;

  parallel function f
    parglobal input Integer i;
    parglobal output Integer o;
  algorithm
    o := 10*i;
    annotation(Inline=true);
  end f;

  function test
    input Integer a;
    output Integer result[elements];
  protected
    Integer v[elements] = {i for i in 1:elements};
    parglobal Integer pv[elements];
    parglobal Integer pr[elements];
    parglobal Integer pa;
    parglobal Integer pi;
  algorithm
    oclSetNumThreadsGlobalLocal1D({globalSizes}, {localSizes});
    pa := a;
    pv := v;
    parfor i in 1 : elements loop
      pi := i;
      pr[i] := pa * pv[i] * f(pi);
    end parfor;
    result := pr;
  end test;
end ParFuncTest;
}}}

Now suppose we call the function 'test' from a script, maybe something like:
{{{#!mo
setCommandLineOptions(""+d=noevalfunc +g=ParModelica -v=1"");
getErrorString();
loadFile(""ParFuncTest.mo"");
getErrorString();

x:=ParFuncTest.test(5);
getErrorString();
}}}

Suppose we try this on host, suppose the host is named 'fermi'...
{{{
$ omc ParFuncTest.mos
true
""""
true
""""
- 3 OpenCL devices available.

1 CL_DEVICE_NAME :		Intel(R) Xeon(R) CPU           E5520  @ 2.27GHz
1 CL_DRIVER_VERSION :	2.0
1 CL_DEVICE_MAX_COMPUTE_UNITS :	16
1 CL_DEVICE_MAX_CLOCK_FREQUENCY :	1600
1 CL_DEVICE_LOCAL_MEM_SIZE :	                                                              32 KB
1 CL_DEVICE_GLOBAL_MEM_SIZE:                                                            24107 MB
1 CL_DEVICE_MAX_MEM_ALLOC_SIZE:                                                             6026 MB
1 CL_DEVICE_MAX_PARAMETER_SIZE: 4096 MB
1 CL_DEVICE_MAX_WORK_GROUP_SIZE: 1024 
1 CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE  : 0
.
 .
  .

- Select your device:      1
	 :Using flags -I""/home/gusth/src/OpenModelica/build/include/omc/c/""
Error building program:
CL_BUILD_PROGRAM_FAILURE 
Build failed: Errors detected in compilation of OpenCL code:
CL_PROGRAM_BUILD_LOG:  
/tmp/OCLuMvo6t.cl(55): error: expression must have arithmetic type
      (*integer_array_element_addr_c99_1(&_pr, 1, /* modelica_integer */ (modelica_integer)_i)) = ((modelica_integer)_pa * ((*integer_array_element_addr_c99_1(&_pv, 1, /* modelica_integer */ (modelica_integer)_i)) * omc_ParFuncTest_f((modelica_integer)_pi)));
                                                                                                                                                                                                                        ^

/tmp/OCLuMvo6t.cl(62): error: function ""ocl_device_alloc"" declared implicitly
    tmp1.c1 = ocl_device_alloc(sizeof(modelica_integer));
              ^

/tmp/OCLuMvo6t.cl(67): error: function ""copy_assignment_helper_integer""
          declared implicitly
    copy_assignment_helper_integer(&tmp1.c1, &_o);
    ^

3 errors detected in the compilation of ""/tmp/OCLuMvo6t.cl"".

Internal error: clc compiler invocation failed.
}}}

Then suppose we suddenly wake up and realise this was just a dream. Maybe a nightmare, but still a dream too good to be true... Somewhere in the dream there was a horrifying part with failure on other devices too, but that's already part of dream #3326, even if the failures where earlier now..."	defect	closed	blocker	1.9.4	ParModelica	trunk	fixed		Mahder Alemseged Gebremedhin
