Create new FQHE code

From diagham
Revision as of 21:32, 7 May 2016 by Regnault (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Adding a new single program

Adding a single program to DiagHam is rather simple. We assume that you want to add a the program FQHESphereMyCode that will be built from the source file FQHESphereMyCode.cc. Since we are dealing with FQHE on the sphere as suggested by the file name, we should include our source file into the directory FQHE/src/Programs/FQHEOnSphere.

To compile our code, we just have to change a few lines in the file Makefile.am located in the FQHE/src/Programs/FQHEOnSphere. We should first add FQHESphereMyCode to the list of binary program


   bin_PROGRAMS=QHEFermions QHEBosons FQHESphereBosonsCorrelation ... [many codes here] FQHESphereBosonsFilterOccupation FQHESphereQuasiholeMatrixElements FQHESphereMyCode


We also need to provide one line that indicates the name of the source file. This should look like

   FQHESphereBosonsFilterOccupation_SOURCES=FQHESphereBosonsFilterOccupation.cc
   
   FQHESphereQuasiholeMatrixElements_SOURCES=FQHESphereQuasiholeMatrixElements.cc
   
   FQHESphereMyCode_SOURCES=FQHESphereMyCode.cc


Last but not least, we need to provide the dependencies and the linkage option. The simplest thing to do is to use a cut/paste from an already existing program i.e. at the very end of Makefile.am


   FQHESphereQuasiholeMatrixElements_DEPENDENCIES=$(top_builddir)/src/Architecture/libArchitecture.a $(top_builddir)/src/Architecture/ArchitectureOperation/libArchitectureOperation.a ... [a very long line of dependencies] ... $(top_builddir)/FQHE/src/Operator/libQHEOperator.a
   
   FQHESphereQuasiholeMatrixElements_LDADD=-L$(top_builddir)/src/Architecture -L$(top_builddir)/src/Architecture/ArchitectureOperation ... [a very long line of linkage option] ..  @GMP_LIBS@ @INTELMKL_LIBS@

   FQHESphereMyCode_DEPENDENCIES=$(top_builddir)/src/Architecture/libArchitecture.a $(top_builddir)/src/Architecture/ArchitectureOperation/libArchitectureOperation.a ... [a very long line of dependencies] ... $(top_builddir)/FQHE/src/Operator/libQHEOperator.a
   
   FQHESphereMyCode_LDADD=-L$(top_builddir)/src/Architecture -L$(top_builddir)/src/Architecture/ArchitectureOperation ... [a very long line of linkage option] ..  @GMP_LIBS@ @INTELMKL_LIBS@


Once it is done, we just have to type make to recompile the code, including the new one.

As an example, here is a small source code that can be used as an example for File:FQHESphereMyCode.cc


   #include "Matrix/RealSymmetricMatrix.h"
   #include "Matrix/RealMatrix.h"
   
   #include "Options/Options.h"
   
   #include <iostream>
   
       
   using std::cout;
   using std::endl;
   
   
   int main(int argc, char** argv)
   {
     cout.precision(14);
     
     // this part of code will take care of the command line options
     OptionManager Manager ("FQHESphereMyCode" , "0.01");
     OptionGroup* SystemGroup = new OptionGroup ("system options");
     OptionGroup* MiscGroup = new OptionGroup ("misc options");  
     Manager += SystemGroup;
     Manager += MiscGroup;
   
     (*SystemGroup) += new  SingleStringOption ('r', "real-matrix", "name of the file containing the real matrix we want to display");
     (*SystemGroup) += new  SingleStringOption ('s', "sym-matrix", "name of the file containing the real symmetric matrix we want to diagonalize");
     (*MiscGroup) += new BooleanOption  ('h', "help", "display this help");
   
     if (Manager.ProceedOptions(argv, argc, cout) == false)
       {
         cout << "see man page for option syntax or type FQHESphereMyCode -h" << endl;
         return -1;
       }
     if (Manager.GetBoolean("help") == true)
       {
         Manager.DisplayHelp (cout);
         return 0;
       }
   
     // check if the file names have been provided
     if (Manager.GetString("real-matrix") == 0)
       {
         cout << "no real matrix has been provided" << endl; 
         return 0;
       }
     if (Manager.GetString("sym-matrix") == 0)
       {
         cout << "no real symmetric matrix has been provided" << endl; 
         return 0;
       }
   
     // read and display the real matrix
     
     RealMatrix Matrix1;
     if (Matrix1.ReadMatrix(Manager.GetString("real-matrix")) == false) 
       {
         cout << "can't read " << Manager.GetString("real-matrix") << endl;
         return 0;
       }
     cout << "content of " << Manager.GetString("real-matrix") << " : " << endl;
     cout << Matrix1 << endl;
   
   
     // read and diagonalize the real symmetric matrix
   
    RealSymmetricMatrix Matrix2;
    if (Matrix2.ReadMatrix(Manager.GetString("sym-matrix")) == false) 
      {
        cout << "can't read " << Manager.GetString("sym-matrix") << endl;
         return 0;
      }
    RealDiagonalMatrix TmpDiagonalMatrix  (Matrix2.GetNbrRow());
    Matrix2.LapackDiagonalize(TmpDiagonalMatrix);
    cout << "eigenvalues of " << Manager.GetString("sym-matrix") << " : " << endl;
    for (int i = 0; i < TmpDiagonalMatrix.GetNbrRow(); ++i)
      {    
        cout << TmpDiagonalMatrix[i] << endl;
      }
    
    return 0;
   }


This simple code reads a real matrix from a file and shows its content. It also reads a real symmetric matrix and computes its eigenvalues. The code should be used as following

``$PATHTODIAGHAM/build/FQHE/src/Programs/FQHEOnSphere/FQHESphereMyCode --sym-matrix fermions_qh_k_1_r_2_n_3_nphi_9_lz_5_cdc_5.mat --real-matrix fermions_qh_k_1_r_2_n_3_nphi_9_lz_1_c_-7.mat

Adding a new package

If you want to write some new codes using DiagHam building blocks, you need some work to get things done in a clean way, especially if you want to update the DiagHam while avoiding conflicts. On this page we will add a new code into the FQHE list of programs by adding a whole package. Go into the FQHE/src/Programs

cd FQHE/src/Programs

and create a directory where you will put your code. Let's call it MyCodes

mkdir MyCodes

In order to work on a concrete example, we copy FQHESphereBosonsFuseParticles.cc into MyCodes it rename to Test.cc

cp FQHEOnSphere/FQHESphereBosonsFuseParticles.cc MyCodes/Test.cc

To compile your new code , you need to edit a few files. First in FQHE/src/Programs, edit Makefile.am to include MyCodes as a subdirectory. Thus change

   SUBDIRS=FQHEOnSphere FQHEOnDisk FQHEOnTorus FQHEOnLattice 

to

   SUBDIRS=FQHEOnSphere FQHEOnDisk FQHEOnTorus FQHEOnLattice MyCodes

go into the DiagHam root directory and edit the configure.in file to change from

   AC_OUTPUT(Makefile src/Makefile src/Programs/Makefile ... blah blah ... Spin/src/Tools/Makefile Spin/src/Tools/SpinFiles/Makefile)

to

   AC_OUTPUT(Makefile src/Makefile src/Programs/Makefile ... blah blah ... Spin/src/Tools/Makefile Spin/src/Tools/SpinFiles/Makefile FQHE/src/Programs/MyCodes/Makefile)

Now go into the FQHE/src/Programs/MyCodes and create a file called Makefile.am with the following containt (download the file Media:FQHEExampleMakefile.am)

   SUBDIRS= 
    
   bin_PROGRAMS=Test
   
   Test_SOURCES=Test.cc
   
   Test_DEPENDENCIES=$(top_builddir)/src/Architecture/libArchitecture.a ... blah blah ... $(top_builddir)/src/MathTools/RandomNumber/libRandomNumber.a
   
   Test_LDADD=-L$(top_builddir)/src/Architecture ... blah blah ... @BLAS_LIBS@ @FORTRAN2C_LIBS@ @BZ2_LIBS@

Each time you create a new program in MyCodes, you need to add one entry one bin_PROGRAMS line, one line for the source (like Test_SOURCES=Test.cc), one line for dependencies (like Test_DEPENDENCIES=...) and one line for linking (Test_LDADD=...). All the other steps are not necessary when you add codes into MyCodes.

We are now getting close to compile the new code. First go in the DiagHam root directory and run

./bootstrap.sh

Everything is now ready. You can proceed with the compilation i.e. go in the build directory an run

`make -jX`

like during the install procedure. Of course, each time you modify your code (like Test.cc), you need to recompile. If you now look into build/FQHE/src/Programs/MyCodes, you will see your program Test waiting for you...