diff --git a/.gitignore b/.gitignore index 147680c..f714e62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,81 +1,120 @@ - -# Created by https://www.gitignore.io/api/c,c++,macos,windows,linux - -### C ### -# Prerequisites -*.d - -# Object files -*.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -modules.order -Module.symvers -Mkfile.old -dkms.conf - - -### C++ ### -# Prerequisites - -# Compiled Object files -*.slo - -# Precompiled Headers - -# Compiled Dynamic libraries - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai - -# Executables - - -### macOS ### + +# Created by https://www.gitignore.io/api/c,c++,macos,windows,linux + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +modules.order +Module.symvers +Mkfile.old +dkms.conf + + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables +*.exe +*.out +*.app + + +### Fortran ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + + + +### macOS ### *.DS_Store .AppleDouble .LSOverride @@ -98,72 +137,74 @@ Icon Network Trash Folder Temporary Items .apdisk - - -### Windows ### -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - - - -#other -*.zip - -*.pdf -*.ppt - - -blaswrap.h -cblas_f77.h -cblas.h -clapack.h -f2c.h -lapack_config.h -lapacke_mangling_with_flags.h -lapacke_mangling.h -lapack_utils.h -lapacke.h - - -libblas.a -librefblas.a -libcblas.a -libf2c.a -libgfortran.dylib -liblapack.a -liblapacke.a -liblapacke.dylib -librefblas.a -libtmglib.a + + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + + + +#other +*.zip +*.pdf +*.ppt + + +blaswrap.h +cblas_f77.h +cblas.h +clapack.h +f2c.h +lapack_config.h +lapacke_mangling_with_flags.h +lapacke_mangling.h +lapack_utils.h +lapacke.h + + +libblas.a +librefblas.a +libcblas.a +libf2c.a +libgfortran.dylib +liblapack.a +liblapacke.a +liblapacke.dylib +librefblas.a +libtmglib.a + + +*.swp diff --git a/A_fortran/Ex01/Makefile b/A_fortran/Ex01/Makefile new file mode 100644 index 0000000..d171a75 --- /dev/null +++ b/A_fortran/Ex01/Makefile @@ -0,0 +1,9 @@ +all: + gfortran -c -std=legacy test1F.f + gcc -c test1C.c + gfortran -o test1.out -std=legacy test1C.o test1F.o + rm -rf *.o + + +clean : + rm -rf *.out *~ *.bak *.o diff --git a/A_fortran/Ex01/README.md b/A_fortran/Ex01/README.md new file mode 100644 index 0000000..0d09623 --- /dev/null +++ b/A_fortran/Ex01/README.md @@ -0,0 +1,56 @@ +# Abstract: +This example shows how we can call a C function from FORTRAN and how to pass a string back to C in a proper way. The code is written in legacy FORTRAN 77 standard. + +# Source: + http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html + + +# Points: +1. when you pass a string from Fortran to C you actually pass two variables including a pointer to an array of single characters (string) and also the length of the array? +2. when you pass a string to C you need to first be sure that you allocate at least one letter more than the characters you need. In FORTRAN strings are not NULL ended, so the "\0" must be added at the end of the string in C. +3. common in FORTRAN is the similar to struct in C + in C: + +```c +extern struct { + int i; + char c; + ... +} mystruct_; +``` + + in FORTRAN + +```fortran +integer i +character c +... +common/mystruct/ i, c, ... +``` + +where the attributes can be accesed via `.att` convention. Except `common` defines only one instance of the struct globally. It just groups the attributes and make them global. It can be request like struct though. + +4. when FORTRAN passes a variable to C function, the C function receives a pointer? +5. when you want to call a C function in Fortran you don't need to declare a dummy in the Fortran code, unlike C Fortran doesn't care if the function is not declared and then on run time it will look for the function (how about variables and structs?) +6. when passing variables, functions or srtucts from/to C/Fortran it is Case-insensitive. but you should be careful that inside each world it is case sensitive. + + + +# Questions: +1. this pages says when you want to call a C function from fortran you need to also declare it as external but here it works properly without declaring! + https://docs.oracle.com/cd/E19059-01/stud.9/817-6694/11_cfort.html + + + + +# Fortran points: +1. in FORTRAN 77 and Fortran 90 (?) one can use the `write` command to print to terminal: + +```fortran +write (, (, , ...)) var_1, var_2, ... +``` +where `` specifies the output (terminals, files ...). One can put `6` for the standard terminal or `*` for the default output (which should be also the stardard terminal). The `` specfies how each variable should be printed depending to their data type. If `*` then the default formating will be used. More formating options for integers `Iw`, reals `Fw.d` and strings `Aw` can be found. Alternatively one can put a line lable instead and then specifiy the format for mutiple `write`/`print` commands: + +```fortran +10 format (, , ...) +``` diff --git a/A_fortran/test1/test1C.c b/A_fortran/Ex01/test1C.c similarity index 100% rename from A_fortran/test1/test1C.c rename to A_fortran/Ex01/test1C.c diff --git a/A_fortran/test1/test1F.f b/A_fortran/Ex01/test1F.f similarity index 95% rename from A_fortran/test1/test1F.f rename to A_fortran/Ex01/test1F.f index 6be8faf..c675cfd 100644 --- a/A_fortran/test1/test1F.f +++ b/A_fortran/Ex01/test1F.f @@ -1,7 +1,7 @@ program test integer ii, jj, kk - common/IjK/ ii, jj, kk + common/IJK/ ii, jj, kk real*8 ff character*25 cc diff --git a/A_fortran/test2/Makefile b/A_fortran/Ex02/Makefile similarity index 100% rename from A_fortran/test2/Makefile rename to A_fortran/Ex02/Makefile diff --git a/A_fortran/test2/readme.txt b/A_fortran/Ex02/readme.txt similarity index 100% rename from A_fortran/test2/readme.txt rename to A_fortran/Ex02/readme.txt diff --git a/A_fortran/test2/test2C.c b/A_fortran/Ex02/test2C.c similarity index 100% rename from A_fortran/test2/test2C.c rename to A_fortran/Ex02/test2C.c diff --git a/A_fortran/test2/test2F.f b/A_fortran/Ex02/test2F.f similarity index 100% rename from A_fortran/test2/test2F.f rename to A_fortran/Ex02/test2F.f diff --git a/A_fortran/Ex03/CSUBS.c b/A_fortran/Ex03/CSUBS.c new file mode 100644 index 0000000..364c012 --- /dev/null +++ b/A_fortran/Ex03/CSUBS.c @@ -0,0 +1,14 @@ +/* File CSUBS.C */ + +#include + +int fact_(int* np) { + int n = *np; + if (n > 1) { + int m = n-1; + return (n * fact_(&m)); + }; + return 1; +} + +void pythagoras_(float* a, float* b, float* c) { *c = sqrt(*a * *a + *b * *b); } diff --git a/A_fortran/Ex03/FORMAIN.FOR b/A_fortran/Ex03/FORMAIN.FOR new file mode 100644 index 0000000..1b397fa --- /dev/null +++ b/A_fortran/Ex03/FORMAIN.FOR @@ -0,0 +1,21 @@ +C File FORMAIN.FOR +C + INTERFACE + INTEGER*4 FUNCTION Fact (n) + INTEGER*4 n + END + END INTERFACE + + INTERFACE + SUBROUTINE Pythagoras (a,b,c) + REAL*4 a + REAL*4 b + REAL*4 c + END + END INTERFACE + + REAL*4 c + WRITE (*,*) 'Factorial of 7 is ', Fact (7) + CALL Pythagoras (30.0, 40.0, c) + WRITE (*,*) 'Hypotenuse if sides 30, 40 is ', c + END diff --git a/A_fortran/Ex03/Makefile b/A_fortran/Ex03/Makefile new file mode 100644 index 0000000..dc9fbfc --- /dev/null +++ b/A_fortran/Ex03/Makefile @@ -0,0 +1,9 @@ +all: + gfortran -c -std=legacy FORMAIN.FOR + gcc -c CSUBS.c + gfortran -o result.out -std=legacy FORMAIN.o CSUBS.o + rm -rf *.o + + +clean : + rm -rf *.out *~ *.bak *.o diff --git a/A_fortran/Ex03/readme.md b/A_fortran/Ex03/readme.md new file mode 100644 index 0000000..cc44838 --- /dev/null +++ b/A_fortran/Ex03/readme.md @@ -0,0 +1,2 @@ +source: https://msdn.microsoft.com/en-us/library/aa279034(v=vs.60).aspx + diff --git a/A_fortran/test4/Makefile b/A_fortran/Ex04/Makefile similarity index 100% rename from A_fortran/test4/Makefile rename to A_fortran/Ex04/Makefile diff --git a/A_fortran/test4/README b/A_fortran/Ex04/README similarity index 100% rename from A_fortran/test4/README rename to A_fortran/Ex04/README diff --git a/A_fortran/test4/cpp_main_0.cpp b/A_fortran/Ex04/cpp_main_0.cpp similarity index 100% rename from A_fortran/test4/cpp_main_0.cpp rename to A_fortran/Ex04/cpp_main_0.cpp diff --git a/A_fortran/test4/cpp_main_1.cpp b/A_fortran/Ex04/cpp_main_1.cpp similarity index 100% rename from A_fortran/test4/cpp_main_1.cpp rename to A_fortran/Ex04/cpp_main_1.cpp diff --git a/A_fortran/test4/fortran_matrix_multiply.f90 b/A_fortran/Ex04/fortran_matrix_multiply.f90 similarity index 100% rename from A_fortran/test4/fortran_matrix_multiply.f90 rename to A_fortran/Ex04/fortran_matrix_multiply.f90 diff --git a/A_fortran/test5/CMAIN.c b/A_fortran/Ex05/CMAIN.c similarity index 100% rename from A_fortran/test5/CMAIN.c rename to A_fortran/Ex05/CMAIN.c diff --git a/A_fortran/test5/FORSUBS.FOR b/A_fortran/Ex05/FORSUBS.FOR similarity index 100% rename from A_fortran/test5/FORSUBS.FOR rename to A_fortran/Ex05/FORSUBS.FOR diff --git a/A_fortran/test5/Makefile b/A_fortran/Ex05/Makefile similarity index 100% rename from A_fortran/test5/Makefile rename to A_fortran/Ex05/Makefile diff --git a/A_fortran/test5/readme.txt b/A_fortran/Ex05/readme.txt similarity index 100% rename from A_fortran/test5/readme.txt rename to A_fortran/Ex05/readme.txt diff --git a/A_fortran/test6/Makefile b/A_fortran/Ex06/Makefile similarity index 100% rename from A_fortran/test6/Makefile rename to A_fortran/Ex06/Makefile diff --git a/A_fortran/test6/readme.txt b/A_fortran/Ex06/readme.txt similarity index 100% rename from A_fortran/test6/readme.txt rename to A_fortran/Ex06/readme.txt diff --git a/A_fortran/test6/test6C.c b/A_fortran/Ex06/test6C.c similarity index 100% rename from A_fortran/test6/test6C.c rename to A_fortran/Ex06/test6C.c diff --git a/A_fortran/test6/test6F.f b/A_fortran/Ex06/test6F.f similarity index 100% rename from A_fortran/test6/test6F.f rename to A_fortran/Ex06/test6F.f diff --git a/A_fortran/test7/Makefile b/A_fortran/Ex07/Makefile similarity index 100% rename from A_fortran/test7/Makefile rename to A_fortran/Ex07/Makefile diff --git a/A_fortran/test7/cfunction1.c b/A_fortran/Ex07/cfunction1.c similarity index 100% rename from A_fortran/test7/cfunction1.c rename to A_fortran/Ex07/cfunction1.c diff --git a/A_fortran/test7/cppfunction.cpp b/A_fortran/Ex07/cppfunction.cpp similarity index 100% rename from A_fortran/test7/cppfunction.cpp rename to A_fortran/Ex07/cppfunction.cpp diff --git a/A_fortran/test7/cprogram.c b/A_fortran/Ex07/cprogram.c similarity index 100% rename from A_fortran/test7/cprogram.c rename to A_fortran/Ex07/cprogram.c diff --git a/A_fortran/test7/ffunction.f b/A_fortran/Ex07/ffunction.f similarity index 100% rename from A_fortran/test7/ffunction.f rename to A_fortran/Ex07/ffunction.f diff --git a/A_fortran/test7/readme.txt b/A_fortran/Ex07/readme.txt similarity index 100% rename from A_fortran/test7/readme.txt rename to A_fortran/Ex07/readme.txt diff --git a/A_fortran/test8/Makefile b/A_fortran/Ex08/Makefile similarity index 100% rename from A_fortran/test8/Makefile rename to A_fortran/Ex08/Makefile diff --git a/A_fortran/test8/cfunction1.c b/A_fortran/Ex08/cfunction1.c similarity index 100% rename from A_fortran/test8/cfunction1.c rename to A_fortran/Ex08/cfunction1.c diff --git a/A_fortran/test8/cppfunction.cpp b/A_fortran/Ex08/cppfunction.cpp similarity index 100% rename from A_fortran/test8/cppfunction.cpp rename to A_fortran/Ex08/cppfunction.cpp diff --git a/A_fortran/test8/cppprogram.cpp b/A_fortran/Ex08/cppprogram.cpp similarity index 100% rename from A_fortran/test8/cppprogram.cpp rename to A_fortran/Ex08/cppprogram.cpp diff --git a/A_fortran/test8/ffunction.f b/A_fortran/Ex08/ffunction.f similarity index 100% rename from A_fortran/test8/ffunction.f rename to A_fortran/Ex08/ffunction.f diff --git a/A_fortran/test9/Makefile b/A_fortran/Ex09/Makefile similarity index 100% rename from A_fortran/test9/Makefile rename to A_fortran/Ex09/Makefile diff --git a/A_fortran/test9/cfunction1.c b/A_fortran/Ex09/cfunction1.c similarity index 100% rename from A_fortran/test9/cfunction1.c rename to A_fortran/Ex09/cfunction1.c diff --git a/A_fortran/test9/cppfunction.cpp b/A_fortran/Ex09/cppfunction.cpp similarity index 100% rename from A_fortran/test9/cppfunction.cpp rename to A_fortran/Ex09/cppfunction.cpp diff --git a/A_fortran/test9/ffunction.f b/A_fortran/Ex09/ffunction.f similarity index 100% rename from A_fortran/test9/ffunction.f rename to A_fortran/Ex09/ffunction.f diff --git a/A_fortran/test9/fprogram.f b/A_fortran/Ex09/fprogram.f similarity index 100% rename from A_fortran/test9/fprogram.f rename to A_fortran/Ex09/fprogram.f diff --git a/A_fortran/test10/Makefile b/A_fortran/Ex10/Makefile similarity index 100% rename from A_fortran/test10/Makefile rename to A_fortran/Ex10/Makefile diff --git a/A_fortran/test10/main.c b/A_fortran/Ex10/main.c similarity index 100% rename from A_fortran/test10/main.c rename to A_fortran/Ex10/main.c diff --git a/A_fortran/test10/ranvec.f90 b/A_fortran/Ex10/ranvec.f90 similarity index 100% rename from A_fortran/test10/ranvec.f90 rename to A_fortran/Ex10/ranvec.f90 diff --git a/A_fortran/test10/readme.txt b/A_fortran/Ex10/readme.txt similarity index 100% rename from A_fortran/test10/readme.txt rename to A_fortran/Ex10/readme.txt diff --git a/A_fortran/test11/Makefile b/A_fortran/Ex11/Makefile similarity index 100% rename from A_fortran/test11/Makefile rename to A_fortran/Ex11/Makefile diff --git a/A_fortran/test11/add.f b/A_fortran/Ex11/add.f similarity index 100% rename from A_fortran/test11/add.f rename to A_fortran/Ex11/add.f diff --git a/A_fortran/test11/redme.txt b/A_fortran/Ex11/redme.txt similarity index 100% rename from A_fortran/test11/redme.txt rename to A_fortran/Ex11/redme.txt diff --git a/A_fortran/test11/test11.c b/A_fortran/Ex11/test11.c similarity index 100% rename from A_fortran/test11/test11.c rename to A_fortran/Ex11/test11.c diff --git a/A_fortran/test12/Makefile b/A_fortran/Ex12/Makefile similarity index 100% rename from A_fortran/test12/Makefile rename to A_fortran/Ex12/Makefile diff --git a/A_fortran/test12/driver.f b/A_fortran/Ex12/driver.f similarity index 100% rename from A_fortran/test12/driver.f rename to A_fortran/Ex12/driver.f diff --git a/A_fortran/test12/readme.txt b/A_fortran/Ex12/readme.txt similarity index 100% rename from A_fortran/test12/readme.txt rename to A_fortran/Ex12/readme.txt diff --git a/A_fortran/test12/testdot.cpp b/A_fortran/Ex12/testdot.cpp similarity index 100% rename from A_fortran/test12/testdot.cpp rename to A_fortran/Ex12/testdot.cpp diff --git a/A_fortran/test12/testmat.cpp b/A_fortran/Ex12/testmat.cpp similarity index 100% rename from A_fortran/test12/testmat.cpp rename to A_fortran/Ex12/testmat.cpp diff --git a/A_fortran/test12/testret.cpp b/A_fortran/Ex12/testret.cpp similarity index 100% rename from A_fortran/test12/testret.cpp rename to A_fortran/Ex12/testret.cpp diff --git a/A_fortran/test13/Makefile b/A_fortran/Ex13/Makefile similarity index 100% rename from A_fortran/test13/Makefile rename to A_fortran/Ex13/Makefile diff --git a/A_fortran/test13/readme.txt b/A_fortran/Ex13/readme.txt similarity index 100% rename from A_fortran/test13/readme.txt rename to A_fortran/Ex13/readme.txt diff --git a/A_fortran/test13/test13C.c b/A_fortran/Ex13/test13C.c similarity index 100% rename from A_fortran/test13/test13C.c rename to A_fortran/Ex13/test13C.c diff --git a/A_fortran/test13/test13F.f b/A_fortran/Ex13/test13F.f similarity index 100% rename from A_fortran/test13/test13F.f rename to A_fortran/Ex13/test13F.f diff --git a/A_fortran/test14/Makefile b/A_fortran/Ex14/Makefile similarity index 100% rename from A_fortran/test14/Makefile rename to A_fortran/Ex14/Makefile diff --git a/A_fortran/test14/readme.txt b/A_fortran/Ex14/readme.txt similarity index 100% rename from A_fortran/test14/readme.txt rename to A_fortran/Ex14/readme.txt diff --git a/A_fortran/test14/test13C.c b/A_fortran/Ex14/test13C.c similarity index 100% rename from A_fortran/test14/test13C.c rename to A_fortran/Ex14/test13C.c diff --git a/A_fortran/test14/test13F.f b/A_fortran/Ex14/test13F.f similarity index 100% rename from A_fortran/test14/test13F.f rename to A_fortran/Ex14/test13F.f diff --git a/A_fortran/test15/Makefile b/A_fortran/Ex15/Makefile similarity index 100% rename from A_fortran/test15/Makefile rename to A_fortran/Ex15/Makefile diff --git a/A_fortran/test15/readme.txt b/A_fortran/Ex15/readme.txt similarity index 100% rename from A_fortran/test15/readme.txt rename to A_fortran/Ex15/readme.txt diff --git a/A_fortran/test15/test13C.c b/A_fortran/Ex15/test13C.c similarity index 100% rename from A_fortran/test15/test13C.c rename to A_fortran/Ex15/test13C.c diff --git a/A_fortran/test15/test13F.f b/A_fortran/Ex15/test13F.f similarity index 100% rename from A_fortran/test15/test13F.f rename to A_fortran/Ex15/test13F.f diff --git a/A_fortran/test16/Makefile b/A_fortran/Ex16/Makefile similarity index 100% rename from A_fortran/test16/Makefile rename to A_fortran/Ex16/Makefile diff --git a/A_fortran/test16/readme.txt b/A_fortran/Ex16/readme.txt similarity index 100% rename from A_fortran/test16/readme.txt rename to A_fortran/Ex16/readme.txt diff --git a/A_fortran/test16/test13C.c b/A_fortran/Ex16/test13C.c similarity index 100% rename from A_fortran/test16/test13C.c rename to A_fortran/Ex16/test13C.c diff --git a/A_fortran/test16/test13F.f b/A_fortran/Ex16/test13F.f similarity index 100% rename from A_fortran/test16/test13F.f rename to A_fortran/Ex16/test13F.f diff --git a/A_fortran/test17/Makefile b/A_fortran/Ex17/Makefile similarity index 100% rename from A_fortran/test17/Makefile rename to A_fortran/Ex17/Makefile diff --git a/A_fortran/test17/readme.txt b/A_fortran/Ex17/readme.txt similarity index 100% rename from A_fortran/test17/readme.txt rename to A_fortran/Ex17/readme.txt diff --git a/A_fortran/test17/test13C.c b/A_fortran/Ex17/test13C.c similarity index 100% rename from A_fortran/test17/test13C.c rename to A_fortran/Ex17/test13C.c diff --git a/A_fortran/test17/test13F.f b/A_fortran/Ex17/test13F.f similarity index 100% rename from A_fortran/test17/test13F.f rename to A_fortran/Ex17/test13F.f diff --git a/A_fortran/test18/Makefile b/A_fortran/Ex18/Makefile similarity index 100% rename from A_fortran/test18/Makefile rename to A_fortran/Ex18/Makefile diff --git a/A_fortran/test18/readme.txt b/A_fortran/Ex18/readme.txt similarity index 100% rename from A_fortran/test18/readme.txt rename to A_fortran/Ex18/readme.txt diff --git a/A_fortran/test18/test13C.c b/A_fortran/Ex18/test13C.c similarity index 100% rename from A_fortran/test18/test13C.c rename to A_fortran/Ex18/test13C.c diff --git a/A_fortran/test18/test13F.f90 b/A_fortran/Ex18/test13F.f90 similarity index 100% rename from A_fortran/test18/test13F.f90 rename to A_fortran/Ex18/test13F.f90 diff --git a/A_fortran/test19/Makefile b/A_fortran/Ex19/Makefile similarity index 100% rename from A_fortran/test19/Makefile rename to A_fortran/Ex19/Makefile diff --git a/A_fortran/test19/readme.txt b/A_fortran/Ex19/readme.txt similarity index 100% rename from A_fortran/test19/readme.txt rename to A_fortran/Ex19/readme.txt diff --git a/A_fortran/test19/test13C.c b/A_fortran/Ex19/test13C.c similarity index 100% rename from A_fortran/test19/test13C.c rename to A_fortran/Ex19/test13C.c diff --git a/A_fortran/test19/test13F.f90 b/A_fortran/Ex19/test13F.f90 similarity index 100% rename from A_fortran/test19/test13F.f90 rename to A_fortran/Ex19/test13F.f90 diff --git a/A_fortran/test20/Makefile b/A_fortran/Ex20/Makefile similarity index 100% rename from A_fortran/test20/Makefile rename to A_fortran/Ex20/Makefile diff --git a/A_fortran/test20/readme.txt b/A_fortran/Ex20/readme.txt similarity index 100% rename from A_fortran/test20/readme.txt rename to A_fortran/Ex20/readme.txt diff --git a/A_fortran/test20/test13C.c b/A_fortran/Ex20/test13C.c similarity index 100% rename from A_fortran/test20/test13C.c rename to A_fortran/Ex20/test13C.c diff --git a/A_fortran/test20/test13F.f90 b/A_fortran/Ex20/test13F.f90 similarity index 100% rename from A_fortran/test20/test13F.f90 rename to A_fortran/Ex20/test13F.f90 diff --git a/A_fortran/test21/Makefile b/A_fortran/Ex21/Makefile similarity index 100% rename from A_fortran/test21/Makefile rename to A_fortran/Ex21/Makefile diff --git a/A_fortran/test21/readme.txt b/A_fortran/Ex21/readme.txt similarity index 100% rename from A_fortran/test21/readme.txt rename to A_fortran/Ex21/readme.txt diff --git a/A_fortran/test21/test13C.c b/A_fortran/Ex21/test13C.c similarity index 100% rename from A_fortran/test21/test13C.c rename to A_fortran/Ex21/test13C.c diff --git a/A_fortran/test21/test13F.f90 b/A_fortran/Ex21/test13F.f90 similarity index 100% rename from A_fortran/test21/test13F.f90 rename to A_fortran/Ex21/test13F.f90 diff --git a/A_fortran/test22/Ctest.c b/A_fortran/Ex22/Ctest.c similarity index 100% rename from A_fortran/test22/Ctest.c rename to A_fortran/Ex22/Ctest.c diff --git a/A_fortran/test22/Ftest.FOR b/A_fortran/Ex22/Ftest.FOR similarity index 100% rename from A_fortran/test22/Ftest.FOR rename to A_fortran/Ex22/Ftest.FOR diff --git a/A_fortran/test22/Makefile b/A_fortran/Ex22/Makefile similarity index 100% rename from A_fortran/test22/Makefile rename to A_fortran/Ex22/Makefile diff --git a/A_fortran/test22/readme.txt b/A_fortran/Ex22/readme.txt similarity index 100% rename from A_fortran/test22/readme.txt rename to A_fortran/Ex22/readme.txt diff --git a/A_fortran/test23/Makefile b/A_fortran/Ex23/Makefile similarity index 100% rename from A_fortran/test23/Makefile rename to A_fortran/Ex23/Makefile diff --git a/A_fortran/test23/readme.txt b/A_fortran/Ex23/readme.txt similarity index 100% rename from A_fortran/test23/readme.txt rename to A_fortran/Ex23/readme.txt diff --git a/A_fortran/test23/tst01.cc b/A_fortran/Ex23/tst01.cc similarity index 100% rename from A_fortran/test23/tst01.cc rename to A_fortran/Ex23/tst01.cc diff --git a/A_fortran/test23/tstfunc1.f b/A_fortran/Ex23/tstfunc1.f similarity index 100% rename from A_fortran/test23/tstfunc1.f rename to A_fortran/Ex23/tstfunc1.f diff --git a/A_fortran/test24/FNUM.FOR b/A_fortran/Ex24/FNUM.FOR similarity index 100% rename from A_fortran/test24/FNUM.FOR rename to A_fortran/Ex24/FNUM.FOR diff --git a/A_fortran/test24/NUMBERS.C b/A_fortran/Ex24/NUMBERS.C similarity index 100% rename from A_fortran/test24/NUMBERS.C rename to A_fortran/Ex24/NUMBERS.C diff --git a/A_fortran/test24/readme.txt b/A_fortran/Ex24/readme.txt similarity index 100% rename from A_fortran/test24/readme.txt rename to A_fortran/Ex24/readme.txt diff --git a/A_fortran/Ex25/Cfile.c b/A_fortran/Ex25/Cfile.c new file mode 100644 index 0000000..517eb32 --- /dev/null +++ b/A_fortran/Ex25/Cfile.c @@ -0,0 +1,17 @@ +#include + +typedef struct { + char s[30]; + int l; +} fstring; + +extern fstring stringf_; + +int main() { + //printf("%s\n", stringf_.string); + fstring stringc = stringf_; + printf("%d\n", stringc.l); + stringc.s[29] = '\0'; + printf("%s\n",stringc.s); + return 0; +} diff --git a/A_fortran/Ex25/Ffile.f b/A_fortran/Ex25/Ffile.f new file mode 100644 index 0000000..cbd948f --- /dev/null +++ b/A_fortran/Ex25/Ffile.f @@ -0,0 +1,7 @@ + BLOCK DATA + + CHARACTER*30 S + COMMON /STRINGF/ S + DATA S /'this is a string in FROTRAN77'/ + + end diff --git a/A_fortran/Ex25/Makefile b/A_fortran/Ex25/Makefile new file mode 100644 index 0000000..8491e23 --- /dev/null +++ b/A_fortran/Ex25/Makefile @@ -0,0 +1,9 @@ +all: + gcc -c Cfile.c + gfortran -c -std=legacy Ffile.f + gfortran -o test.out -std=legacy Cfile.o Ffile.f + #gcc -o test.out -std=legacy -lgfortran Cfile.o Ffile.o + rm -rf *.o + +clean: + rm -rf *.o *.out diff --git a/A_fortran/Ex26/CMAIN.c b/A_fortran/Ex26/CMAIN.c new file mode 100644 index 0000000..10d9015 --- /dev/null +++ b/A_fortran/Ex26/CMAIN.c @@ -0,0 +1,19 @@ +/* File CMAIN.C */ + +#include + +extern int fact_(int* n); +extern void pythagoras_(float* a, float* b, float* c); + +int main() +{ + int n = 7; + printf("Factorial of 7 is: %d\n", fact_(&n)); + + float a, b, c; + a = 30; + b = 40; + pythagoras_(&a, &b, &c); + printf("Hypotenuse if sides 30, 40 is: %f\n", c); + return 0; +} diff --git a/A_fortran/Ex26/FORSUBS.FOR b/A_fortran/Ex26/FORSUBS.FOR new file mode 100644 index 0000000..5a108c5 --- /dev/null +++ b/A_fortran/Ex26/FORSUBS.FOR @@ -0,0 +1,18 @@ +C File FORSUBS.FOR +C + INTEGER*4 FUNCTION FACT (n) + INTEGER*4 n + INTEGER*4 i, amt + amt = 1 + DO i = 1, n + amt = amt * i + END DO + Fact = amt + END + + SUBROUTINE PYTHAGORAS (a, b, c) + REAL*4 a + REAL*4 b + REAL*4 c + c = SQRT (a * a + b * b) + END diff --git a/A_fortran/Ex26/Makefile b/A_fortran/Ex26/Makefile new file mode 100644 index 0000000..e13ff15 --- /dev/null +++ b/A_fortran/Ex26/Makefile @@ -0,0 +1,8 @@ +all: + gcc -c CMAIN.c + gfortran -c FORSUBS.FOR + gfortran -o result.out CMAIN.o FORSUBS.o + +clean : + rm -rf *.out *~ *.bak *.o + diff --git a/A_fortran/Ex26/readme.md b/A_fortran/Ex26/readme.md new file mode 100644 index 0000000..a5cebdf --- /dev/null +++ b/A_fortran/Ex26/readme.md @@ -0,0 +1,3 @@ +source: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa293328(v%3dvs.60) + +more info here: https://stackoverflow.com/questions/53585628/minimum-modification-to-make-a-visual-studio-fortran-c-mixed-code-gfortran-gcc-c diff --git a/A_fortran/test32/Makefile b/A_fortran/Ex32/Makefile similarity index 100% rename from A_fortran/test32/Makefile rename to A_fortran/Ex32/Makefile diff --git a/A_fortran/test32/cpps.cpp b/A_fortran/Ex32/cpps.cpp similarity index 100% rename from A_fortran/test32/cpps.cpp rename to A_fortran/Ex32/cpps.cpp diff --git a/A_fortran/test32/main.f b/A_fortran/Ex32/main.f similarity index 100% rename from A_fortran/test32/main.f rename to A_fortran/Ex32/main.f diff --git a/A_fortran/test32/readme.txt b/A_fortran/Ex32/readme.txt similarity index 100% rename from A_fortran/test32/readme.txt rename to A_fortran/Ex32/readme.txt diff --git a/A_fortran/test33/Makefile b/A_fortran/Ex33/Makefile similarity index 100% rename from A_fortran/test33/Makefile rename to A_fortran/Ex33/Makefile diff --git a/A_fortran/test33/cpps.cpp b/A_fortran/Ex33/cpps.cpp similarity index 100% rename from A_fortran/test33/cpps.cpp rename to A_fortran/Ex33/cpps.cpp diff --git a/A_fortran/test33/main.f b/A_fortran/Ex33/main.f similarity index 100% rename from A_fortran/test33/main.f rename to A_fortran/Ex33/main.f diff --git a/A_fortran/test33/readme.txt b/A_fortran/Ex33/readme.txt similarity index 100% rename from A_fortran/test33/readme.txt rename to A_fortran/Ex33/readme.txt diff --git a/A_fortran/test34/ftnfctn.f b/A_fortran/Ex34/ftnfctn.f similarity index 100% rename from A_fortran/test34/ftnfctn.f rename to A_fortran/Ex34/ftnfctn.f diff --git a/A_fortran/test34/main.c b/A_fortran/Ex34/main.c similarity index 100% rename from A_fortran/test34/main.c rename to A_fortran/Ex34/main.c diff --git a/A_fortran/test34/readme.txt b/A_fortran/Ex34/readme.txt similarity index 100% rename from A_fortran/test34/readme.txt rename to A_fortran/Ex34/readme.txt diff --git a/A_fortran/test35/f77char.h b/A_fortran/Ex35/f77char.h similarity index 100% rename from A_fortran/test35/f77char.h rename to A_fortran/Ex35/f77char.h diff --git a/A_fortran/test35/f77cmplx.h b/A_fortran/Ex35/f77cmplx.h similarity index 100% rename from A_fortran/test35/f77cmplx.h rename to A_fortran/Ex35/f77cmplx.h diff --git a/A_fortran/test35/f77matrx.h b/A_fortran/Ex35/f77matrx.h similarity index 100% rename from A_fortran/test35/f77matrx.h rename to A_fortran/Ex35/f77matrx.h diff --git a/A_fortran/test35/fortran.h b/A_fortran/Ex35/fortran.h similarity index 100% rename from A_fortran/test35/fortran.h rename to A_fortran/Ex35/fortran.h diff --git a/A_fortran/test35/readme.txt b/A_fortran/Ex35/readme.txt similarity index 100% rename from A_fortran/test35/readme.txt rename to A_fortran/Ex35/readme.txt diff --git a/A_fortran/test36/c_calls_f77/c_calls_f77.html b/A_fortran/Ex36/c_calls_f77/c_calls_f77.html similarity index 100% rename from A_fortran/test36/c_calls_f77/c_calls_f77.html rename to A_fortran/Ex36/c_calls_f77/c_calls_f77.html diff --git a/A_fortran/test36/c_calls_f77/kronrod.f b/A_fortran/Ex36/c_calls_f77/kronrod.f similarity index 100% rename from A_fortran/test36/c_calls_f77/kronrod.f rename to A_fortran/Ex36/c_calls_f77/kronrod.f diff --git a/A_fortran/test36/c_calls_f77/kronrod_prb.c b/A_fortran/Ex36/c_calls_f77/kronrod_prb.c similarity index 100% rename from A_fortran/test36/c_calls_f77/kronrod_prb.c rename to A_fortran/Ex36/c_calls_f77/kronrod_prb.c diff --git a/A_fortran/test36/c_calls_f77/kronrod_prb.sh b/A_fortran/Ex36/c_calls_f77/kronrod_prb.sh similarity index 100% rename from A_fortran/test36/c_calls_f77/kronrod_prb.sh rename to A_fortran/Ex36/c_calls_f77/kronrod_prb.sh diff --git a/A_fortran/test36/c_calls_f77/kronrod_prb_output.txt b/A_fortran/Ex36/c_calls_f77/kronrod_prb_output.txt similarity index 100% rename from A_fortran/test36/c_calls_f77/kronrod_prb_output.txt rename to A_fortran/Ex36/c_calls_f77/kronrod_prb_output.txt diff --git a/A_fortran/test36/c_calls_f77/robots.txt b/A_fortran/Ex36/c_calls_f77/robots.txt similarity index 100% rename from A_fortran/test36/c_calls_f77/robots.txt rename to A_fortran/Ex36/c_calls_f77/robots.txt diff --git a/A_fortran/test36/c_calls_f90/c_calls_f90.html b/A_fortran/Ex36/c_calls_f90/c_calls_f90.html similarity index 100% rename from A_fortran/test36/c_calls_f90/c_calls_f90.html rename to A_fortran/Ex36/c_calls_f90/c_calls_f90.html diff --git a/A_fortran/test36/c_calls_f90/kronrod.f90 b/A_fortran/Ex36/c_calls_f90/kronrod.f90 similarity index 100% rename from A_fortran/test36/c_calls_f90/kronrod.f90 rename to A_fortran/Ex36/c_calls_f90/kronrod.f90 diff --git a/A_fortran/test36/c_calls_f90/kronrod_prb.c b/A_fortran/Ex36/c_calls_f90/kronrod_prb.c similarity index 100% rename from A_fortran/test36/c_calls_f90/kronrod_prb.c rename to A_fortran/Ex36/c_calls_f90/kronrod_prb.c diff --git a/A_fortran/test36/c_calls_f90/kronrod_prb.sh b/A_fortran/Ex36/c_calls_f90/kronrod_prb.sh similarity index 100% rename from A_fortran/test36/c_calls_f90/kronrod_prb.sh rename to A_fortran/Ex36/c_calls_f90/kronrod_prb.sh diff --git a/A_fortran/test36/c_calls_f90/kronrod_prb_output.txt b/A_fortran/Ex36/c_calls_f90/kronrod_prb_output.txt similarity index 100% rename from A_fortran/test36/c_calls_f90/kronrod_prb_output.txt rename to A_fortran/Ex36/c_calls_f90/kronrod_prb_output.txt diff --git a/A_fortran/test36/c_calls_f90/robots.txt b/A_fortran/Ex36/c_calls_f90/robots.txt similarity index 100% rename from A_fortran/test36/c_calls_f90/robots.txt rename to A_fortran/Ex36/c_calls_f90/robots.txt diff --git a/A_fortran/test36/f77_calls_c/f77_calls_c.html b/A_fortran/Ex36/f77_calls_c/f77_calls_c.html similarity index 100% rename from A_fortran/test36/f77_calls_c/f77_calls_c.html rename to A_fortran/Ex36/f77_calls_c/f77_calls_c.html diff --git a/A_fortran/test36/f77_calls_c/kronrod.c b/A_fortran/Ex36/f77_calls_c/kronrod.c similarity index 100% rename from A_fortran/test36/f77_calls_c/kronrod.c rename to A_fortran/Ex36/f77_calls_c/kronrod.c diff --git a/A_fortran/test36/f77_calls_c/kronrod.h b/A_fortran/Ex36/f77_calls_c/kronrod.h similarity index 100% rename from A_fortran/test36/f77_calls_c/kronrod.h rename to A_fortran/Ex36/f77_calls_c/kronrod.h diff --git a/A_fortran/test36/f77_calls_c/kronrod.sh b/A_fortran/Ex36/f77_calls_c/kronrod.sh similarity index 100% rename from A_fortran/test36/f77_calls_c/kronrod.sh rename to A_fortran/Ex36/f77_calls_c/kronrod.sh diff --git a/A_fortran/test36/f77_calls_c/kronrod_output.txt b/A_fortran/Ex36/f77_calls_c/kronrod_output.txt similarity index 100% rename from A_fortran/test36/f77_calls_c/kronrod_output.txt rename to A_fortran/Ex36/f77_calls_c/kronrod_output.txt diff --git a/A_fortran/test36/f77_calls_c/kronrod_prb.f b/A_fortran/Ex36/f77_calls_c/kronrod_prb.f similarity index 100% rename from A_fortran/test36/f77_calls_c/kronrod_prb.f rename to A_fortran/Ex36/f77_calls_c/kronrod_prb.f diff --git a/A_fortran/test36/f77_calls_c/robots.txt b/A_fortran/Ex36/f77_calls_c/robots.txt similarity index 100% rename from A_fortran/test36/f77_calls_c/robots.txt rename to A_fortran/Ex36/f77_calls_c/robots.txt diff --git a/A_fortran/test36/f90_calls_c/f90_calls_c.html b/A_fortran/Ex36/f90_calls_c/f90_calls_c.html similarity index 100% rename from A_fortran/test36/f90_calls_c/f90_calls_c.html rename to A_fortran/Ex36/f90_calls_c/f90_calls_c.html diff --git a/A_fortran/test36/f90_calls_c/hello.c b/A_fortran/Ex36/f90_calls_c/hello.c similarity index 100% rename from A_fortran/test36/f90_calls_c/hello.c rename to A_fortran/Ex36/f90_calls_c/hello.c diff --git a/A_fortran/test36/f90_calls_c/hello.sh b/A_fortran/Ex36/f90_calls_c/hello.sh similarity index 100% rename from A_fortran/test36/f90_calls_c/hello.sh rename to A_fortran/Ex36/f90_calls_c/hello.sh diff --git a/A_fortran/test36/f90_calls_c/hello_output.txt b/A_fortran/Ex36/f90_calls_c/hello_output.txt similarity index 100% rename from A_fortran/test36/f90_calls_c/hello_output.txt rename to A_fortran/Ex36/f90_calls_c/hello_output.txt diff --git a/A_fortran/test36/f90_calls_c/hello_prb.f90 b/A_fortran/Ex36/f90_calls_c/hello_prb.f90 similarity index 100% rename from A_fortran/test36/f90_calls_c/hello_prb.f90 rename to A_fortran/Ex36/f90_calls_c/hello_prb.f90 diff --git a/A_fortran/test36/f90_calls_c/kronrod.c b/A_fortran/Ex36/f90_calls_c/kronrod.c similarity index 100% rename from A_fortran/test36/f90_calls_c/kronrod.c rename to A_fortran/Ex36/f90_calls_c/kronrod.c diff --git a/A_fortran/test36/f90_calls_c/kronrod.h b/A_fortran/Ex36/f90_calls_c/kronrod.h similarity index 100% rename from A_fortran/test36/f90_calls_c/kronrod.h rename to A_fortran/Ex36/f90_calls_c/kronrod.h diff --git a/A_fortran/test36/f90_calls_c/kronrod.sh b/A_fortran/Ex36/f90_calls_c/kronrod.sh similarity index 100% rename from A_fortran/test36/f90_calls_c/kronrod.sh rename to A_fortran/Ex36/f90_calls_c/kronrod.sh diff --git a/A_fortran/test36/f90_calls_c/kronrod_output.txt b/A_fortran/Ex36/f90_calls_c/kronrod_output.txt similarity index 100% rename from A_fortran/test36/f90_calls_c/kronrod_output.txt rename to A_fortran/Ex36/f90_calls_c/kronrod_output.txt diff --git a/A_fortran/test36/f90_calls_c/kronrod_prb.f90 b/A_fortran/Ex36/f90_calls_c/kronrod_prb.f90 similarity index 100% rename from A_fortran/test36/f90_calls_c/kronrod_prb.f90 rename to A_fortran/Ex36/f90_calls_c/kronrod_prb.f90 diff --git a/A_fortran/test36/f90_calls_c/robots.txt b/A_fortran/Ex36/f90_calls_c/robots.txt similarity index 100% rename from A_fortran/test36/f90_calls_c/robots.txt rename to A_fortran/Ex36/f90_calls_c/robots.txt diff --git a/A_fortran/test36/mixed77/ex1_f77_cc.sh b/A_fortran/Ex36/mixed77/ex1_f77_cc.sh similarity index 100% rename from A_fortran/test36/mixed77/ex1_f77_cc.sh rename to A_fortran/Ex36/mixed77/ex1_f77_cc.sh diff --git a/A_fortran/test36/mixed77/ex1_f77_cc_output.txt b/A_fortran/Ex36/mixed77/ex1_f77_cc_output.txt similarity index 100% rename from A_fortran/test36/mixed77/ex1_f77_cc_output.txt rename to A_fortran/Ex36/mixed77/ex1_f77_cc_output.txt diff --git a/A_fortran/test36/mixed77/ex1_g77_gcc.sh b/A_fortran/Ex36/mixed77/ex1_g77_gcc.sh similarity index 100% rename from A_fortran/test36/mixed77/ex1_g77_gcc.sh rename to A_fortran/Ex36/mixed77/ex1_g77_gcc.sh diff --git a/A_fortran/test36/mixed77/ex1_g77_gcc_output.txt b/A_fortran/Ex36/mixed77/ex1_g77_gcc_output.txt similarity index 100% rename from A_fortran/test36/mixed77/ex1_g77_gcc_output.txt rename to A_fortran/Ex36/mixed77/ex1_g77_gcc_output.txt diff --git a/A_fortran/test36/mixed77/ex1_main.f b/A_fortran/Ex36/mixed77/ex1_main.f similarity index 100% rename from A_fortran/test36/mixed77/ex1_main.f rename to A_fortran/Ex36/mixed77/ex1_main.f diff --git a/A_fortran/test36/mixed77/ex1_sub.c b/A_fortran/Ex36/mixed77/ex1_sub.c similarity index 100% rename from A_fortran/test36/mixed77/ex1_sub.c rename to A_fortran/Ex36/mixed77/ex1_sub.c diff --git a/A_fortran/test36/mixed77/mixed.html b/A_fortran/Ex36/mixed77/mixed.html similarity index 100% rename from A_fortran/test36/mixed77/mixed.html rename to A_fortran/Ex36/mixed77/mixed.html diff --git a/A_fortran/test36/mixed77/robots.txt b/A_fortran/Ex36/mixed77/robots.txt similarity index 100% rename from A_fortran/test36/mixed77/robots.txt rename to A_fortran/Ex36/mixed77/robots.txt diff --git a/A_fortran/test36/mixed90/ex1_fort_cc.sh b/A_fortran/Ex36/mixed90/ex1_fort_cc.sh similarity index 100% rename from A_fortran/test36/mixed90/ex1_fort_cc.sh rename to A_fortran/Ex36/mixed90/ex1_fort_cc.sh diff --git a/A_fortran/test36/mixed90/ex1_fort_cc_output.txt b/A_fortran/Ex36/mixed90/ex1_fort_cc_output.txt similarity index 100% rename from A_fortran/test36/mixed90/ex1_fort_cc_output.txt rename to A_fortran/Ex36/mixed90/ex1_fort_cc_output.txt diff --git a/A_fortran/test36/mixed90/ex1_fort_gcc.sh b/A_fortran/Ex36/mixed90/ex1_fort_gcc.sh similarity index 100% rename from A_fortran/test36/mixed90/ex1_fort_gcc.sh rename to A_fortran/Ex36/mixed90/ex1_fort_gcc.sh diff --git a/A_fortran/test36/mixed90/ex1_fort_gcc_output.txt b/A_fortran/Ex36/mixed90/ex1_fort_gcc_output.txt similarity index 100% rename from A_fortran/test36/mixed90/ex1_fort_gcc_output.txt rename to A_fortran/Ex36/mixed90/ex1_fort_gcc_output.txt diff --git a/A_fortran/test36/mixed90/ex1_gfortran_gcc.sh b/A_fortran/Ex36/mixed90/ex1_gfortran_gcc.sh similarity index 100% rename from A_fortran/test36/mixed90/ex1_gfortran_gcc.sh rename to A_fortran/Ex36/mixed90/ex1_gfortran_gcc.sh diff --git a/A_fortran/test36/mixed90/ex1_gfortran_gcc_output.txt b/A_fortran/Ex36/mixed90/ex1_gfortran_gcc_output.txt similarity index 100% rename from A_fortran/test36/mixed90/ex1_gfortran_gcc_output.txt rename to A_fortran/Ex36/mixed90/ex1_gfortran_gcc_output.txt diff --git a/A_fortran/test36/mixed90/ex1_main.f90 b/A_fortran/Ex36/mixed90/ex1_main.f90 similarity index 100% rename from A_fortran/test36/mixed90/ex1_main.f90 rename to A_fortran/Ex36/mixed90/ex1_main.f90 diff --git a/A_fortran/test36/mixed90/ex1_sub.c b/A_fortran/Ex36/mixed90/ex1_sub.c similarity index 100% rename from A_fortran/test36/mixed90/ex1_sub.c rename to A_fortran/Ex36/mixed90/ex1_sub.c diff --git a/A_fortran/test36/mixed90/ex2_fort_cxx.sh b/A_fortran/Ex36/mixed90/ex2_fort_cxx.sh similarity index 100% rename from A_fortran/test36/mixed90/ex2_fort_cxx.sh rename to A_fortran/Ex36/mixed90/ex2_fort_cxx.sh diff --git a/A_fortran/test36/mixed90/ex2_fort_cxx_output.txt b/A_fortran/Ex36/mixed90/ex2_fort_cxx_output.txt similarity index 100% rename from A_fortran/test36/mixed90/ex2_fort_cxx_output.txt rename to A_fortran/Ex36/mixed90/ex2_fort_cxx_output.txt diff --git a/A_fortran/test36/mixed90/ex2_fort_g++.sh b/A_fortran/Ex36/mixed90/ex2_fort_g++.sh similarity index 100% rename from A_fortran/test36/mixed90/ex2_fort_g++.sh rename to A_fortran/Ex36/mixed90/ex2_fort_g++.sh diff --git a/A_fortran/test36/mixed90/ex2_fort_g++_output.txt b/A_fortran/Ex36/mixed90/ex2_fort_g++_output.txt similarity index 100% rename from A_fortran/test36/mixed90/ex2_fort_g++_output.txt rename to A_fortran/Ex36/mixed90/ex2_fort_g++_output.txt diff --git a/A_fortran/test36/mixed90/ex2_gfortran_g++.sh b/A_fortran/Ex36/mixed90/ex2_gfortran_g++.sh similarity index 100% rename from A_fortran/test36/mixed90/ex2_gfortran_g++.sh rename to A_fortran/Ex36/mixed90/ex2_gfortran_g++.sh diff --git a/A_fortran/test36/mixed90/ex2_gfortran_g++_output.txt b/A_fortran/Ex36/mixed90/ex2_gfortran_g++_output.txt similarity index 100% rename from A_fortran/test36/mixed90/ex2_gfortran_g++_output.txt rename to A_fortran/Ex36/mixed90/ex2_gfortran_g++_output.txt diff --git a/A_fortran/test36/mixed90/ex2_main.f90 b/A_fortran/Ex36/mixed90/ex2_main.f90 similarity index 100% rename from A_fortran/test36/mixed90/ex2_main.f90 rename to A_fortran/Ex36/mixed90/ex2_main.f90 diff --git a/A_fortran/test36/mixed90/ex2_sub.cpp b/A_fortran/Ex36/mixed90/ex2_sub.cpp similarity index 100% rename from A_fortran/test36/mixed90/ex2_sub.cpp rename to A_fortran/Ex36/mixed90/ex2_sub.cpp diff --git a/A_fortran/test36/mixed90/robots.txt b/A_fortran/Ex36/mixed90/robots.txt similarity index 100% rename from A_fortran/test36/mixed90/robots.txt rename to A_fortran/Ex36/mixed90/robots.txt diff --git a/A_fortran/test36/mixedC/ex1_cc_fort.sh b/A_fortran/Ex36/mixedC/ex1_cc_fort.sh similarity index 100% rename from A_fortran/test36/mixedC/ex1_cc_fort.sh rename to A_fortran/Ex36/mixedC/ex1_cc_fort.sh diff --git a/A_fortran/test36/mixedC/ex1_cc_fort_output.txt b/A_fortran/Ex36/mixedC/ex1_cc_fort_output.txt similarity index 100% rename from A_fortran/test36/mixedC/ex1_cc_fort_output.txt rename to A_fortran/Ex36/mixedC/ex1_cc_fort_output.txt diff --git a/A_fortran/test36/mixedC/ex1_gcc_fort.sh b/A_fortran/Ex36/mixedC/ex1_gcc_fort.sh similarity index 100% rename from A_fortran/test36/mixedC/ex1_gcc_fort.sh rename to A_fortran/Ex36/mixedC/ex1_gcc_fort.sh diff --git a/A_fortran/test36/mixedC/ex1_gcc_fort_output.txt b/A_fortran/Ex36/mixedC/ex1_gcc_fort_output.txt similarity index 100% rename from A_fortran/test36/mixedC/ex1_gcc_fort_output.txt rename to A_fortran/Ex36/mixedC/ex1_gcc_fort_output.txt diff --git a/A_fortran/test36/mixedC/ex1_main.c b/A_fortran/Ex36/mixedC/ex1_main.c similarity index 100% rename from A_fortran/test36/mixedC/ex1_main.c rename to A_fortran/Ex36/mixedC/ex1_main.c diff --git a/A_fortran/test36/mixedC/ex1_sub.f90 b/A_fortran/Ex36/mixedC/ex1_sub.f90 similarity index 100% rename from A_fortran/test36/mixedC/ex1_sub.f90 rename to A_fortran/Ex36/mixedC/ex1_sub.f90 diff --git a/A_fortran/test36/mixedC/ex2_cc_fort.sh b/A_fortran/Ex36/mixedC/ex2_cc_fort.sh similarity index 100% rename from A_fortran/test36/mixedC/ex2_cc_fort.sh rename to A_fortran/Ex36/mixedC/ex2_cc_fort.sh diff --git a/A_fortran/test36/mixedC/ex2_cc_fort_output.txt b/A_fortran/Ex36/mixedC/ex2_cc_fort_output.txt similarity index 100% rename from A_fortran/test36/mixedC/ex2_cc_fort_output.txt rename to A_fortran/Ex36/mixedC/ex2_cc_fort_output.txt diff --git a/A_fortran/test36/mixedC/ex2_gcc_fort.sh b/A_fortran/Ex36/mixedC/ex2_gcc_fort.sh similarity index 100% rename from A_fortran/test36/mixedC/ex2_gcc_fort.sh rename to A_fortran/Ex36/mixedC/ex2_gcc_fort.sh diff --git a/A_fortran/test36/mixedC/ex2_gcc_fort_output.txt b/A_fortran/Ex36/mixedC/ex2_gcc_fort_output.txt similarity index 100% rename from A_fortran/test36/mixedC/ex2_gcc_fort_output.txt rename to A_fortran/Ex36/mixedC/ex2_gcc_fort_output.txt diff --git a/A_fortran/test36/mixedC/ex2_main.c b/A_fortran/Ex36/mixedC/ex2_main.c similarity index 100% rename from A_fortran/test36/mixedC/ex2_main.c rename to A_fortran/Ex36/mixedC/ex2_main.c diff --git a/A_fortran/test36/mixedC/ex2_sub.f90 b/A_fortran/Ex36/mixedC/ex2_sub.f90 similarity index 100% rename from A_fortran/test36/mixedC/ex2_sub.f90 rename to A_fortran/Ex36/mixedC/ex2_sub.f90 diff --git a/A_fortran/test36/mixedC/mixed.html b/A_fortran/Ex36/mixedC/mixed.html similarity index 100% rename from A_fortran/test36/mixedC/mixed.html rename to A_fortran/Ex36/mixedC/mixed.html diff --git a/A_fortran/test36/mixedC/robots.txt b/A_fortran/Ex36/mixedC/robots.txt similarity index 100% rename from A_fortran/test36/mixedC/robots.txt rename to A_fortran/Ex36/mixedC/robots.txt diff --git a/A_fortran/test36/readme.txt b/A_fortran/Ex36/readme.txt similarity index 100% rename from A_fortran/test36/readme.txt rename to A_fortran/Ex36/readme.txt diff --git a/A_fortran/README.md b/A_fortran/README.md new file mode 100644 index 0000000..591c7d1 --- /dev/null +++ b/A_fortran/README.md @@ -0,0 +1,45 @@ +# Description: +FORTRAN/Fortran is obviously a different programing language from C. However, considering it has been the de facto programing language for mathematical and algebraic calculations, many legacy libraries, including original implementations BLAS and LAPACK APIs are written in Fortran. Of course you can use the libraries mentioned in this tutorial without knowing how to do mixed Fortran and C programing, but knowing that not only will help you a lot understanding what happening under the hood, but also gives you the ability to modify or even write your own Fortran subroutines if required. not to mention it opens the door to tens of other libraries out there written in Fortran. Fortran is historically the gold standard programing language for mathematical operations and learning Fortran for you as a C programmer will be life changing. + +# keywords: +* mixed language programing +* call Fortran functions/subroutines from C/C++ +* interface the function calls + +# requirements +you need to have Fortran and C compilers. Preferably GNU gcc and gfortran + +# Points: +1. name of the routines/subroutines/functions and structs/commons in some versions or dialects of Fortran must be in small letters and an underscore _ must be added to the C function + +# Sources to be studied: +3. http://arnholm.org/software/cppf77/cppf77.htm --> test35 +4. http://www.nag.com/lapack-ex/node1.html#sec:Introduction +5. http://physics.oregonstate.edu/~landaur/nacphy/lapack/fortran.html +6. http://www.fortran.com/the-fortran-company-homepage/fortran-tools-libraries-and-application-software/ --> Fortran Tools, Libraries, and Application Software +7. iso_c_binding +8. https://docs.oracle.com/cd/E19059-01/stud.9/817-6694/11_cfort.html +9. https://www.math.utah.edu/software/c-with-fortran.html +10. https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/290051 +11. http://luthaf.github.io/calling-c++-from-fortran.html +12. http://alignment.hep.brandeis.edu/Software/Mixing/Mixing_Manual.html +13. http://www.fortran.bcs.org/2002/interop.htm +14. http://www.pgroup.com/userforum/viewtopic.php?p=7398&sid=2a05571a922045c6c4ae26d65bbf9fba +15. http://www.unidata.ucar.edu/software/netcdf/examples/programs/ +16. http://people.sc.fsu.edu/~jburkardt/c_src/mixed/mixed.html +17. https://docs.oracle.com/cd/E19422-01/819-3685/11_cfort.html +18. cfortran--> http://www-zeus.desy.de/~burow/cfortran/ +19. https://docs.oracle.com/cd/E19957-01/805-4940/6j4m1u7qq/index.html + + +# To do: + +1. Change the naming scheme from test-- to example-- and add 0 before the single digit numbers so it sorts correctly + + +# Issues: +1. test22 result not correct +2. test19 does not compile +3. test24 not compiling +4. test4 not compiling +5. test34 not compiling diff --git a/A_fortran/readme.txt b/A_fortran/readme.txt deleted file mode 100644 index b821332..0000000 --- a/A_fortran/readme.txt +++ /dev/null @@ -1,41 +0,0 @@ -FORTRAN or Fortran is actually a different programing language separated from C, however considering it has been the de facto programing language for mathematical and algebraic calculations, many legacy libraries, including original implementations BLAS and LAPACK APIs are written in Fortran. Of course you can use the libraries mentioned in this tutorial without knowing how to do mixed Fortran and C programing, but knowing that not only will help you a lot understanding what happening under the hood, but also gives you the ability to modify or even write your own fortran subroutines if required. not to mention it opens the door to tens of other libraries out there written in fortran. fortran is historically the gold standard programing language for mathematical operations and learning fortran for you as a C programer will be life changing. - -keywords: -mixed language programing -call fortran functions/subroutines -interface the function calls - - - -sources to be looked at: -1. -2. -3. http://arnholm.org/software/cppf77/cppf77.htm --> test35 -4. http://www.nag.com/lapack-ex/node1.html#sec:Introduction -5. http://physics.oregonstate.edu/~landaur/nacphy/lapack/fortran.html -6. http://www.fortran.com/the-fortran-company-homepage/fortran-tools-libraries-and-application-software/ --> Fortran Tools, Libraries, and Application Software -7. iso_c_binding -8. https://docs.oracle.com/cd/E19059-01/stud.9/817-6694/11_cfort.html -9. https://www.math.utah.edu/software/c-with-fortran.html -10. https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/290051 -11. http://luthaf.github.io/calling-c++-from-fortran.html -12. http://alignment.hep.brandeis.edu/Software/Mixing/Mixing_Manual.html -13. http://www.fortran.bcs.org/2002/interop.htm -14. http://www.pgroup.com/userforum/viewtopic.php?p=7398&sid=2a05571a922045c6c4ae26d65bbf9fba -15. http://www.unidata.ucar.edu/software/netcdf/examples/programs/ -16. http://people.sc.fsu.edu/~jburkardt/c_src/mixed/mixed.html -17. https://docs.oracle.com/cd/E19422-01/819-3685/11_cfort.html -18. cfortran--> http://www-zeus.desy.de/~burow/cfortran/ - - -points: - -1. name of the routines/subroutines/functions and structs/commons in some versions or dialects of fortran must be in small letters and and an underscore _ must be added to the C function - - -issues: -1. test22 result not correct -2. test19 does not compile -3. test24 not compiling -4. test4 not compiling -5. test34 not compiling diff --git a/A_fortran/test1/Makefile b/A_fortran/test1/Makefile deleted file mode 100644 index 95af412..0000000 --- a/A_fortran/test1/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -all: - gfortran -c test1F.f - gcc -c test1C.c - gfortran -o test1.out test1C.o test1F.o - rm -rf *.o - - -clean : - rm -rf *.out *~ *.bak *.o diff --git a/A_fortran/test1/readme.txt b/A_fortran/test1/readme.txt deleted file mode 100644 index 28d934c..0000000 --- a/A_fortran/test1/readme.txt +++ /dev/null @@ -1,42 +0,0 @@ -fortran code written if FORTRAN 77? - -this file shows how we can call a C function from fortran and how to pass a string properly from fortran to C -source: http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html - - -points: -1. when you pass a string from fortran to C you actually pass two variables including a pointer to an array of single characters (string) and also the length of the array. -2. when you pass a string to C you need to first be sure that you allocate at least one letter more than the characters you need and in C first of se "\0" or NULL as the end of the string -3. common is the equivalent of struct in C - in C: - extern struct { - int i; - char c; - ... - } mystruct_; - in fortran - integer i - character c - ... - common/mystruct/ i, c, ... - -4. when fortran passes a variable to C function, the C function receives a pointer? -5. when you want to call a C function in fortran you don't need to declare a dummy in the fortran code, unlike C ,fortran doesn't care if the function is not declared and then on run time it will look for the function (how about variables and structs?) -6. when passing variables, functions or srtucts from/to C/fortran it is Case-insensitive. but you should be careful that inside each world it is case sensitive. - - - -questions: -1. this pages says when you want to call a C function from fortran you need to also declare it as external but here it works properly without declaring! - https://docs.oracle.com/cd/E19059-01/stud.9/817-6694/11_cfort.html -I think we needed a - external doubleijk - here, but we don't! - - - - -fortran points: -1. in FORTRAN 77 (?) one can print to terminal with something like: - write(6,) var_1,var_2,... - 10 format('some text', typeof_var_N,'some other text',...) diff --git a/A_fortran/test3/CSUBS.C b/A_fortran/test3/CSUBS.C deleted file mode 100644 index e49334b..0000000 --- a/A_fortran/test3/CSUBS.C +++ /dev/null @@ -1,11 +0,0 @@ -/* File CSUBS.C */ - -#include - -int Fact(int n) { - if (n > 1) - return (n * Fact(n - 1)); - return 1; -} - -void Pythagoras(float a, float b, float *c) { *c = sqrt(a * a + b * b); } diff --git a/A_fortran/test3/FORMAIN.FOR b/A_fortran/test3/FORMAIN.FOR deleted file mode 100644 index d6b76c0..0000000 --- a/A_fortran/test3/FORMAIN.FOR +++ /dev/null @@ -1,18 +0,0 @@ -C File FORMAIN.FOR -C - INTERFACE TO INTEGER*4 FUNCTION Fact [C,ALIAS:'_Fact'] (n) - INTEGER*4 n [VALUE] - END - - INTERFACE TO SUBROUTINE Pythagoras [C,ALIAS:'_Pythagoras'] (a,b,c) - REAL*4 a [VALUE] - REAL*4 b [VALUE] - REAL*4 c [REFERENCE] - END - - INTEGER*4 Fact - REAL*4 c - WRITE (*,*) 'Factorial of 7 is ', Fact (7) - CALL Pythagoras (30, 40, c) - WRITE (*,*) 'Hypotenuse if sides 30, 40 is ', c - END diff --git a/A_fortran/test3/Makefile b/A_fortran/test3/Makefile deleted file mode 100644 index 107e6f9..0000000 --- a/A_fortran/test3/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -all: - gfortran -c FORMAIN.FOR - gcc -c CSUBS.C - gfortran -o result.out FORMAIN.o CSUBS.o - rm -rf *.o - - -clean : - rm -rf *.out *~ *.bak *.o diff --git a/A_fortran/test3/readme.txt b/A_fortran/test3/readme.txt deleted file mode 100644 index ccd19ae..0000000 --- a/A_fortran/test3/readme.txt +++ /dev/null @@ -1,16 +0,0 @@ -source: https://msdn.microsoft.com/en-us/library/aa279034(v=vs.60).aspx - -isues: -not compiling: - - -FORMAIN.FOR:3:26: - - INTERFACE TO INTEGER*4 FUNCTION Fact [C,ALIAS:'_Fact'] (n) - 1 -Error: Syntax error: Trailing garbage in INTERFACE statement at (1) -FORMAIN.FOR:4:19: - - INTEGER*4 n [VALUE] - 1 -Fatal Error: Coarrays disabled at (1), use '-fcoarray=' to enable diff --git a/B_BLAS/ibm/sample1/Makefile b/B_BLAS/Ex01/Makefile similarity index 78% rename from B_BLAS/ibm/sample1/Makefile rename to B_BLAS/Ex01/Makefile index 8d3f6a6..a18771c 100644 --- a/B_BLAS/ibm/sample1/Makefile +++ b/B_BLAS/Ex01/Makefile @@ -1,7 +1,7 @@ FLNAME = sample1. # path to your libraries if you have followed the instructions spsecific for these examples or /usr/local/... -BINDIR = ../../../common +BINDIR = ../../common NBLAS = true NGFORTRAN = true @@ -11,4 +11,4 @@ NCLAPACK = false NLAPACKE = false -include ../../../common/Makefile.inc +include ../../common/Makefile.inc diff --git a/B_BLAS/ibm/sample1/readme.txt b/B_BLAS/Ex01/readme.txt similarity index 93% rename from B_BLAS/ibm/sample1/readme.txt rename to B_BLAS/Ex01/readme.txt index e0d4bd7..8aa0041 100644 --- a/B_BLAS/ibm/sample1/readme.txt +++ b/B_BLAS/Ex01/readme.txt @@ -1,3 +1,8 @@ +on ubuntu install BLAS via + sudo apt-get install libblas-dev +and then compile with + gcc foo.c -lblas + source: https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbcpx01/atlasexample1.htm issues: diff --git a/B_BLAS/ibm/sample1/sample1.c b/B_BLAS/Ex01/sample1.c similarity index 100% rename from B_BLAS/ibm/sample1/sample1.c rename to B_BLAS/Ex01/sample1.c diff --git a/B_BLAS/lindonslog/example1/Makefile b/B_BLAS/Ex02/Makefile similarity index 78% rename from B_BLAS/lindonslog/example1/Makefile rename to B_BLAS/Ex02/Makefile index 9b9c5b5..8b1389f 100644 --- a/B_BLAS/lindonslog/example1/Makefile +++ b/B_BLAS/Ex02/Makefile @@ -2,7 +2,7 @@ FLNAME = example1. # path to your libraries if you have followed the instructions spsecific for these examples or /usr/local/... -BINDIR = ../../../common +BINDIR = ../../common NBLAS = true NGFORTRAN = false @@ -12,4 +12,4 @@ NCLAPACK = false NLAPACKE = false -include ../../../common/Makefile.inc +include ../../common/Makefile.inc diff --git a/B_BLAS/lindonslog/example1/example1.c b/B_BLAS/Ex02/example1.c similarity index 100% rename from B_BLAS/lindonslog/example1/example1.c rename to B_BLAS/Ex02/example1.c diff --git a/B_BLAS/lindonslog/example1/readme.txt b/B_BLAS/Ex02/readme.md similarity index 100% rename from B_BLAS/lindonslog/example1/readme.txt rename to B_BLAS/Ex02/readme.md diff --git a/B_BLAS/ubuntuforums/example1/Makefile b/B_BLAS/Ex03/Makefile similarity index 100% rename from B_BLAS/ubuntuforums/example1/Makefile rename to B_BLAS/Ex03/Makefile diff --git a/B_BLAS/ubuntuforums/example1/example1.c b/B_BLAS/Ex03/example1.c similarity index 100% rename from B_BLAS/ubuntuforums/example1/example1.c rename to B_BLAS/Ex03/example1.c diff --git a/B_BLAS/ubuntuforums/example1/readme.txt b/B_BLAS/Ex03/readme.txt similarity index 100% rename from B_BLAS/ubuntuforums/example1/readme.txt rename to B_BLAS/Ex03/readme.txt diff --git a/B_BLAS/ubuntuforums/example2/Makefile b/B_BLAS/Ex04/Makefile similarity index 100% rename from B_BLAS/ubuntuforums/example2/Makefile rename to B_BLAS/Ex04/Makefile diff --git a/B_BLAS/ubuntuforums/example2/example2.c b/B_BLAS/Ex04/example2.c similarity index 100% rename from B_BLAS/ubuntuforums/example2/example2.c rename to B_BLAS/Ex04/example2.c diff --git a/B_BLAS/ubuntuforums/example2/readme.txt b/B_BLAS/Ex04/readme.txt similarity index 100% rename from B_BLAS/ubuntuforums/example2/readme.txt rename to B_BLAS/Ex04/readme.txt diff --git a/B_BLAS/xianyi/example2/Makefile b/B_BLAS/Ex05/Makefile similarity index 100% rename from B_BLAS/xianyi/example2/Makefile rename to B_BLAS/Ex05/Makefile diff --git a/B_BLAS/xianyi/example2/readme.txt b/B_BLAS/Ex05/readme.txt similarity index 100% rename from B_BLAS/xianyi/example2/readme.txt rename to B_BLAS/Ex05/readme.txt diff --git a/B_BLAS/Ex05/timeDGEMM.txt b/B_BLAS/Ex05/timeDGEMM.txt new file mode 100644 index 0000000..2873b84 --- /dev/null +++ b/B_BLAS/Ex05/timeDGEMM.txt @@ -0,0 +1 @@ +10x5x3 0.000022 s 13.636364 MFLOPS diff --git a/B_BLAS/xianyi/example2/time_dgemm.c b/B_BLAS/Ex05/time_dgemm.c similarity index 94% rename from B_BLAS/xianyi/example2/time_dgemm.c rename to B_BLAS/Ex05/time_dgemm.c index 442c007..79370b0 100644 --- a/B_BLAS/xianyi/example2/time_dgemm.c +++ b/B_BLAS/Ex05/time_dgemm.c @@ -10,7 +10,7 @@ int main(int argc, char* argv[]) int i; printf("test!\n"); if(argc<4){ - printf("Input Error\n"); + printf("Input Error. you need at least 3 integer arguments for the executable\n"); return 1; } @@ -61,4 +61,4 @@ int main(int argc, char* argv[]) free(B); free(C); return 0; -} \ No newline at end of file +} diff --git a/B_BLAS/ibm/readme.txt b/B_BLAS/ibm/readme.txt deleted file mode 100644 index bad0b4d..0000000 --- a/B_BLAS/ibm/readme.txt +++ /dev/null @@ -1,3 +0,0 @@ -source: https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbcpx01/atlasexample1.htm - -needs ATLAS diff --git a/B_BLAS/intel/example1.c b/B_BLAS/intel/example1.c deleted file mode 100644 index a525f7e..0000000 --- a/B_BLAS/intel/example1.c +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2009-2015 Intel Corporation. All Rights Reserved. -* The information and material ("Material") provided below is owned by Intel -* Corporation or its suppliers or licensors, and title to such Material remains -* with Intel Corporation or its suppliers or licensors. The Material contains -* proprietary information of Intel or its suppliers and licensors. The Material -* is protected by worldwide copyright laws and treaty provisions. No part of -* the Material may be copied, reproduced, published, uploaded, posted, -* transmitted, or distributed in any way without Intel's prior express written -* permission. No license under any patent, copyright or other intellectual -* property rights in the Material is granted to or conferred upon you, either -* expressly, by implication, inducement, estoppel or otherwise. Any license -* under such intellectual property rights must be express and approved by Intel -* in writing. -* -******************************************************************************** -*/ -/* - ZGESV Example. - ============== - - The program computes the solution to the system of linear - equations with a square matrix A and multiple - right-hand sides B, where A is the coefficient matrix: - - ( 1.23, -5.50) ( 7.91, -5.38) ( -9.80, -4.86) ( -7.32, 7.57) - ( -2.14, -1.12) ( -9.92, -0.79) ( -9.18, -1.12) ( 1.37, 0.43) - ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38) - ( 1.27, 7.29) ( 8.90, 6.92) ( -8.82, 1.25) ( 5.41, 5.37) - - and B is the right-hand side matrix: - - ( 8.33, -7.32) ( -6.11, -3.81) - ( -6.18, -4.80) ( 0.14, -7.71) - ( -5.71, -2.80) ( 1.41, 3.40) - ( -1.60, 3.08) ( 8.54, -4.05) - - Description. - ============ - - The routine solves for X the system of linear equations A*X = B, - where A is an n-by-n matrix, the columns of matrix B are individual - right-hand sides, and the columns of X are the corresponding - solutions. - - The LU decomposition with partial pivoting and row interchanges is - used to factor A as A = P*L*U, where P is a permutation matrix, L - is unit lower triangular, and U is upper triangular. The factored - form of A is then used to solve the system of equations A*X = B. - - Example Program Results. - ======================== - - ZGESV Example Program Results - - Solution - ( -1.09, -0.18) ( 1.28, 1.21) - ( 0.97, 0.52) ( -0.22, -0.97) - ( -0.20, 0.19) ( 0.53, 1.36) - ( -0.59, 0.92) ( 2.22, -1.00) - - Details of LU factorization - ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38) - ( 0.49, 0.47) ( 12.26, -3.57) ( -7.87, -0.49) ( -0.98, 6.71) - ( 0.25, -0.15) ( -0.60, -0.37) (-11.70, -4.64) ( -1.35, 1.38) - ( -0.83, -0.32) ( 0.05, 0.58) ( 0.93, -0.50) ( 2.66, 7.86) - - Pivot indices - 3 3 3 4 -*/ -#include -#include - -/* Complex datatype */ -struct _dcomplex { - double re, im; -}; -typedef struct _dcomplex dcomplex; - -/* ZGESV prototype */ -extern void zgesv(int *n, int *nrhs, dcomplex *a, int *lda, int *ipiv, - dcomplex *b, int *ldb, int *info); -/* Auxiliary routines prototypes */ -extern void print_matrix(char *desc, int m, int n, dcomplex *a, int lda); -extern void print_int_vector(char *desc, int n, int *a); - -/* Parameters */ -#define N 4 -#define NRHS 2 -#define LDA N -#define LDB N - -/* Main program */ -int main() { - /* Locals */ - int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info; - /* Local arrays */ - int ipiv[N]; - dcomplex a[LDA * N] = { - {1.23, -5.50}, {-2.14, -1.12}, {-4.30, -7.10}, {1.27, 7.29}, - {7.91, -5.38}, {-9.92, -0.79}, {-6.47, 2.52}, {8.90, 6.92}, - {-9.80, -4.86}, {-9.18, -1.12}, {-6.51, -2.67}, {-8.82, 1.25}, - {-7.32, 7.57}, {1.37, 0.43}, {-5.86, 7.38}, {5.41, 5.37}}; - dcomplex b[LDB * NRHS] = {{8.33, -7.32}, {-6.18, -4.80}, {-5.71, -2.80}, - {-1.60, 3.08}, {-6.11, -3.81}, {0.14, -7.71}, - {1.41, 3.40}, {8.54, -4.05}}; - /* Executable statements */ - printf(" ZGESV Example Program Results\n"); - /* Solve the equations A*X = B */ - zgesv(&n, &nrhs, a, &lda, ipiv, b, &ldb, &info); - /* Check for the exact singularity */ - if (info > 0) { - printf("The diagonal element of the triangular factor of A,\n"); - printf("U(%i,%i) is zero, so that A is singular;\n", info, info); - printf("the solution could not be computed.\n"); - exit(1); - } - /* Print solution */ - print_matrix("Solution", n, nrhs, b, ldb); - /* Print details of LU factorization */ - print_matrix("Details of LU factorization", n, n, a, lda); - /* Print pivot indices */ - print_int_vector("Pivot indices", n, ipiv); - exit(0); -} /* End of ZGESV Example */ - -/* Auxiliary routine: printing a matrix */ -void print_matrix(char *desc, int m, int n, dcomplex *a, int lda) { - int i, j; - printf("\n %s\n", desc); - for (i = 0; i < m; i++) { - for (j = 0; j < n; j++) - printf(" (%6.2f,%6.2f)", a[i + j * lda].re, a[i + j * lda].im); - printf("\n"); - } -} - -/* Auxiliary routine: printing a vector of integers */ -void print_int_vector(char *desc, int n, int *a) { - int j; - printf("\n %s\n", desc); - for (j = 0; j < n; j++) - printf(" %6i", a[j]); - printf("\n"); -} diff --git a/B_BLAS/readme.md b/B_BLAS/readme.md new file mode 100644 index 0000000..8a0b5d7 --- /dev/null +++ b/B_BLAS/readme.md @@ -0,0 +1,72 @@ +There are several implementations of BLAS including the original Netlib BLAS (formerly BellLabs), OpenBLAS/GotoBLAS2, ATLAS, GSL, ... To compile these examples you need to have any of those installed. To do this you have several possibilities: + 1. Use existing capabilities/repositories of your operating system: if you use these options then you can compile your C code with `-lblas` linker and the compiler automatically knows where to look for libblas.* (e.g. gcc foo.c -lblas) + 1.1. ubuntu: on ubuntu you can install by `sudo apt-get install libblas-dev` + 1.2. mac OS X: Acceleration framework is already built in the OS just link against the frame work `gcc foo.c -framework Accelerate` or `gcc foo.c -lblas` + 2. compile the Netlib BLAS yourself: + 2.1. compile a C code if you have followed this option: following this option you will have a static library `libblas.a` or `librefblas.a` which is an archived collection of object files *.o compiled from Netlib BLAS fortran subroutines. When we want to compile a C code which want to call one of those routines, we also need to link to the gfortran library `libgfortran.*` or use gfortran to compile the object files so I will put two make files here: + + ``` + all: + gcc -c foo.c + gcc -o bar.out foo.o -L path/to/libgfortran.*/ -lgfortran -L path/to/libblas.a -lblas + ``` + + or alternatively compile the code directly with gfortran: + + ``` + all: + gcc -c foo.c + gfortran -o bar.out foo.o -L path/to/libblas.a -lblas + ``` + + or + + ``` + all: + gcc foo.c bar.out -L path/to/libgfortran.*/ -lgfortran -L path/to/libblas.a -lblas + ``` + + 2.2. compile: + + 2.2.1. compile using the unix bash script provided for you in the BZ_common folder. this will provide you with a libblas.a file inside the BZ_common/bin/lib which you can link against later + + 2.2.2. compile it your self: + a. download the latest from netlib: http://www.netlib.org/blas/ + + b. unarchive + + c. run make from terminal + + d. rename the blas_LINUX.a to libblas.a + + e. if you want your compiler to know automatically where to look for the library copy the libblas.a file after to a folder you know. (e.g. /usr/local/lib/) + + d. compile your C code linking against this folder + compiler bla...bla -L your/folder/ -lblas + + 3. install it with other libraries + + 3.1. install it with ATLAS + + 3.2. install it with openblas? + + 3.3. install it with LAPACK + +useful notes: +to use BLAS fortran routine inside the C code you need to declare the BLAS fortran routine inside the C code first. for example if foo is a fortran routine with output and inputs, you need to declare it in yor C code as: + output foo_(inputs) +and then use it as foo_ inside the code. [source](http://stackoverflow.com/questions/22085277/how-to-call-clapack-from-c) + + + +list of functions used in these examples: +1. dgemm : multiplies two matrices +2. dscal : scales a vector/array +3. ddot : dot product of two vector/array + +complete list of BLAS routines/subroutines: + + +sources to be studied: +1. http://www.christophlassner.de/using-blas-from-c-with-row-major-data.html + this sources claims that calling BLAS fortran routines directly is faster than using CBLAS diff --git a/B_BLAS/readme.txt b/B_BLAS/readme.txt deleted file mode 100644 index db343bd..0000000 --- a/B_BLAS/readme.txt +++ /dev/null @@ -1,65 +0,0 @@ -BLAS is a actually not a library but an API, specification or interface which gives you the ability to use functions for linear algebra, including vector-vector, vector-matrix and matrix-matrix operations. there are several implementations of BLAS. Netlib BLAS (formerly belonged to Bell Laboratories), OpenBLAS, ATLAS, ... - - -to compile these examples you need to have BLAS library installed. to do this you have several possibilities: -1. use existing capabilities/repositories of your operating system. if you use these options then you can compile your C code with -lblas linker and the compiler automatically knows where to look for libblas.* (e.g. gcc foo.c -lblas) - 1.1. ubuntu: - on ubuntu you can install by - sudo apt-get build-essential libblas-dev - - 1.2. mac OS X: - Acceleration framework is already built in the OS just link against the frame work - gcc foo.c -framework Accelerate - or - gcc foo.c -lblas - - -2. compile the Netlib BLAS yourself: - 2.1. compile a C code if you have followed this option: - following this option you will have a static library libblas.a or librefblas.a which is an archived collection of object files *.o compiled from Netlib BLAS fortran subroutines. when we want to compile a C code which want to call one of those routines, we also need to link to the gfortran library libgfortran.* or use gfortran to compile the object files so I will put two make files here: - all: - gcc -c foo.c - gcc -o bar.out foo.o -L path/to/libgfortran.*/ -lgfortran -L path/to/libblas.a -lblas - or alternatively compile the code directly with gfortran: - all: - gcc -c foo.c - gfortran -o bar.out foo.o -L path/to/libblas.a -lblas - or - all: - gcc foo.c bar.out -L path/to/libgfortran.*/ -lgfortran -L path/to/libblas.a -lblas - 2.2. compile: - 2.2.1. compile using the unix bash script provided for you in the BZ_common folder. this will provide you with a libblas.a file inside the BZ_common/bin/lib which you can link against later - 2.2.2. compile it your self: - a. download the latest from netlib: http://www.netlib.org/blas/ - b. unarchive - c. run make from terminal - d. rename the blas_LINUX.a to libblas.a - e. if you want your compiler to know automatically where to look for the library copy the libblas.a file after to a folder you know. (e.g. /usr/local/lib/) - d. compile your C code linking against this folder - compiler bla...bla -L your/folder/ -lblas - -3. install it with other libraries - 3.1. install it with ATLAS - 3.2. install it with openblas? - 3.3. install it with LAPACK - -useful notes: -to use BLAS fortran routine inside the C code you need to declare the BLAS fortran routine inside the C code first. for example if foo is a fortran routine with output and inputs, you need to declare it in yor C code as: - output foo_(inputs) -and then use it as foo_ inside the code - -source: http://stackoverflow.com/questions/22085277/how-to-call-clapack-from-c - - - -list of functions used in these examples: -1. dgemm : multiplies two matrices -2. dscal : scales a vector/array -3. ddot : dot product of two vector/array - -complete list of BLAS routines/subroutines: - - -sources to be studied: -1. http://www.christophlassner.de/using-blas-from-c-with-row-major-data.html - this sources claims that calling BLAS fortran routines directly is faster than using CBLAS diff --git a/B_BLAS/ubuntuforums/readme.txt b/B_BLAS/ubuntuforums/readme.txt deleted file mode 100644 index 2f77d88..0000000 --- a/B_BLAS/ubuntuforums/readme.txt +++ /dev/null @@ -1,3 +0,0 @@ -source: https://ubuntuforums.org/showthread.php?t=1740797 - -ddot is the dot product of two vectors/arrays diff --git a/D_LAPACK/Ex02/example1.c b/D_LAPACK/Ex02/example1.c new file mode 100644 index 0000000..ad5e8f3 --- /dev/null +++ b/D_LAPACK/Ex02/example1.c @@ -0,0 +1,76 @@ + +#include +#include + +/* Complex datatype */ +struct _dcomplex { + double re, im; +}; +typedef struct _dcomplex dcomplex; + +/* ZGESV prototype */ +extern void zgesv(int *n, int *nrhs, dcomplex *a, int *lda, int *ipiv, + dcomplex *b, int *ldb, int *info); +/* Auxiliary routines prototypes */ +extern void print_matrix(char *desc, int m, int n, dcomplex *a, int lda); +extern void print_int_vector(char *desc, int n, int *a); + +/* Parameters */ +#define N 4 +#define NRHS 2 +#define LDA N +#define LDB N + +/* Main program */ +int main() { + /* Locals */ + int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info; + /* Local arrays */ + int ipiv[N]; + dcomplex a[LDA * N] = { + {1.23, -5.50}, {-2.14, -1.12}, {-4.30, -7.10}, {1.27, 7.29}, + {7.91, -5.38}, {-9.92, -0.79}, {-6.47, 2.52}, {8.90, 6.92}, + {-9.80, -4.86}, {-9.18, -1.12}, {-6.51, -2.67}, {-8.82, 1.25}, + {-7.32, 7.57}, {1.37, 0.43}, {-5.86, 7.38}, {5.41, 5.37}}; + dcomplex b[LDB * NRHS] = {{8.33, -7.32}, {-6.18, -4.80}, {-5.71, -2.80}, + {-1.60, 3.08}, {-6.11, -3.81}, {0.14, -7.71}, + {1.41, 3.40}, {8.54, -4.05}}; + /* Executable statements */ + printf(" ZGESV Example Program Results\n"); + /* Solve the equations A*X = B */ + zgesv(&n, &nrhs, a, &lda, ipiv, b, &ldb, &info); + /* Check for the exact singularity */ + if (info > 0) { + printf("The diagonal element of the triangular factor of A,\n"); + printf("U(%i,%i) is zero, so that A is singular;\n", info, info); + printf("the solution could not be computed.\n"); + exit(1); + } + /* Print solution */ + print_matrix("Solution", n, nrhs, b, ldb); + /* Print details of LU factorization */ + print_matrix("Details of LU factorization", n, n, a, lda); + /* Print pivot indices */ + print_int_vector("Pivot indices", n, ipiv); + exit(0); +} /* End of ZGESV Example */ + +/* Auxiliary routine: printing a matrix */ +void print_matrix(char *desc, int m, int n, dcomplex *a, int lda) { + int i, j; + printf("\n %s\n", desc); + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) + printf(" (%6.2f,%6.2f)", a[i + j * lda].re, a[i + j * lda].im); + printf("\n"); + } +} + +/* Auxiliary routine: printing a vector of integers */ +void print_int_vector(char *desc, int n, int *a) { + int j; + printf("\n %s\n", desc); + for (j = 0; j < n; j++) + printf(" %6i", a[j]); + printf("\n"); +} diff --git a/D_LAPACK/Ex02/readme.md b/D_LAPACK/Ex02/readme.md new file mode 100644 index 0000000..fac3abc --- /dev/null +++ b/D_LAPACK/Ex02/readme.md @@ -0,0 +1,53 @@ +/* + ZGESV Example. + ============== + + The program computes the solution to the system of linear + equations with a square matrix A and multiple + right-hand sides B, where A is the coefficient matrix: + + ( 1.23, -5.50) ( 7.91, -5.38) ( -9.80, -4.86) ( -7.32, 7.57) + ( -2.14, -1.12) ( -9.92, -0.79) ( -9.18, -1.12) ( 1.37, 0.43) + ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38) + ( 1.27, 7.29) ( 8.90, 6.92) ( -8.82, 1.25) ( 5.41, 5.37) + + and B is the right-hand side matrix: + + ( 8.33, -7.32) ( -6.11, -3.81) + ( -6.18, -4.80) ( 0.14, -7.71) + ( -5.71, -2.80) ( 1.41, 3.40) + ( -1.60, 3.08) ( 8.54, -4.05) + + Description. + ============ + + The routine solves for X the system of linear equations A*X = B, + where A is an n-by-n matrix, the columns of matrix B are individual + right-hand sides, and the columns of X are the corresponding + solutions. + + The LU decomposition with partial pivoting and row interchanges is + used to factor A as A = P*L*U, where P is a permutation matrix, L + is unit lower triangular, and U is upper triangular. The factored + form of A is then used to solve the system of equations A*X = B. + + Example Program Results. + ======================== + + ZGESV Example Program Results + + Solution + ( -1.09, -0.18) ( 1.28, 1.21) + ( 0.97, 0.52) ( -0.22, -0.97) + ( -0.20, 0.19) ( 0.53, 1.36) + ( -0.59, 0.92) ( 2.22, -1.00) + + Details of LU factorization + ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38) + ( 0.49, 0.47) ( 12.26, -3.57) ( -7.87, -0.49) ( -0.98, 6.71) + ( 0.25, -0.15) ( -0.60, -0.37) (-11.70, -4.64) ( -1.35, 1.38) + ( -0.83, -0.32) ( 0.05, 0.58) ( 0.93, -0.50) ( 2.66, 7.86) + + Pivot indices + 3 3 3 4 +*/ diff --git a/README.md b/README.md index 908d4bf..a3c207b 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,33 @@ -# A collection of math tutorials in C -While ago, when I started doing some linear algebra in C, it came to me as a surprise to see there are so few tutorials for BLAS, LAPACK and other fundamental APIs. Despite the fact that they are somehow the building blocks of many other libraries. For that reason I started collecting all the examples I could find all over the net for BLAS, LAPACK, CLAPACK, LAPACKE, ATLAS, OpenBLAS ... in this Github repo. Well, I should warn you that as a mechanical engineer I have little experience in managing such a repo and it might firstly seems as a complete mess to you guys. However if you manage to get over the mess you will find all kind of examples and instructions which might be help. I have tried the most and the ones does not compile I have mentioned. I have modified many of them to be compilable with GNU compilers (gcc, g++ and gfortran). I have made make files which you can read to learn how you can call individual fortran routines in a C or C++ program. I have also put some installations instructions for mac and linux (sorry windows guys!). I want to make sure if you are a C developer you can use any of these libraries without any problems regardless of your platform or hardware +# Description: +When I started doing some linear algebra in C, it came to me as a surprise to see there are so few tutorials for BLAS, LAPACK, and other fundamental APIs. Even though they are somehow the building blocks of many other libraries. So, I started collecting all the examples I could find all over the internet for BLAS, LAPACK, CLAPACK, LAPACKE, ATLAS, OpenBLAS ... in this Github repo. Well, I should warn you that as a mechanical engineer, I have little experience managing such a repo, and it might first seem a complete mess to you guys. However, if you manage to get over the mess, you will find all kinds of examples and instructions that might help. I have tried the most, and the ones that do not compile I have mentioned. I have modified many of them to be compilable with GNU compilers (`gcc`, `g++`, and `gfortran`). I have made `MakeFile`s, which you can read to learn how you can call individual FORTRAN routines in a C or C++ program. I have also put some installation instructions for macOS and Linux (sorry, windows guys!). I want to make sure if you are a C developer, you can use any of these libraries without any problems, regardless of your platform or hardware. -issues: + +# Issues: 1. not able to compile ATLAS on mac OS X. a bug report was made on sourceforce: https://sourceforge.net/p/math-atlas/bugs/261/ -2. for some of the BLAS and CBLAS examples the -lgfortran is requred to compile. I don't know why! (on mac OS X you need to install gfortran and then look for libgfortran.dylib and link against it while compiling) +2. for some of the BLAS and CBLAS examples the -lgfortran is required to compile. I don't know why! (on mac OS X you need to install gfortran and then look for libgfortran.dylib and link against it while compiling) +3. Change the name of the repository from Cmathtuts to something more relevant including linear algebra +4. When to use Fortran or FORTRAN? + -to do: +# To do: 1. make compiling/installation for all libraries for different platforms -2. check the Makefile s on other platforms(tested only on mac OS X) + 1. windows + 2. macOS + 3. GNU/linux +2. check the Makefiles on other platforms(tested only on mac OS X) + + +# Ideas: +1. Adding OpenCL implementations of the APIs -sources to be studied: +# sources to be studied: 1. http://physics.oregonstate.edu/~landaur/nacphy/lapack/cprogp.html 2. https://people.sc.fsu.edu/~jburkardt/c_src/clapack/clapack.html