Trang chủHomepage forum Main Diễn đàn AlbumAlbumn ảnh LibraryThư phòng LibraryPhDvn in Media LinkWeb Links BlogTrang cá nhân Member ListDanh sách thành viên New posts Bài viết mới Private MailThư của bạn Control PanelBảng điều khiển SearchGoogle search TiviTivi FAQLuật Ban chã FAQDownload/upload Center




 
Loading...
  Lost your password? Lost your Username? Make a new account!  
Vietscholar forum  
 

Connect with Facebook
Go Back   Vietscholar forum > Academic Life > Computer Science

Notices

PhDvn trên Facebook
Mời các bạn tham gia PhDvn /> </a><a onclick= Facebook group PhDvn và những người bạn.
Thông báo về cách thức tham gia online conference về hội thảo du học châu Âu

Trả lời
 
LinkBack Ðiều Chỉnh Kiếm Trong Bài
  #1 (permalink)  
Old 07-24-2009
haichit.'s Avatar
TM tay to
 
Tham gia ngày: Jun 2009
Đến từ: Stony Brook
Bài gởi: 1,675
Thanks: 118
Thanked 460 Times in 287 Posts
Downloads: 1
Uploads: 1
Gửi tin nhắn qua Skype™ tới haichit.
Default Complie C library statically?

Tình hình là research của em đang tắc vì em loay hoay compile một số C code sang Python code. Vấn đề nó đơn giản thế này thôi. Có một số bác tốt bụng upload pswarm C code (optimization program) lên mạng, em nhanh tay download về. Về cơ bản thì pswarm có hai files là pswarm.c và pattern.c (với header là pswarm.h và pattern.h). Các bác ấy còn tốt bụng hơn nữa là viết một cái wrapper function để có thể gọi C function từ Python interpreter. Cái function ấy nằm trong pswarm_py.c (header là pswarm_py.h).

Nếu chỉ compile shared library thì không có vấn đề gì lớn lắm. Chỉ type mấy cái này

gcc -O3 -fPIC -c ./pattern.c ./pswarm.c ar ruv libpswarm.a pattern.o pswarm.o ranlib libpswarm.a || true gcc -O3 -fPIC -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -I/mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include -c ./pswarm_py.c gcc -shared -O3 -fPIC -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -I/mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include ./pswarm_py.o libpswarm.a -o pswarm_py.so
Diễn giả để các bác đỡ phải đọc code thì nó thế này, gcc sẽ compile ra hai object files là pswarm.o và pattern.o rồi quẳng chúng nó vào libpswarm.a. Sau đó, wrapper function sẽ được compile vơi python header để có file: pswarm_py.o. Sau đó, bằng cái dòng lệnh cuối sẽ compile pswarm.o với libpswarm.a để cho ra cái module pswarm_py.so. Cái này module này có thể dùng trong Python với lệnh đơn giản là "import pyswarm_py".

Nhưng mà oái oăm ở chỗ là cái này dùng shared library nên em không thể dùng để submit job cho computer cluster được. Nên em cần compile thành static libray rồi compile với python để được một chuơng trình to đùng chứa tất cả các module.

Em thử change 'shared' thảnh 'static' nhưng mà gặp error suốt. Có lẽ vấn đề ở đây không phải chỉ là cái option 'static'.

Sau vài ngày lợi dụng bạn google, lang thang trong mấy cái mailing list cùng với việc chạy loăng quăng hỏi bọn labmate nhưng vẫn chưa tìm được chân lý.
Mà trên đây toàn các cao thủ CS, chả lẽ lại không khai sáng cho em được. Thanks những ai đã đọc từ đầu đến cuối. Va appreciate ai giúp em trút bỏ cái nỗi buồn nặng trịch thế này..
__________________
Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.

thay đổi nội dung bởi: haichit., 07-24-2009 lúc 01:08 PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
  #2 (permalink)  
Old 07-24-2009
Tartan's Avatar
Trusted member
 
