Ideal way to handle F2PY compiler with multiple Fortran files - f2py

I'm using F2PY to compile my Fortran codes, but it's a little confusing how I can sort out the dependency between files.
For example, there are file A.f90 and B.f90, that B.f90 uses a module in A.f90. How would I compile these to get a dynamic library? My approach is
with open('A.f90') as fh:
source = fh.read()
with open('B.f90') as fh:
source += fh.read()
f2py.compile(source, ...)
But I don't think it's a good practice. I believe there will be better approaches for this. I would like to compile those independently but use modules from A as a dynamic library when compiling B. Any advice would be appreciated!

You can send the fortran files with dependencies through the extra_args option within the f2py.compile module.
Your code would then look like
with open('B.f90') as fh:
source = fh.read()
f2py.compile(source,....,extra_args=path_to_A.f90)

Related

How to use ceylon js (also with google closure compiler)

Calling a file resulting from the concatenation (bash: cat ... >> app.js) of the following three files:
/usr/share/ceylon/1.2.0/repo/ceylon/language/1.2.0/ceylon.language-1.2.0.js
modules/com/example/helloworld/1.0.0/com.example.helloworld-1.0.0-model.js
modules/com/example/helloworld/1.0.0/com.example.helloworld-1.0.0.js
with the command nodejs app.js does nothing. The same when used in a web page. How do have I to call that javascript program so that it runs without using require.js ?
Please give the rules how ceylon modules and the run function and other functions contained within translate to javascript and are to be called.
How can I get one javascript file from compilation of several ceylon modules without concatenating them manually or with require.js?
The above is without using google closure compiler.
Given the size of 1.6 MB of the language module, it makes no sense to run ceylon-js without using google closure compiler.
Compiling "ceylon.language-1.2.0.js" alone with google closure compiler results in a lot of warnings.
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js /usr/share/ceylon/1.2.0/repo/ceylon/language/1.2.0/ceylon.language-1.2.0.js --js_output_file lib-compiled.js
How can I get rid of those warnings?
In what order do I have to chain together files resulting from ceylon-js with the model file and the language file to compile them in advanced mode with google closure compiler for dead code elimination.
These are 3 questions, really.
A Ceylon module is compiled to a CommonJS module. Concatenating the resulting files won't work because each file is on CommonJS format, which is a big function that returns an object with the exported declarations.
You can compile the modules with the --no-module option to get just the generated code, without it being wrapped in CommonJS format. For the language module, you can copy the file and just delete the first line and the last 5 lines.
I do not yet know how to get rid of the warnings you mention in the second question.
And as for the third question, I would recommend putting the language module first, then the rest of the files. If you have any toplevel declarations with the same name in different modules, you'll have conflicts (only the last declaration will remain), even if they're not shared, since they're all in the same module/unit.
Well, I think require.js can run the compilation of the modules to one file and then run the google-closure-compiler, see: http://www.requirejs.org/docs/optimization.html

Add TCL binding to a fairly large C++ code base

I have a C++ project whose source files are distributed over several trees. Currently each is built into a static library and finally the main() function is compiled and linked with all those libraries through static link.
Now I am using SWIG to add TCL binding to the project. The examples I can find all are simple, just one C++ source.
My understanding is, I need to re-compile each library to be shared libraries, compile the SWIFT binding code to a shared library and link all these libraries into one. In TCL, I load that final one.
For example, here is my source tree:
dir1: s1.c
dir2: s2.c
dir3: swig_binding.c
My action plan to the above source tree is:
Update the Makefiles so that I have
dir1: libs1.so
dir2: libs2.so
dir3: libswig_binding.so
Link the 3 .so files into one, libswig_binding.so
Inside TCL, load libswig_binding.so
Do you see if I miss anything?

cython extensions using cuda

I have a conv net implementation as a C++ class. The class is built on top of a template library ( mshadow ) that generates CUDA code, so it takes the form of a header file. Consequently, it can only be used in files compiled using nvcc. I am now trying to wrap this class in Python for easier loading and saving of parameters, data, etc.
How do I go about wrapping the C++ class using Cython? I looked at npcuda-example, which demonstrates how to write a wrapper pyx file around a C++ class. Unfortunately, in this example, the pyx file compiles to a cpp file. This will not work for me because I need to include the class header in the pyx file and compile it using nvcc.
I believe I could use the setup.py from npcuda-example if there were some way to force the wrapper pyx file to compile to a cu file so that nvcc would be called when distutils tried to compile the extension.
Any ideas?
in the npcuda-example, the wrapper.pyx will combine *.cu by defining
cdef extern from "src/manager.hh"
I guess it is exactly what you want?

