Skip to content

Commit

Permalink
rename library objects with serial/mpi suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Jackson committed Jan 15, 2025
1 parent 7f1b117 commit 70caf27
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ install: default
if [ -f "utility/w90pov/w90pov" ]; then install -m755 "utility/w90pov/w90pov" "$(DESTDIR)$(PREFIX)/bin/w90pov"; fi;
if [ -f "utility/w90vdw/w90vdw.x" ]; then install -m755 "utility/w90vdw/w90vdw.x" "$(DESTDIR)$(PREFIX)/bin/w90vdw.x"; fi;
install -d $(DESTDIR)$(PREFIX)/lib/
if [ -f "libwannier.a" ]; then install -m644 "libwannier.a" "$(DESTDIR)$(PREFIX)/lib/libwannier.a"; fi;
if [ -f "libwannier.a" ]; then $(MAKE) pkgconfig; fi;
if [ -f "$(LIBRARYV2)" ]; then install -m644 "$(LIBRARYV2)" "$(DESTDIR)$(PREFIX)/lib/$(LIBRARYV2)"; fi;
if [ -f "$(LIBRARYV2)" ]; then $(MAKE) pkgconfig; fi;

all: wannier lib post w90chk2chk w90pov w90vdw w90spn2spn

Expand Down Expand Up @@ -92,7 +92,7 @@ clean:
cd $(ROOTDIR)/test-suite && ./clean_tests

veryclean: clean
cd $(ROOTDIR) && rm -f wannier90.x postw90.x libwannier.a libwan2.a w90chk2chk.x w90spn2spn.x libwan2-extra.a
cd $(ROOTDIR) && rm -f wannier90.x postw90.x libwannier.a w90chk2chk.x w90spn2spn.x libwannier-extra.a
cd $(ROOTDIR)/test-suite && ./clean_tests -i

thedoc:
Expand Down
11 changes: 7 additions & 4 deletions src/Makefile.2
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ else
COMMS = serial
endif

# Contains definition of OBJS, OBJS_POST, LIBRARY, DYNLIBRARY
include ../Makefile.header

POSTDIR = ../postw90/

ifeq ($(COMMS),mpi08)
USEMPI=y
TEMP1 = -DMPI -DMPI08
TEMP2 = $(MPIF90)
else ifeq ($(COMMS),mpih)
USEMPI=y
TEMP1 = -DMPI -DMPIH
TEMP2 = $(MPIF90)
else ifeq ($(COMMS),mpi90)
USEMPI=y
TEMP1 = -DMPI -DMPI90
TEMP2 = $(MPIF90)
else ifeq ($(COMMS),mpi)
USEMPI=y
# default to f90 style "use mpi"
TEMP1 = -DMPI -DMPI90
TEMP2 = $(MPIF90)
Expand All @@ -34,6 +35,8 @@ TEMP1 =
TEMP2 = $(F90)
endif

# Contains definition of OBJS, OBJS_POST, LIBRARY, DYNLIBRARY
include ../Makefile.header

wannier libs dynlibs w90chk2chk w90spn2spn: POSTOPTS = $(TEMP1)
wannier libs dynlibs w90chk2chk w90spn2spn: COMPILER = $(TEMP2)
Expand Down Expand Up @@ -112,7 +115,7 @@ library_extra.o : ../library_extra.F90
c_interface.o : ../c_interface.F90 \
library_interface.o comms.o constants.o error_base.o io.o kmesh.o overlap.o plot.o transport.o \
types.o wannier90_readwrite.o wannier90_types.o wannierise.o
$(COMPILER) $(POSTOPTS) $(FCOPTS) -c ../c_interface.F90
$(COMPILER) $(POSTOPTS) $(FCOPTS) -c ../c_interface.F90 --std=f2018

constants.o: ../constants.F90
$(COMPILER) $(POSTOPTS) $(FCOPTS) -c ../constants.F90
Expand Down
20 changes: 12 additions & 8 deletions src/Makefile.header
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ WRAPSRC = ../src/constants.F90 ../src/types.F90 ../src/wannier90_readwrite.F90 \
../src/library_extra.F90
# ../src/postw90/postw90_types.F90../src/postw90/pw90_library.F90

LIBRARYV2 = ../../libwan2.a
LIBRARYV2EXTRA = ../../libwan2-extra.a

## Dynamic library section
## Define some defaults (good for linux) if none is defined in the make.inc
Expand All @@ -30,11 +28,17 @@ LIBRARYV2EXTRA = ../../libwan2-extra.a
## calling it .so and using -shared often works equally well)
## NOTE: if you want to compile the dynamic library, you have to compile
## everything with -fPIC usually, on 64bit systems
DYNLIBRARYEXTENSION ?= so
SHAREDLIBFLAGS ?=-shared -fPIC
SHAREDLIBFLAGS ?=-shared -Wl,-soname,libwannier90.so.4 -fPIC

## Define the filename
DYNLIBBASE = wannier_$(COMMS)
DYNLIBEXTRABASE = wannier-extra_$(COMMS)
DYNLIBRARY = lib$(DYNLIBBASE).$(DYNLIBRARYEXTENSION)
DYNLIBRARYEXTRA = lib$(DYNLIBEXTRABASE).$(DYNLIBRARYEXTENSION)
ifdef USEMPI
LIBSUFFIX=mpi
else
LIBSUFFIX=serial
endif

DYNLIBBASE = wannier90_$(LIBSUFFIX)
LIBRARYV2 = ../../libwannier90_$(LIBSUFFIX).a
LIBRARYV2EXTRA = ../../libwannier90-extra_$(LIBSUFFIX).a
DYNLIBRARY = libwannier90_$(LIBSUFFIX).so.4
DYNLIBRARYEXTRA = libwannier90-extra_$(LIBSUFFIX).so.4
4 changes: 2 additions & 2 deletions src/wannier90.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __wannier90_h__
#define __wannier90_h__
#ifndef WANNIER90_H
#define WANNIER90_H

#include <ISO_Fortran_binding.h>
#include <string.h>
Expand Down
4 changes: 2 additions & 2 deletions test-suite/libv2-demo2/makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include ../../make.inc
.cc.o:
$(CXX) -I ../../src -c $<
$(CXX) -g -I ../../src -c $< -fpermissive
wannier_c.x : wannier.o ../../libwan2.a
$(CXX) wannier.o ../../libwan2.a $(LIBS) -lgfortran -o $@
$(CXX) -g wannier.o ../../libwan2.a $(LIBS) -lgfortran -o $@ -fpermissive
clean:
@rm wannier.o wannier_c.x
4 changes: 4 additions & 0 deletions test-suite/libv2-demo2/test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

extern "C" {
#include "wannier90.h"
}
56 changes: 33 additions & 23 deletions test-suite/libv2-demo2/wannier.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "wannier90.hh"

extern "C" {
#include "wannier90.h"
}
#include <cassert>
#include <complex>
#include <filesystem>
#include <fstream>
#include <iomanip>
Expand Down Expand Up @@ -62,25 +66,29 @@ int main(int argc, char* argv[]) {
int nb = nband(filestring);
if (nb == 0) nb = nw; // not specified in input



///////////// LIBRARY

void* w90glob = w90_create(); // allocate an instance of the library data block
w90_data w90glob;
w90_create(w90glob);

cset_option(w90glob, "kpoints", &kpt[0][0], nk, 3);
cset_option(w90glob, "mp_grid", nkabc);
cset_option(w90glob, "num_bands", nb);
cset_option(w90glob, "num_kpts", nk);
cset_option(w90glob, "num_wann", nw);
cset_option(w90glob, "unit_cell_cart", &uc[0][0], 3, 3);
w90_set_option_double2d(w90glob, "kpoints", &kpt[0][0], nk, 3);
w90_set_option_int1d(w90glob, "mp_grid", nkabc, 3);
w90_set_option_int(w90glob, "num_bands", nb);
w90_set_option_int(w90glob, "num_kpts", nk);
w90_set_option_int(w90glob, "num_wann", nw);
w90_set_option_double2d(w90glob, "unit_cell_cart", &uc[0][0], 3, 3);

int ierr;
cinput_setopt(w90glob, root.c_str(), ierr); // process necessary library options
assert(ierr == 0);
cinput_reader(w90glob, ierr); // process any other options
w90_input_setopt(w90glob, root.c_str(), ierr); // process necessary library options

w90_input_reader_c(w90glob, ierr); // process any other options
assert(ierr == 0);

int nnfd;
cget_nn(w90glob, nnfd); // return number of NN in FD scheme
w90_get_nn_c(w90glob, &nnfd); // return number of NN in FD scheme
cout << nnfd <<endl;

// prepare nnkp and gkpb arrans
// horrible contortions to make multidimensional arrays...
Expand All @@ -101,8 +109,8 @@ int main(int argc, char* argv[]) {
}
}

cget_nnkp(w90glob, &nnkp[0][0]); // return indexes of NN k-points in FD scheme
cget_gkpb(w90glob, &gkpb[0][0][0]);
w90_get_nnkp_c(w90glob, &nnkp[0][0]); // return indexes of NN k-points in FD scheme
w90_get_gkpb_c(w90glob, &gkpb[0][0][0]);

// printout nnkp data for testing
for (int i = 0; i < nk; ++i) {
Expand All @@ -120,10 +128,10 @@ int main(int argc, char* argv[]) {
complex<double>* umat = new complex<double>[nw * nw * nk];
double* edata = new double[nb * nk];

cset_m_local(w90glob, mdata); // m matrix
cset_u_matrix(w90glob, umat); // results returned here
cset_u_opt(w90glob, adata); // initial projections
cset_eigval(w90glob, edata); // contains eigenvalues
w90_set_m_local_c(w90glob, mdata); // m matrix
w90_set_u_matrix_c(w90glob, umat); // results returned here
w90_set_u_opt_c(w90glob, adata); // initial projections
w90_set_eigval_c(w90glob, edata); // contains eigenvalues

fn = root + ".mmn";
readm(fn, nnkp, gkpb, nk, nb, nnfd, mdata);
Expand All @@ -134,15 +142,17 @@ int main(int argc, char* argv[]) {
fn = root + ".eig";
if (filesystem::exists(fn)) reade(fn, nk, nb, edata);

cdisentangle(w90glob, ierr);
cproject(w90glob, ierr);
w90_disentangle_c(w90glob, ierr);
w90_project_overlap_c(w90glob, ierr);
assert(ierr == 0);

cwannierise(w90glob, ierr);
w90_wannierise_c(w90glob, ierr);
assert(ierr == 0);

// cget_centres(w90glob, wannier_ctr);
// cget_spreads(w90glob, wannier_spr);
double wannier_ctr[nw];
double wannier_spr[nw];
w90_get_centres_c(w90glob, wannier_ctr);
w90_get_spreads_c(w90glob, wannier_spr);
w90_delete(w90glob);

return 0;
Expand Down

0 comments on commit 70caf27

Please sign in to comment.