Tham gia ngày: Jul 2009
Bài gởi: 13
Thanks: 1
Thanked 11 Times in 5 Posts
Downloads: 0
Uploads: 0
Default

Hải compile thử với -lpthread

gcc -static -O3 -fPIC -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -I/mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include ./pswarm_py.o libpswarm.a -o pswarm_py.so -lpthread

Trích:
View Post
gcc -shared -O3 -fPIC -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -I/mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include ./pswarm_py.o libpswarm.a -o pswarm_py.so
.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
I thank Tartan for this original paper:
SpringerCV (08-07-2009)
  #3 (permalink)  
Old 07-24-2009
haichit.'s Avatar
TM tay to
 
Tham gia ngày: Jun 2009
Đến từ: Stony Brook
Bài gởi: 1,675
Thanks: 118
Thanked 460 Times in 287 Posts
Downloads: 1
Uploads: 1
Gửi tin nhắn qua Skype™ tới haichit.
Default

ối giời ơi, it's simply amazing. []
Thanks bác nhé (em là gái thì hôn bác phát, nhưng tiếc là bác không phải là gái để em hôn) [r32)]
__________________
Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.

thay đổi nội dung bởi: haichit., 07-24-2009 lúc 03:40 PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
  #4 (permalink)  
Old 07-25-2009
haichit.'s Avatar
TM tay to
 
Tham gia ngày: Jun 2009
Đến từ: Stony Brook
Bài gởi: 1,675
Thanks: 118
Thanked 460 Times in 287 Posts
Downloads: 1
Uploads: 1
Gửi tin nhắn qua Skype™ tới haichit.
Default

He he, em được voi thì đòi các bác cố vấn thêm tẹo. Chuyện là thế này, có một bác khác cũng tốt bụng, viết cái code bằng FORTRAN và một bác tốt bụng khác viết f2py để chuyển fortran code sang python module. Nếu dùng shared library thì em sẽ dùng thế này

f2py -c --fcompiler=gfortran -m egb egb.f90

Với egb là tên module sau khi compile và egb.f90 là source code.

Nhưng mà em vẫn muốn compile cho static library như post #1 của em. Sau khi search key word 'gfortran' ở log file thì em thấy cái này

/usr/bin/gfortran -Wall -Wall -shared build/build/src.linux-i686-2.5/egbmodule.o build/build/src.linux-i686-2.5/fortranobject.o build/egb_gbneck_3_psi.o build/build/src.linux-i686-2.5/egb-f2pywrappers2.o -L/usr/lib/gcc/i486-linux-gnu/4.1.2 -lgfortran -o ./egb.a
Nói tóm tắt là cái thằng f2py sẽ generate một số object files là egbmodule.o, fortranobject.o, egb_gbneck_3_psi.o, egb-f2pywrappers2.o

Sau đó thì compile lại để ra sản phẩm egb.a

Tuy nhiên cái này vẫn dùng shared library. Em thử import vào python thì nhận được cái error đau buồn này:

/mnt/raidc/haichit/INSTALL/HABANERO/bin/python2.5: error while loading shared libraries: libgfortran.so.1: cannot open shared object file: No such file or directory

Nghĩa là em cần cho cái libgfortran library vào python.

Em cũng thử cho cái keyword mà bác Tartan gợi ý nhưng mà không được (em dốt nên cho bừa vào)...

Em google search thì thấy một cái câu hỏi tuơng tự như của em đang bỏ ngỏ
[Only registered and activated users can see links. ]

Nên ... bác nào nhón tay nói hộ em vài câu. Thanks. Chứ không lão thầy của em lại hí hửng nói: Đấy, ngay từ đầu tao đã bảo mày viết bằng Fortran cho nó lành rồi mà đ. nghe.
__________________
Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.

thay đổi nội dung bởi: haichit., 07-25-2009 lúc 01:52 PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
  #5 (permalink)  
Old 07-25-2009
Tartan's Avatar
Trusted member
 