using a function which is defined in a scheme file, inside another scheme file

I am new to Scheme.
I wrote a program that defines a function named "run", and I stored it as "Run.scm".
Then I have a "test.scm" file which uses this "run" function which I defined it inside "Run.scm".
I don't know how to include the "Run.scm" inside "test.scm" that I can use "run" function inside test file. Can anyone help me?
Compatible method
If you have a file with source code you can in any Scheme comforming program use load. So in your test you can do this:
% ls
test.scm Run.scm
Contents of test.scm
(load "Run.scm")
(run)
The new and better way (R6RS and later)
If you have a R6RS or a R7RS you have the ability to make a library. It is implementation specific how the library is incorporated into it but not how the source file looks. Read you documentation to how you add the library to your system.
Then, imagine you have made an awesome/utility.scm library. In R6rs/R7RS you would add it to your code like this:
(import (awesome utility))
;; start using the imported code..
(awesome-function '(1 2 3 4)) ; ==> (4 3 2 1)
Alternative by R5RS Schemes
Since R5RS and earlier just had load most implementations made their own way of loading both libraries and source files. eg. Racket has require and Chicken Scheme has import. To use these will lock you in with one supplier, but many libraries do it by building a implementation specific start file that import the other files in the special way to make out the differences between them or make a source file based on parts with gnu make or similar program.

SWIG TCL Static Linking

I am trying to use SWIG to generate wrappers for some of my C++ function calls.
Also, I am trying to do build my own TCL shell so I need to static link the generated SWIG libraries. I have my own main function with a Tcl_AppInit call where I do some prior setup.
To do this what function should I include in my program's Tcl_AppInit call? I found that SWIG_init is not the right function. I even tried Cell_Init where cell is the name of the class in my code, but that doesn't help either.
How do I static link SWIG object files with my own main function and Tcl_Appinit call?
Currently when I use the following command to link my executabel I get the following error:
g++ -o bin/icde src/core/*.o src/read/*.o src/swig/*.o src/icde/*.o -ltk -ltcl
I get the following error:
src/icde/main.o: In function `AppInit(Tcl_Interp*)':
main.cpp:(.text+0xa9): undefined reference to `Cell_Init(Tcl_Interp*)'
collect2: ld returned 1 exit status
I checked the src/swig/cell.o file which has the Cell_Init function or not using objdump:
~> objdump -d src/swig/cell.o | grep Cell_Init
00006461 <Cell_Init>:
646c: 75 0a jne 6478 <Cell_Init+0x17>
I am not sure if I am doing something wrong while linking.
------------------- UPDATE ----------------------------
I found that including the swig/swig.cxx file directly in the main file which calls the Tcl_AppInit function resolves the linking issue. Is there a reason for this.
Isn't it possible to create and seprately link the swig file and the file with the main function?
In general, with SWIG you'll end up with a bunch of generated source files that you compile. The normal thing you do then is package them up into a shared library (with appropriate bound dependencies on other shared libraries) that can be imported into a Tcl runtime with the load command.
But you don't want that this time. Instead, you want the object files that you would use to make that shared lib, and you want to include them in the instructions to build an executable along with the object file that holds your main and Tcl_AppInit. You also need to make sure that when linking your main executable that you make it dependent on those external shared libraries; executable building requires that you satisfy all dependencies and make all symbols be bound to their definitions. (You can use a static library to make this easier: it combines a bunch of object files into one file. There's very little difference to just using the object files from it though; in particular, static libraries aren't bound to their dependencies.)
Finally, you do want to include a call to Cell_Init in your Tcl_AppInit. That's the right place to put it (well, as long as you're not arranging for the package to be loaded into sub-interpreters). If it was failing before, that was because you'd got your linking wrong. (Tip: linkers work best when objects and libraries on the link line only depend on things later on the link line. Getting the link order right is a bit of a black art when you've got a complex build!)