I am trying to pre-process a Fortran module (pmu.F90) with pgf90. The module is as follows:
module pmu
module variables
contains
include 'file.F90'
end module
file.F90 is a subroutine which contains the following lines:
#ifdef PART
startm1 = xstart - 1
startm2 = xstart - 2
endp1 = xend + 1
endp2 = xend + 2
#else
startm1 = xstart - 1
startm2 = xstart - 1
endp1 = xend + 1
endp2 = xend + 1
#endif
If I compile with:
pgf90 -DPART -Mfree -Mbounds -Msave -Mdclchk -r8 -Mpreprocess -I/data/users/mrosso/fftw3/include -c pmu.F90
I get
PGF90-S-0021-Label field of continuation line is not blank.
Well, the included file contains no procedures, which is what you need between the "contains" and "end module" statements in the module pmu file.
Another issue with using CPP with Fortran is that the Fortran include statement is not the same as the CPP #include. In particular, their interaction is not specified. That is, if you're including a file which itself contains CPP directives, it's one less thing that can go wrong if you use #include instead.
Related
So I am trying to parse out #define statements out of a C file using Lua patterns, but there is the case on multiline defines, where you might escape the newline character with a backslash.
In order for me to know where the define ends, I need to be able to define backslash + linebreak as if it were a single character so I can get the complement of that and then use the * quantifier on it and then count until the first non-escaped linebreak.
How do I do that?
You cannot simply replace all occurrences of "\\\n" with some temporary symbol, because a problem will arise with the line "c\\\\\n" in the following example.
Instead, you should implement mini-scanner for C source files:
local str = [[
#define x y
#define a b\
c\\
d();
#define z
]]
-- Print all #defines found in the text
local line = ""
for char in str:gmatch"\\?." do
if char == "\n" then
if line:sub(1, #"#define") == "#define" then
print(line)
end
line = ""
else
line = line..char
end
end
Output:
#define x y
#define a b\
c\\
#define z
I have a small lua function to check if a file exists
function file_exists( filePath )
local handler = io.open( filePath )
if handler then
io.close( handler )
return true
end
return false
end
However, this will always return false when the file path contains special chars such as German umlauts (äöü). Is there any way around this?
Thanks a lot!
utf8_to_cp1252 = (
function(cp1252_description)
local unicode_to_1252 = {}
for code, unicode in cp1252_description:gmatch'\n0x(%x%x)%s+0x(%x+)' do
unicode_to_1252[tonumber(unicode, 16)] = tonumber(code, 16)
end
local undefined = ('?'):byte()
return
function (utf8str)
local pos, result = 1, {}
while pos <= #utf8str do
local code, size = utf8str:byte(pos, pos), 1
if code >= 0xC0 and code < 0xFE then
local mask = 64
code = code - 128
repeat
local next_byte = utf8str:byte(pos+size, pos+size) or 0
if next_byte >= 0x80 and next_byte < 0xC0 then
code, size = (code - mask - 2) * 64 + next_byte, size+1
else
code, size = utf8str:byte(pos, pos), 1
end
mask = mask * 32
until code < mask
end
pos = pos + size
table.insert(result,
string.char(unicode_to_1252[code] or undefined))
end
return table.concat(result)
end
end
)[[
download
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
and insert the whole text here:
#
# Name: cp1252 to Unicode table
# Unicode version: 2.0
# Table version: 2.01
..................................
0xFD 0x00FD #LATIN SMALL LETTER Y WITH ACUTE
0xFE 0x00FE #LATIN SMALL LETTER THORN
0xFF 0x00FF #LATIN SMALL LETTER Y WITH DIAERESIS
]]
Usage:
cp1252_filename = utf8_to_cp1252(your_utf8_filename)
Now you can use cp1252_filename to invoke io.open(), os.rename(), os.execute() and other functions from standard Lua library.
Lua and its tiny standard library is platform neutral and is not aware of correct Windows functions to read full unicode names. You can use winapi module to get some Windows-specific functions for this task. Note that it requires short name generation to be enabled on target disk.
local handler = io.open( winapi.short_path(filePath) )
if handler then
-- etc
end
It can also be easily installed through LuaRocks: luarocks install winapi.
After a series of pains, I have installed Theano on a machine with AMD graphics card - Radeon HD 5450 (Cedar).
Now, consider a following code.
import numpy
import theano
import theano.tensor as T
rng = numpy.random
N = 400 #number of samples
feats = 784 #dimensionality of features
D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=2))
training_steps = 10000
# theano symbolic variables
x = T.matrix("x")
y = T.vector("y")
w = theano.shared(rng.randn(784), name="w")
b = theano.shared(0., name="b")
print("Initial Model:")
print(str(w.get_value()) + " " + str(b.get_value()) )
p_1 = 1/(1 + T.exp(-T.dot(x, w) - b)) # probability of target being 1
prediction = p_1 > 0.5 # prediction threshold
xent = -y * T.log(p_1) - (1-y)*T.log(1-p_1) # cross-entropy loss function
cost = xent.mean() + 0.01 * (w**2).sum() # cost - to be minimized
gw, gb = T.grad(cost, [w, b])
#compile it
train = theano.function(
inputs = [x, y],
outputs = [prediction, xent],
updates = {w: w - 0.1*gw, b: b - 0.1*gb} )
predict = theano.function(inputs = [x], outputs = prediction)
#train it
for i in range (training_steps):
pred, err = train(D[0], D[1])
print("Final Model: ")
print(str(w.get_value()) + " " + str(b.get_value()) )
print("Target values for D: " + str(D[1]))
print("Predictions on D: " + str(D[0]))
I think this code should work just fine. But I get a series of errors:
ERROR (theano.gof.opt): Optimization failure due to: local_gpua_hgemm
ERROR (theano.gof.opt): node: dot(x.T, Elemwise{sub,no_inplace}.0)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 1772, in process_node
replacements = lopt.transform(node)
File "/home/user/anaconda3/lib/python3.5/site-packages/theano/sandbox/gpuarray/opt.py", line 140, in local_opt
new_op = maker(node, context_name)
File "/home/user/anaconda3/lib/python3.5/site-packages/theano/sandbox/gpuarray/opt.py", line 732, in local_gpua_hgemm
if nvcc_compiler.nvcc_version < '7.5':
TypeError: unorderable types: NoneType() < str()
And I get the same set of messages multiple times. Then at the end:
File "/home/user/anaconda3/lib/python3.5/site-packages/pygpu-0.2.1-py3.5-linux-x86_64.egg/pygpu/elemwise.py", line 286, in __init__
**self.flags)
File "pygpu/gpuarray.pyx", line 1950, in pygpu.gpuarray.GpuKernel.__cinit__ (pygpu/gpuarray.c:24214)
File "pygpu/gpuarray.pyx", line 467, in pygpu.gpuarray.kernel_init (pygpu/gpuarray.c:7174)
pygpu.gpuarray.UnsupportedException: ('The following error happened while compiling the node', GpuElemwise{Composite{((-i0) - i1)}}[(0, 0)]<gpuarray>(GpuFromHost<None>.0, InplaceGpuDimShuffle{x}.0), '\n', b'Device does not support operation')
Does this mean I cannot use this GPU or I have done something wrong in my code. Moreover, from the errors, it seems there is been a search for nvcc. But I do not have CUDA, I have opencl.
>>> import theano
Mapped name None to device opencl0:0: Cedar
also:
>>> from theano import config
>>> config.device
'opencl0:0'
>>> config.cuda
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fba9dee7d30>
>>> config.nvcc
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fba9e5967f0>
>>> config.gpu
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fbaa9f61828>
So how do I go from here? Is there way to make sure clcc is searched instead of nvcc.
PS_1: hello world works.
PS_2: System = 14.04 64 bit
OpenCL is not yet supported by Theano. As a result, only NVIDIA GPUs are supported.
The status of OpenCL is recorded on GitHub.
You need to disable GPU operation by setting device=cpu in your Theano config. There are multiple ways to do this (i.e. via THEANO_FLAGS environment variable or via a .theanorc file; see documentation).
Before running the script, try setting
export THEANO_FLAGS=device=cpu,floatX=float64
Your situation may need additional configuration options. See the documentation for more.
After compiling the reMail project with no error, one of the warnings is:
remail-iphone/sqlite3/sqlite3.c:18703:15: Signed shift result
(0x1F0000000) requires 34 bits to represent, but 'int' only has 32
bits
i.e. (0x1f<<28) in the following code:
if (!(a&0x80))
{
a &= (0x1f<<28)|(0x7f<<14)|(0x7f);
b &= (0x7f<<14)|(0x7f);
b = b<<7;
a |= b;
s = s>>11;
*v = ((u64)s)<<32 | a;
return 7;
}
What's the proper way to kill this warning for iOS (32-bit)?
reMail for iPhone seems to be using an old version of SQLite (3.6.15). If I'm not mistaken, the following commit should fix exactly this problem: http://www.sqlite.org/src/info/587109c81a9cf479?sbs=0
if (!(a&0x80))
{
/* assert( ((0xFF<<28)|(0x7f<<14)|(0x7f))==0xf01fc07f ); */
a &= 0xf01fc07f;
b &= (0x7f<<14)|(0x7f);
b = b<<7;
a |= b;
s = s>>11;
*v = ((u64)s)<<32 | a;
return 7;
}
However, there might be other code sections where this problem occurs. The mentioned link shows two instances in util.c, but since sqlite.c is "an amalgamation of many separate C source files from SQLite", you may find additional occurences.
Maybe reMail would work with a recent version of SQLite, too...
I am playing a little bit with Lua.
I came across the following code snippet that have an unexpected behavior:
a = 3;
b = 5;
c = a-- * b++; // some computation
print(a, b, c);
Lua runs the program without any error but does not print 2 6 15 as expected. Why ?
-- starts a single line comment, like # or // in other languages.
So it's equivalent to:
a = 3;
b = 5;
c = a
LUA doesn't increment and decrement with ++ and --. -- will instead start a comment.
There isn't and -- and ++ in lua.
so you have to use a = a + 1 or a = a -1 or something like that
If you want 2 6 15 as the output, try this code:
a = 3
b = 5
c = a * b
a = a - 1
b = b + 1
print(a, b, c)
This will give
3 5 3
because the 3rd line will be evaluated as c = a.
Why? Because in Lua, comments starts with --. Therefore, c = a-- * b++; // some computation is evaluated as two parts:
expression: c = a
comment: * b++; //// some computation
There are 2 problems in your Lua code:
a = 3;
b = 5;
c = a-- * b++; // some computation
print(a, b, c);
One, Lua does not currently support incrementation. A way to do this is:
c = a - 1 * b + 1
print(a, b, c)
Two, -- in Lua is a comment, so using a-- just translates to a, and the comment is * b++; // some computation.
Three, // does not work in Lua, use -- for comments.
Also it's optional to use ; at the end of every line.
You can do the following:
local default = 0
local max = 100
while default < max do
default = default + 1
print(default)
end
EDIT: Using SharpLua in C# incrementing/decrementing in lua can be done in shorthand like so:
a+=1 --increment by some value
a-=1 --decrement by some value
In addition, multiplication/division can be done like so:
a*=2 --multiply by some value
a/=2 --divide by some value
The same method can be used if adding, subtracting, multiplying or dividing one variable by another, like so:
a+=b
a-=b
a/=b
a*=b
This is much simpler and tidier and I think a lot less complicated, but not everybody will share my view.
Hope this helps!