Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
10 changes: 10 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/Def.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
% // Include files
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "IsingModelAux.h"
% // Additional include directories
% // Additional library directories
% // Additional linker libs/dll etc
% // Additional source files
IsingModelAux.cpp
51 changes: 51 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/IsingModelAux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdio.h>
#include "IsingModelAux.h"
#include <string.h>
#include <assert.h>

int** IsingModelAux::initialization(int n) {
int** latice;
latice = new int*[n];
for (int i = 0; i < n; i++) {
latice[i] = new int[n];
for (int j = 0; j < n; j++) {
latice[i][j] = 1;
}
}
return latice;
}

int IsingModelAux::calculateEnergy(int** latice, int n) {
int energy = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i < n - 1) {
energy += latice[i][j] * latice[i + 1][j];
}
if (j < n - 1) {
energy += latice[i][j] * latice[i][j + 1];
}
}
}

return energy;
}

int IsingModelAux::calculateEnergyDifference(int** latice, int lineIndex, int columnIndex, int n) {
int energyDifference = 0;

if (lineIndex < n - 1) {
energyDifference += latice[lineIndex + 1][columnIndex];
}
if (lineIndex > 0) {
energyDifference += latice[lineIndex - 1][columnIndex];
}
if (columnIndex < n - 1) {
energyDifference += latice[lineIndex][columnIndex + 1];
}
if (columnIndex > 0) {
energyDifference += latice[lineIndex][columnIndex - 1];
}

return 2 * latice[lineIndex][columnIndex] * energyDifference;
}
21 changes: 21 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/IsingModelAux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef ISINGMODELAUX_H
#define ISINGMODELAUX_H

#include <stdio.h>

#define LATICE_DIMENSION 100
#define J 1
#define B 0
#define kT 1
#define STEPS 1000000
#define ITERATIONS 1000

class IsingModelAux
{
public:
static int** initialization(int n);
static int calculateEnergy(int** latice, int n);
static int calculateEnergyDifference(int** latice, int lineIndex, int columnIndex, int n);
};

#endif
Empty file.
64 changes: 64 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/agapia.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module MAIN { listen nil } { read nil }
{

PREPAREDATA
%
COMPUTEALLJOBS

}{ speak nil } { write nil }

module PREPAREDATA {listen nil} {read nil} @Master
{
ClearVectorOfProcessItems(&tasks);
iterations = ITERATIONS;

for (int i = 0; i < iterations; i++){
tasks@[i].iteration = i;
}

} {speak nil} {write iterations : int ; ((iteration : int) tasks [];)}

module COMPUTEALLJOBS {listen nil} {read iterations : int ; ((iteration : int) tasks [];)}
{

I # foreach_s (iterations)
{
COMPUTEITERATION
}

} { speak nil } { write nil }

module I {listen nil } { read n:int}
{

}{speak nil} { write nil }

module COMPUTEITERATION { listen nil } { read iteration : int }
{
int** latice = IsingModelAux::initialization(LATICE_DIMENSION);
int energy = IsingModelAux::calculateEnergy(latice, LATICE_DIMENSION);

for (int i = 0; i < STEPS; i++) {
int lineIndex = rand() % LATICE_DIMENSION;
int columnIndex = rand() % LATICE_DIMENSION;
float randomProbability = ((double)rand() / (RAND_MAX));
float probability = 0.0f;

int energyDifference = IsingModelAux::calculateEnergyDifference(latice, lineIndex, columnIndex, LATICE_DIMENSION);
if (energyDifference < 0) {
probability = 1.0;
}
else {
probability = exp(-energyDifference);
}

if (randomProbability < probability) {
latice[lineIndex][columnIndex] *= -1;
energy -= energyDifference;
}
}

printf("Ended iteration %d with energy = %d\n", iteration, energy);
fflush(stdout);

}{ speak nil } { write nil }
4 changes: 4 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/execution.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo off
set GENPATH=%AGAPIAPATH%\GenerateApp\Release\GenerateApp.exe
%GENPATH% exectype=distributed Def.txt agapia.txt MainInput.txt IsingModelAux.h IsingModelAux.cpp

88 changes: 88 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/temp/AgapiaToCCode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "AgapiaToCCode.h"
#include "ExecutionBlackbox.h"
#include "InputTypes.h"

#include "Includes.h"


void COMPUTEITERATION(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast)
{
// Local variables declaration:
int& iteration = ((IntDataItem*)((SimpleProcessItem*)pNorth->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef();


// User code:
int** latice = IsingModelAux::initialization(LATICE_DIMENSION);
int energy = IsingModelAux::calculateEnergy(latice, LATICE_DIMENSION);

for (int i = 0; i < STEPS; i++) {
int lineIndex = rand() % LATICE_DIMENSION;
int columnIndex = rand() % LATICE_DIMENSION;
float randomProbability = ((double)rand() / (RAND_MAX));
float probability = 0.0f;

int energyDifference = IsingModelAux::calculateEnergyDifference(latice, lineIndex, columnIndex, LATICE_DIMENSION);
if (energyDifference < 0) {
probability = 1.0;
}
else {
probability = exp(-energyDifference);
}

if (randomProbability < probability) {
latice[lineIndex][columnIndex] *= -1;
energy -= energyDifference;
}
}

printf("Ended iteration %d with energy = %d\n", iteration, energy);
fflush(stdout);



}




void I(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast)
{
// Local variables declaration:
int& n = ((IntDataItem*)((SimpleProcessItem*)pNorth->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef();


// User code:



}




void PREPAREDATA(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast)
{
// Local variables declaration:
int& iterations = ((IntDataItem*)((SimpleProcessItem*)pSouth->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef();
VectorProcessItem& tasks = *((VectorProcessItem*)pSouth->m_InputsInBlock[1]);


// User code:
ClearVectorOfProcessItems(&tasks);
iterations = ITERATIONS;

for (int i = 0; i < iterations; i++){
SetInputItemToVector(16, &tasks, i, "iteration", i);
}



}


void InitializeAgapiaToCFunctions()
{
ExecutionBlackbox::Get()->AddAgapiaToCFunction("COMPUTEITERATION", &COMPUTEITERATION);
ExecutionBlackbox::Get()->AddAgapiaToCFunction("I", &I);
ExecutionBlackbox::Get()->AddAgapiaToCFunction("PREPAREDATA", &PREPAREDATA);
}
8 changes: 8 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/temp/Includes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include "IsingModelAux.h"

Binary file not shown.
34 changes: 34 additions & 0 deletions Examples/Part6_HardProblems/3. ISING MODEL/temp/agapia_transf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module MAIN { listen nil } { read nil }
{

PREPAREDATA
%
COMPUTEALLJOBS

}{ speak nil } { write nil }

module PREPAREDATA {listen nil} {read nil}
{
@MASTER
} {speak nil} {write iterations : int ; ((iteration : int) tasks [];)}

module COMPUTEALLJOBS {listen nil} {read iterations : int ; ((iteration : int) tasks [];)}
{

I # foreach_s (iterations)
{
COMPUTEITERATION
}

} { speak nil } { write nil }

module I {listen nil } { read n:int}
{
@
}{speak nil} { write nil }

module COMPUTEITERATION { listen nil } { read iteration : int }
{
@
}{ speak nil } { write nil }

Binary file modified Manual/1.Installation, Usage and Debugging.docx
Binary file not shown.