Tham gia ngày: Jul 2009
Bài gởi: 13
Thanks: 1
Thanked 11 Times in 5 Posts
Downloads: 0
Uploads: 0
Default

Hải thử compile gfortran với --disable-shared


gfortran -Wall --disable-shared build/build/src.linux-i686-2.5/egbmodule.o build/build/src.linux-i686-2.5/fortranobject.o build/egb_gbneck_3_psi.o build/build/src.linux-i686-2.5/egb-f2pywrappers2.o -L/usr/lib/gcc/i486-linux-gnu/4.1.2 -lgfortran -o ./egb.a

Trích:
View Post
/usr/bin/gfortran -Wall -Wall -shared build/build/src.linux-i686-2.5/egbmodule.o build/build/src.linux-i686-2.5/fortranobject.o build/egb_gbneck_3_psi.o build/build/src.linux-i686-2.5/egb-f2pywrappers2.o -L/usr/lib/gcc/i486-linux-gnu/4.1.2 -lgfortran -o ./egb.a
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
  #6 (permalink)  
Old 07-25-2009
haichit.'s Avatar
TM tay to
 
Tham gia ngày: Jun 2009
Đến từ: Stony Brook
Bài gởi: 1,675
Thanks: 118
Thanked 460 Times in 287 Posts
Downloads: 1
Uploads: 1
Gửi tin nhắn qua Skype™ tới haichit.
Default

Cám ơn bác. Lần này thì vẫn chưa được anh ạ. Có lẽ vẫn cần -shared

Đây là vài cái error ở final lines mà em gặp

build/build/src.linux-i686-2.5/fortranobject.o: In function `F2PyDict_SetItemString':
build/src.linux-i686-2.5/fortranobject.c:21: undefined reference to `PyErr_Occurred'
build/src.linux-i686-2.5/fortranobject.c:22: undefined reference to `PyErr_Print'
build/src.linux-i686-2.5/fortranobject.c:23: undefined reference to `PyErr_Clear'
build/build/src.linux-i686-2.5/fortranobject.o: In function `PyFortranObject_New':
build/src.linux-i686-2.5/fortranobject.c:41: undefined reference to `_PyObject_New'
build/src.linux-i686-2.5/fortranobject.c:42: undefined reference to `PyDict_New'
build/src.linux-i686-2.5/fortranobject.c:66: undefined reference to `PyDict_SetItemString'
build/build/src.linux-i686-2.5/fortranobject.o: In function `PyFortranObject_NewAsAttr':
build/src.linux-i686-2.5/fortranobject.c:78: undefined reference to `_PyObject_New'
build/src.linux-i686-2.5/fortranobject.c:80: undefined reference to `PyDict_New'
build/build/src.linux-i686-2.5/fortranobject.o: In function `fortran_dealloc':
build/src.linux-i686-2.5/fortranobject.c:91: undefined reference to `PyMem_Free'
build/src.linux-i686-2.5/fortranobject.c:91: undefined reference to `PyMem_Free'
build/build/src.linux-i686-2.5/fortranobject.o: In function `F2PyDict_SetItemString':
build/src.linux-i686-2.5/fortranobject.c:27: undefined reference to `PyDict_SetItemString'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libgfortranbegin.a(fmain.o): In function `main':
(.text+0x23): undefined reference to `MAIN__'
collect2: ld returned 1 exit status


Theo như em hiểu thì chắc cái error cuối "(.text+0x23): undefined reference to `MAIN__'" yêu cầu code của mình là một chuơng trình đầy đủ, chứ không chỉ là module.

Để em thử compile tất cả các file với options "--disable-shared" như anh gợi ý xem sao.
__________________
Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.

thay đổi nội dung bởi: haichit., 07-25-2009 lúc 08:36 PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
  #7 (permalink)  
Old 07-25-2009
haichit.'s Avatar
TM tay to
 
