Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added lmpi_cxx flag which fixed compile bug for GNU mpifort #95

Closed
wants to merge 4 commits into from

Conversation

BorisDeletic
Copy link

Quick fix for compiling on Ubuntu 22.04 with GNU (version 11.3.0)

Copy link
Member

@williamjameshandley williamjameshandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for this contribution @BorisDeletic, and my apologies for taking so long to get to this.

@@ -68,7 +68,7 @@ libchord.so: $(LIB_DIR)/libchord.so

examples: $(EXAMPLES)
$(EXAMPLES): % : $(BIN_DIR)/%
$(PROGRAMS): % : $(BIN_DIR)/%
$(PROGRAMS): % : $(BIN_DIR)/% #!!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is presumably not needed?

@@ -95,7 +95,7 @@ $(DRIVERS_DIR)/polychord_examples.o:
$(patsubst %,$(BIN_DIR)/%,$(PROGRAMS)): $(BIN_DIR)/polychord_% : $(LIB_DIR)/libchord.a $(LIB_DIR)/lib%_likelihood.a $(DRIVERS_DIR)/polychord_%.o
$(LD) $(DRIVERS_DIR)/polychord_$*.o $(LIB_DIR)/libchord.a -o $@ $(LDFLAGS) -l$*_likelihood $(LDLIBS)

$(patsubst polychord_%,$(LIB_DIR)/lib%_likelihood.a,$(PROGRAMS)): $(LIB_DIR)/lib%_likelihood.a: $(LIB_DIR)/libchord.a
$(patsubst polychord_%,$(LIB_DIR)/lib%_likelihood.a,$(PROGRAMS)): $(LIB_DIR)/lib%_likelihood.a: $(LIB_DIR)/libchord.a $(LIKELIHOOD_DIR)/CC_ini/%_likelihood.o
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this essential, or does this hard-code a specific naming convention?

@@ -32,7 +32,7 @@ endif
ifneq (,$(findstring clang,$(shell '$(CXX)' -v 2>&1)))
LDLIBS += -lc++
else
LDLIBS += -lstdc++
LDLIBS += -lstdc++ -lmpi_cxx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have confirmed that this indeed fails without this flag on my Arch Linux system as well

Comment on lines +45 to +119
double potential(double field)
{
// double mu = -2.0;
double lambda = 1.5;

double V = lambda * pow(field * field - 1, 2) + field * field;

return V;
}


double laplacian(double* theta, int n, int i, int j)
{
double kinetic = 0.0;

int idx = i * n + j;

int idx_left = j + 1 == n ? i * n : i * n + (j+1);
int idx_right = j - 1 < 0 ? i * n + (n-1) : i * n + (j-1);
int idx_up = i - 1 < 0 ? (n-1) * n + j : (i-1) * n + j;
int idx_down = i + 1 == n ? j : (i+1) * n + j; // with torus b.c.

kinetic += 2 * pow(theta[idx], 2);
kinetic -= theta[idx] * theta[idx_left];
kinetic -= theta[idx] * theta[idx_right];
kinetic -= theta[idx] * theta[idx_up];
kinetic -= theta[idx] * theta[idx_down];

return kinetic;
}


double magnetisation(double* theta, int n)
{
double mag = 0.0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
mag += theta[i * n + j];
}
}

return mag / (n*n);
}


double loglikelihood (double theta[], int nDims, double phi[], int nDerived)
{
double mu = 5e-1;
double sigma = 1e-1;
double logL= -std::log(std::atan(1)*8*sigma*sigma)*nDims/2.;
// assume n x n = nDims grid for now.
double fieldAction = 0.0;

double kappa = 0.05;
int n = sqrt(nDims);

// kinetic term
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
fieldAction += kappa * laplacian(theta, n, i, j);
}
}

// potential term
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
fieldAction += potential(theta[i * n + j]);
}
}

//lagrangian becomes to T + V after wick rotation

double rad2 = 0.;
for (int i=0;i<nDims;i++)
rad2 += (theta[i]-mu)*(theta[i]-mu);
//lambda=inf gives V(|1|)=0 else inf, so only phi=|1| has non infinite action (non-zero prob)
//therefore we recover ising model with kappa = 1/T

phi[0] = std::sqrt(rad2);
logL -= rad2/(2.*sigma*sigma);

return logL;
phi[0] = magnetisation(theta, n);

return -fieldAction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool though this is, this is probably not the place for this implementation -- we should probably leave it blank for future users to implement their own. I do like the idea of having an example C++ likelihood for people to try out, so perhaps include it as an example (in the same vein as the fortran ones).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants