I am trying to make an array of Integers, which is accessed inside the task.
with CPU=>CPUs(1) doesn't work, as doesn't work any expression at all.
Plain integers work fine, though.
procedure Lab1 is
n: Integer:=222;
CPUs: array (1..3) of Integer := (1, 1, 1);
pri: array (1..3) of Integer := (1, 5, 10);
task T3
with CPU=>1+1
is
pragma Priority(pri(1));
pragma Task_Name ("T3");
end T3;
task body T3 is
int1:Integer:=generate_random_number(4)+n;
I read that it should be possible.
The expression giving the processor for a task can be dynamic.
Adding use System.Multiprocessors.CPU_Range; gives me:
Lab1.ada:20:05: "System" is not visible Lab1.ada:20:05: non-visible
declaration at system.ads:37 Lab1.ada:22:11: warning: file name does
not match unit name, should be "lab1.adb" Lab1.ada:30:14: operator for
type "System.Multiprocessors.CPU_Range" is not directly visible
Lab1.ada:30:14: use clause would make operation legal
I think I figured it.
with System.Multiprocessors;
use System.Multiprocessors;
procedure Lab1 is
n: Integer:=222;
CPUs: array (1..3) of CPU_Range := (1, 1, 1);
pri: array (1..3) of Integer := (1, 5, 10);
task T3
with CPU=>CPUs(1)
is
Related
i have a function that puts a number in a var (var1). if var1 = 3 then create 3 new variables and assign a value for later send that values in an out type. I don't know how can i do, my code is something like this where "pos" acts like an INSTR() that i know its each 13 chars. And "newvar||var1" is because i want my vars names be newvar1, newvar2, newvar3, etc.:
FOR n IN 1..var1
LOOP
pos NUMBER(4):= 0;
newvar||var1 NUMBER(3);
newvar||var1 := SUBSTR(TO_NUMBER(numberInsideString), 1, 1+pos);
pos := pos+13;
END LOOP;
My question is, how a person who really know PLSQL would do that, im learning PLSQL please help. thank you.
What you want to try to do suggests that you need a one dimensional array in order repeatedly to assign new values for each iteration within the loop. One of the types in OWA package such as vc_arr(composed of VARCHAR2 data type values) is handy to define an array.
Coming to the code, you can start with moving the variables into the declaration section, and write such a simple code as a sample exercise
SET serveroutput ON
DECLARE
pos INT := 0;
numberInsideString VARCHAR2(100):='as12df34sdg345apl8976gkh4f11öjhöh678u7jgvj';
newvar OWA.vc_arr;
BEGIN
FOR n IN 1..3
LOOP
newvar(n) := SUBSTR(numberInsideString, 1, 1+pos);
pos := pos+5;
Dbms_Output.Put_Line(newvar(n));
END LOOP;
END;
/
a
as12df
as12df34sdg
I am absolutely new in lua and just want to modify an existing script.
There is a function that writes values in a list. I would like to sort them by name:
function display_moments()
local counter = 1
if(moments[media_name]~=nill) then
moments_list = main_layout:add_list(1,4,4,1) -- empty moments_list widget to prevent duplicate entries
for i,j in pairs(moments[media_name]) do
moments_list:add_value(i,counter)
counter = counter + 1
end
end
end
Do I have the chance to get my list sorted in any way?
From Lua table.sort (ref manual) if your list is as follows
local _list = {1,4,4,1}
print(unpack(_list)) -- 1, 4, 4, 1
table.sort(_list)
print(unpack(_list)) -- 1, 1, 4, 4
you can add following line after the loop, given that your list is an array
table.sort(moments_list)
I have the follow expression:
myGrid.ForEach(Sub(Model) myStreamWriter.WriteLine(Function(x As Integer) (x + 1)))
Of course it's not working. I want to write in a text file (WriteLine) a sequential number (1, 2, 3, etc.) for each record collected in the variable varGrid type: List (of mytable)
Any idea? It's fine CSharp code too.
Regards.
You could declare the counter outside of the foreach lambda, just as you would declare it outside of the scope of a foreach loop.
var x = 1;
myGrid.ForEach(model => myStreamWriter.WriteLine(x++.ToString()));
I am running Mathematica 7, and I am trying to run a simple Do loop in parallel, using ParallelDo. The following standard, sequential code works fine:
len = 10;
A = Table[0, {len}];
Do[
A[[i]] = i*10;
, {i, 1, len}]
However, if I use ParallelDo instead of the standard Do, this code gives error messages:
len = 10;
A = Table[0, {len}];
ParallelDo[
A[[i]] = i*10;
, {i, 1, len}]
The error messages that I get are:
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
General::stop: Further output of Set::noval will be suppressed during this calculation.
General::stop: Further output of Set::noval will be suppressed during this calculation.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Set::noval: Symbol A in part assignment does not have an immediate value.
Is there anything I can do to run this Do loop in parallel?
Thank you!
Andrew DeYoung
Carnegie Mellon University
I get no errors on Mathematica 8.0.1.0.
However, the code probably doesn't do what you intended, because A is copied to each subprocess (and changes are local to that subprocess). Hence
ParallelDo[A[[i]] = i*10; Print#A, {i, 1, len}]
prints
and the final result is A = {0, 0, ..., 0}.
Instead, you should add SetSharedVariable[A] after initializing A. The result is now {10,20,30,40,50,60,70,80,90,100}, as expected.
Any reason not to use a ParallelTable?
ParallelTable[i*10,{i, 1, len}]
Why isn't t:insert(9) working in Lua?
(I want to append a value of 9 to the end of the table)
t = {1,2,3}
table.insert(t, 9) -- works (appends 9 to end of table t)
t:insert(9) -- does NOT work
I thought in general
a.f(a,x) is equalivant to a:f(x) in Lua
While it's true that a:f(x) is simply syntactic sugar for a.f(a,x) that second syntax is not what you have there. Think it through backwards:
The function call you tried is t:insert(9)
So the syntax rule you stated would be t.insert(t, 9)
But the working function call is table.insert(t, 9)
See how the last two aren't the same? So the answer to your question is that insert() isn't a function contained in t, it's in "table".
Since the table methods haven't been associated with t, you either have to call them directly through the table.insert syntax, or define the metatable on t to be table, e.g.:
> t = {1,2,3}
> setmetatable(t, {__index=table})
> t:insert(9)
> print (t[4])
9
You're trying to call an entry in your table called insert, however, in table t, there is none. If you want it to work, what you could do is to set the insert entry to table.insert
t = {insert = table.insert, 1, 2, 3}
t:insert(9)
print(t[4]) -- 9, as you'd expect