Tham gia ngày: Jun 2009
Đến từ: Stony Brook
Bài gởi: 1,675
Thanks: 118
Thanked 460 Times in 287 Posts
Downloads: 1
Uploads: 1
Gửi tin nhắn qua Skype™ tới haichit.
Default

Có lẽ --disable-shared không phải là options hay sao ấy [].
Em type cái này
gfortran --disable-shared -c ../../egb_gbneck_3_psi.f90

Thì nhận được cái này.

f951: error: unrecognized command line option "-fdisable-shared"

Em search google như "how to compile fortran module statically by gfortran" cũng không xong.
__________________
Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
  #8 (permalink)  
Old 07-25-2009
haichit.'s Avatar
TM tay to
 
Tham gia ngày: Jun 2009
Đến từ: Stony Brook
Bài gởi: 1,675
Thanks: 118
Thanked 460 Times in 287 Posts
Downloads: 1
Uploads: 1
Gửi tin nhắn qua Skype™ tới haichit.
Default

Hí hoáy nhìn lại cái dòng compile cuối cùng

/usr/bin/gfortran -Wall -Wall -shared build/build/src.linux-i686-2.5/egbmodule.o build/build/src.linux-i686-2.5/fortranobject.o build/egb_gbneck_3_psi.o build/build/src.linux-i686-2.5/egb-f2pywrappers2.o -L/usr/lib/gcc/i486-linux-gnu/4.1.2 -lgfortran -lpthread -o ./egb.a

Thì thấy 4 object files egbmodule.o, fortranobject.o, egb_gbneck_3_psi.o, egb-f2pywrappers2.o

egbmodule.o <-- egbmodule.c
fortranobject.o <-- fortranobject.c
egb_gbneck_3_psi.o <-- egb_gbneck_3_psi.f90
egb-f2pywrappers2.o <-- egb-f2pywrappers2.c


Em loay hoay compile manually, và thêm --disable-shared thì thấy cái error lúc đầu. Sau đó thì thử thay từ đó bằng -static rồi compile vào một file lớn thì vẫn không xong, kết quả cuối cùng vẫn là

error while loading shared libraries: libgfortran.so.1: cannot open shared object file: No such file or directory
[]

Còn đây là command để compile mấy object file trên

gcc -pthread -static -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Ibuild/src.linux-i686-2.5 -I/mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -c egbmodule.c

gcc -O3 -fPIC -static -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -I/mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include -c fortranobject.c

gcc -pthread -static -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -I/mnt/raidc/haichit/GB/software/STATIC.COMPILE/build/src.linux-i686-2.5 -I -I/mnt/raidc/haichit/GB/software/STATIC.COMPILE/build/ /mnt/raidc/haichit/INSTALL/HABANERO/lib/python2.5/site-packages/numpy/core/include -I/mnt/raidc/haichit/INSTALL/HABANERO/include/python2.5 -c egb-f2pywrappers2.f90
__________________
Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.

thay đổi nội dung bởi: haichit., 07-25-2009 lúc 09:43 PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn FaceBook
Trả lời

Bookmarks

Latex Maths & Physics Editor ...


Ðang đọc: 1 (0 thành viên và 1 khách)
 
Ðiều Chỉnh Kiếm Trong Bài
Kiếm Trong Bài:

Kiếm Chi Tiết

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt
Trackbacks are Mở
Pingbacks are Mở
Refbacks are Mở


Chủ đề giống nhau
Ðề tài Người Gởi Chuyên mục Trả lời Bài viết sau cùng
Question library khi phỏng vấn xin học bổng VEF/322, từ những người đã thành công haichit. Du học Hoa Kỳ, Canada 12 08-11-2010 08:44 PM
Vietscholar Library pirimidin Library 0 07-11-2010 10:12 PM
a good handbook of library ejournal list ailatoi1984 Chia sẻ tài nguyên 0 07-28-2009 01:11 AM


 
PhDvn.org
   
All times are GMT -5. The time now is 08:32 AM.  
 
Style by TheProphet  
 

Search Engine Optimization by vBSEO 3.3.0