On Tue, Oct 4, 2011 at 6:59 PM, Shiyuan <span dir="ltr"><<a href="mailto:gshy2014@gmail.com">gshy2014@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<pre><div class="im"><i><br></i>><i> Are you using the PETSc makefiles to compile it? Or did you make up that<br></i>><i> compile line yourself? Why not just use the PETSc makefile to compile it?<br><br><br><br></i></div>
Actually, the compiling command I usedd is generated by <br>
PETSs's makefiles.<i> </i>But I am looking for something like "make getincludedirs; make getpetscflags;<br>make getlinklibs" which can give me the compiling flags Petsc uses to feed nvcc. Are there anything<br>
like that?<div class="im"><br><i><br><br></i>><i><br></i>><i> Presumably cusp/thrust has some pattern for what include files need to be<br></i>><i> included in what order. If you do not know the pattern then why not start by<br>
</i>><i> copying what PETSc does, since that compiles? For example<br></i>><i> cuspvecimpl.h has<br></i>><i><br></i>><i> #include <cublas.h><br></i>><i> #include <cusp/blas.h><br></i>><i> #include <thrust/device_vector.h><br>
</i>><i> #include <thrust/iterator/constant_iterator.h><br></i>><i> #include <thrust/transform.h><br></i>><i> #include <thrust/iterator/permutation_iterator.h><br></i>><i><br></i>><i> while cuspmatimpl.h has<br>
</i>><i><br></i>><i> #include <../src/vec/vec/impls/seq/seqcusp/cuspvecimpl.h><br></i>><i> #include <cusp/csr_matrix.h><br></i>><i> #include <cusp/multiply.h><br></i>><i> /*for MatCreateSeqAIJCUSPFromTriple*/<br>
</i>><i> #include <cusp/coo_matrix.h><br></i>><i><br></i>><i> so start with at least those. Generally just picking a couple of random<br></i>><i> include files from some C++ package (like cusp/thrust) and including them<br>
</i>></div><i> won't work.<br><br><br>I did check the documentation of cusp, and I don't see a requirement about <br></i><i>the order for including headers. It doesn't sound reasonable to require programmers to enforce the order when the programmers<br>
uses only functions from one library. Does it?( I think there is an issue I don't see, please excuse me for my ignorance). And I did <br>try a few experiment where I picked some cusp examples and changed the orders of including headers, and they do work. <br>
<br> <br><br><br></i><div class="im">>I believe that your problem is the clash of VecType between CUSP and PETSc.<br>>In <a href="http://aijcusp.cu" target="_blank">aijcusp.cu</a>, we have<br><br>>#undef VecType<br>
>#include "../src/mat/impls/aij/seq/seqcusp/cuspmatimpl.h"<br>
<br> > Matt<br><br></div>That explains it. But I still don't get the solution. If I want to define a function where I call some functions provided by Petsc and some functions provided by cusp and thrust,<br>In what order should I include the headers? For example, if I want Mat, Vec and cusp::krylov::cg.<br>
If I look at the <a href="http://aijcusp.cu" target="_blank">aijcusp.cu</a> where MatMult_SeqAIJCusp is defined, it has a long list of headers,<br></pre><div style="margin-left:40px"> <br>#include "petscconf.h"<br>
PETSC_CUDA_EXTERN_C_BEGIN<br>
#include "../src/mat/impls/aij/seq/aij.h" /*I "petscmat.h" I*/<br>#include "petscbt.h"<br>#include "../src/vec/vec/impls/dvecimpl.h"<br>#include "private/vecimpl.h"<br>
PETSC_CUDA_EXTERN_C_END<br>#undef VecType<br>#include "../src/mat/impls/aij/seq/seqcusp/cuspmatimpl.h"<br><br><br>#ifdef PETSC_HAVE_TXPETSCGPU<br><br>#include "csr_matrix_data.h"<br>#include "csr_matrix_data_gpu.h"<br>
#include "csr_tri_solve_gpu.h"<br>#include "csr_tri_solve_gpu_level_scheduler.h"<br>#include "csr_spmv_inode.h"<br>#include <algorithm><br>#include <vector><br>#include <string><br>
#include <thrust/sort.h><br>#include <thrust/fill.h><br><br></div><pre><br>But looking at this list of headers, I cannot see what files do I really need and what else is missing if I only want Mat, Vec and cusp::krylov::cg. <br>
Is there a less painful way? Thanks.</pre></blockquote><div><include PETSc headers></div><div>#undef VecType</div><div><include CUSP headers you want></div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<pre><font color="#888888"><br>Shiyuan <br><i></i><i></i><br><br>---------------------------------------------------------------------------------------------------------------------------------------------------------------------</font><div>
<div></div><div class="h5"><br>
<i></i>><i> On Oct 4, 2011, at 2:07 PM, Shiyuan wrote:<br></i>><i><br></i>><i> > Hi,<br></i>><i> > I cannot compiling a source file with petsc.h and cusp headers like<br></i>><i> the following:<br>
</i>><i> ><br></i>><i> > #include"petsc.h"<br></i>><i> > #include<iostream><br></i>><i> > #include "cusp/csr_matrix.h"<br></i>><i> > #include <cusp/krylov/cg.h><br>
</i>><i> > int main(void){<br></i>><i> > std::cout<<"Hello World!"<<std::endl;<br></i>><i> > return 0;<br></i>><i> > }<br></i>><i> ><br></i>><i> > I use the following to compile it:<br>
</i>><i> ><br></i>><i> > nvcc -m64 -O -arch=sm_13 -c --compiler-options="-Wall -Wwrite-strings<br></i>><i> -Wno-strict-aliasing -Wno-unknown-pragmas -O<br></i>><i> -I/home/guest/sgu1/softwares/petsc-dev/include<br>
</i>><i> -I/home/guest/sgu1/softwares/petsc-dev/helena-cxx-nompi-os64-release/include<br></i>><i> -I/usr/local/cuda/include -I/home/guest/sgu1/softwares/cusp-library/<br></i>><i> -I/home/guest/sgu1/softwares/thrust/<br>
</i>><i> -I/home/guest/sgu1/softwares/petsc-dev/include/mpiuni -DCUDA=1<br></i>><i> -I/home/guest/sgu1/softwares/slepc-dev<br></i>><i> -I/home/guest/sgu1/softwares/slepc-dev/helena-cxx-nompi-os64-release/include<br>
</i>><i> -I/home/guest/sgu1/softwares/slepc-dev/include<br></i>><i> -I/home/guest/sgu1/softwares/ImageMagick-6.7.2/include/ImageMagick<br></i>><i> -D__INSDIR__= -I/home/guest/sgu1/softwares/slepc-dev<br></i>><i> -I/home/guest/sgu1/softwares/slepc-dev/helena-cxx-nompi-os64-release/include<br>
</i>><i> -I/home/guest/sgu1/softwares/slepc-dev/include" MyKspTmp4.cu -o MyKspTmp4.o<br></i>><i> ><br></i>><i> > and it gives me error:<br></i>><i> ><br></i>><i> /usr/local/cuda/include/thrust/detail/device/cuda/detail/b40c/vector_types.h(37):<br>
</i>><i> error: expected an identifier<br></i>><i> ><br></i>><i> > I think I did not do it in a correct way. I took a a look at some of<br></i>><i> petsc's .cu files, they usually include a long list of headers. Can petsc.h<br>
</i>><i> directly included in a source code with cusp headers? What's the correct way<br></i>><i> to do it? Does the makefile system in petsc provide the command or flags to<br></i>><i> do that? How can I obtain those flags?<br>
</i>><i> ><br></i>><i> > And after I compile it and obtain .o files, can I use g++ to link the .o<br></i>><i> files with petcs libs and other .o files as usual, i.e.,<br></i>><i> > g++ -o $(BIN_DIR)/$@ $(CPPFLAGS) $@.s $(objects) $(PETSC_LIB)<br>
</i>><i> $(OTHERS)<br></i>><i> > or I need to do some extra steps and some specific linking flags to do<br></i>><i> that?<br></i>><i> > Thanks.<br></i>><i> ><br></i>><i> > Shiyuan<br></i>><i> ><br>
</i>><i> ><br></i>><i> ><br></i>><i><br></i>><i><br></i></div></div></pre>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>