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
17 changes: 17 additions & 0 deletions Code/C/fem/constraint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#include "constraint.h"

void constraintPrint(Constraint *theConstraint){
printf("Constraint No. : %d \n", theConstraint->tag);
printf("Node No. : %d \n", theConstraint->NodeTag);
printf("Constraint: %d %d %d \n", theConstraint->DOF[0], theConstraint->DOF[1], theConstraint->DOF[2]);
}

void constraintSetup(Constraint *theConstraint, int tag, int NodeTag, int DOF1, int DOF2, int DOF3) {
theConstraint->tag = tag;
theConstraint->NodeTag = NodeTag;
theConstraint->DOF[0] = DOF1;
theConstraint->DOF[1] = DOF2;
theConstraint->DOF[2] = DOF3;
theConstraint->next = NULL;
}
17 changes: 17 additions & 0 deletions Code/C/fem/constraint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _CONSTRAINT //if no definition for "_CONSTRAINT"
#define _CONSTRAINT
//preventing the compiler from loading it again if multiple reference to this file exists.

#include <stdio.h>

typedef struct constraint {
int tag;
int NodeTag;
int DOF[3];
struct constraint *next;
} Constraint;

void constraintPrint(Constraint *);
void constraintSetup(Constraint *, int tag, int NodeTag, int DOF1, int DOF2, int DOF3);

#endif
39 changes: 38 additions & 1 deletion Code/C/fem/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
void domainPrint(Domain *theDomain) {
printf("The Nodes:\n");
domainPrintNodes(theDomain);
domainPrintConstraint(theDomain);
}

void domainAddNode(Domain *theDomain, int tag, double crd1, double crd2) {
Expand All @@ -17,6 +18,7 @@ void domainAddNode(Domain *theDomain, int tag, double crd1, double crd2) {
} else {
theNextNode->next = NULL;
}

theDomain->theNodes = theNextNode;
}

Expand All @@ -32,10 +34,45 @@ Node *domainGetNode(Domain *theDomain, int nodeTag) {
Node *theCurrentNode = theDomain->theNodes;
while (theCurrentNode != NULL) {
if (theCurrentNode->tag == nodeTag) {
return theCurrentNode;
return theCurrentNode; //return gets out of the program
} else {
theCurrentNode = theCurrentNode->next;
}
};
return NULL;
}


void domainAddConstraint(Domain *theDomain, int tag, int NodeTag, int DOF1, int DOF2, int DOF3) {
Constraint *theNextConstraint = (Constraint *)malloc(sizeof(Constraint));
constraintSetup(theNextConstraint, tag, NodeTag, DOF1, DOF2, DOF3);

if (theDomain->theConstraints != NULL) {
theNextConstraint->next = theDomain->theConstraints;

} else {
theNextConstraint->next = NULL;
}

theDomain->theConstraints = theNextConstraint;
}

void domainPrintConstraint(Domain *theDomain) {
Constraint *theCurrentConstraint = theDomain->theConstraints;
while (theCurrentConstraint != NULL) {
constraintPrint(theCurrentConstraint);
theCurrentConstraint = theCurrentConstraint->next;
};
}

Constraint *domainGetConstraint(Domain *theDomain, int constraintTag) {
Constraint *theCurrentConstraint = theDomain->theConstraints;
while (theCurrentConstraint != NULL) {
if (theCurrentConstraint->tag == constraintTag) {
return theCurrentConstraint; //return gets out of the program
} else {
theCurrentConstraint = theCurrentConstraint->next;
}
};
return NULL;
}
8 changes: 8 additions & 0 deletions Code/C/fem/domain.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#include "node.h"
#include "constraint.h"

typedef struct struct_domain {
Node *theNodes;
Constraint *theConstraints;

} Domain;

void domainPrint(Domain *theDomain);

void domainAddNode(Domain *theDomain, int tag, double crd1, double crd2);
void domainPrintNodes(Domain *theDomain);
Node *domainGetNode(Domain *, int nodeTag);

void domainAddConstraint(Domain *theDomain, int tag, int NodeTag, int DOF1, int DOF2, int DOF3);
void domainPrintConstraint(Domain *theDomain);
Constraint *domainGetConstraint(Domain *, int constaintTag);

79 changes: 79 additions & 0 deletions Code/C/fem/domain1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <stdio.h>
#include <stdlib.h>
#include "domain.h"
#include "node.h"

void domainPrint(Domain *theDomain) {
printf("The Nodes:\n");
domainPrintNodes(theDomain);
domainPrintConstraint(theDomain);
}

void domainAddNode(Domain *theDomain, int tag, double crd1, double crd2) {
Node *theNextNode = (Node *)malloc(sizeof(Node));
nodeSetup(theNextNode, tag, crd1, crd2);

if (theDomain->theNodes != NULL) {
theNextNode->next = theDomain->theNodes;

} else {
theNextNode->next = NULL;
}

theDomain->theNodes = theNextNode;
}

void domainPrintNodes(Domain *theDomain) {
Node *theCurrentNode = theDomain->theNodes;
while (theCurrentNode != NULL) {
nodePrint(theCurrentNode);
theCurrentNode = theCurrentNode->next;
};
}

Node *domainGetNode(Domain *theDomain, int nodeTag) {
Node *theCurrentNode = theDomain->theNodes;
while (theCurrentNode != NULL) {
if (theCurrentNode->tag == nodeTag) {
return theCurrentNode; //return gets out of the program
} else {
theCurrentNode = theCurrentNode->next;
}
};
return NULL;
}


void domainAddConstraint(Domain *theDomain, int tag, int NodeTag, int DOF1, int DOF2, int DOF3) {
Constraint *theNextConstraint = (Constraint *)malloc(sizeof(Constraint));
constraintSetup(theNextConstraint, tag, NodeTag, DOF1, DOF2, DOF3);

if (theDomain->theConstraints != NULL) {
theNextConstraint->next = theDomain->theConstraints;

} else {
theNextConstraint->next = NULL;
}

theDomain->theConstraints = theNextConstraint;
}

void domainPrintConstraint(Domain *theDomain) {
Constraint *theCurrentConstraint = theDomain->theConstraints;
while (theCurrentConstraint != NULL) {
constraintPrint(theCurrentConstraint);
theCurrentConstraint = theCurrentConstraint->next;
};
}

Constraint *domainGetConstraint(Domain *theDomain, int constraintTag) {
Constraint *theCurrentConstraint = theDomain->theConstraints;
while (theCurrentConstraint != NULL) {
if (theCurrentConstraint->tag == constraintTag) {
return theCurrentConstraint; //return gets out of the program
} else {
theCurrentConstraint = theCurrentConstraint->next;
}
};
return NULL;
}
19 changes: 19 additions & 0 deletions Code/C/fem/domain1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "node.h"
#include "constraint.h"

typedef struct struct_domain {
Node *theNodes;
Constraint *theConstraints;

} Domain;

void domainPrint(Domain *theDomain);

void domainAddNode(Domain *theDomain, int tag, double crd1, double crd2);
void domainPrintNodes(Domain *theDomain);
Node *domainGetNode(Domain *, int nodeTag);

void domainAddConstraint(Domain *theDomain, int tag, int NodeTag, int DOF1, int DOF2, int DOF3);
void domainPrintConstraint(Domain *theDomain);
Constraint *domainGetConstraint(Domain *, int constaintTag);

12 changes: 12 additions & 0 deletions Code/C/fem/main.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#include "node.h"
#include "domain.h"
#include "constraint.h"

int main(int argc, char **argv) {
Domain theDomain;

theDomain.theNodes=0;

domainAddNode(&theDomain, 1, 0.0, 0.0);
domainAddNode(&theDomain, 2, 0.0, 2.0);
domainAddNode(&theDomain, 3, 1.0, 1.0);

theDomain.theConstraints = 0;
domainAddConstraint(&theDomain, 1, 1, 1,1,1);
domainAddConstraint(&theDomain, 2, 3, 1,0,0);

domainPrint(&theDomain);

// get and print singular node
printf("\nsingular node:\n");
Node *theNode = domainGetNode(&theDomain, 2);
nodePrint(theNode);

// get and print constraints
printf("\nconstraints:\n");
Constraint *theConstraint = domainGetConstraint(&theDomain, 1);
constraintPrint(theConstraint);
}
28 changes: 28 additions & 0 deletions Code/C/fem/main1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "node.h"
#include "domain.h"
#include "constraint.h"

int main(int argc, char **argv) {
Domain theDomain;

theDomain.theNodes = 0; //initialize the pointers
domainAddNode(&theDomain, 1, 0.0, 0.0);
domainAddNode(&theDomain, 2, 0.0, 2.0);
domainAddNode(&theDomain, 3, 1.0, 1.0);

theDomain.theConstraints = 0;
domainAddConstraint(&theDomain, 1, 1, 1,1,1);
domainAddConstraint(&theDomain, 2, 3, 1,0,0);

domainPrint(&theDomain);

// get and print singular node
printf("\nsingular node:\n");
Node *theNode = domainGetNode(&theDomain, 2);
nodePrint(theNode);

// get and print constraints
printf("\nconstraints:\n");
Constraint *theConstraint = domainGetConstraint(&theDomain, 1);
constraintPrint(theConstraint);
}
43 changes: 43 additions & 0 deletions Code/Parallel/mpi/pi_numeric_integration_parallel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <cstdio>
#define LUMP 5

using namespace std;

static int long numSteps=100000;

int main(int argc, char **argv) {

int numP, procID;

double pi=0, time=0;

clock_t start; //timer
start = std::clock();
//cout<<start<<endl;

// the usual mpi initialization
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numP);
MPI_Comm_rank(MPI_COMM_WORLD, &procID);





//integration
for (int aa=0; aa<numSteps; aa++) {
double x= (float)aa*1.0/(float)numSteps;
pi=pi+4.0/(1.0+x*x)*1.0/(float)numSteps;
}

cout<<pi<<endl;
//timer
time=( std::clock() - start ) / (double) CLOCKS_PER_SEC;
cout<<time<<endl;
return 0;
}
8 changes: 4 additions & 4 deletions Code/Parallel/mpi/submit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# This script requests 1 node and 8 cores/node (out of total 64 avail)
# for a total of 8 MPI tasks.
#---------------------------------------------------------------------
#SBATCH -J myjob # Job name
#SBATCH -o myjob.%j.out # stdout; %j expands to jobid
#SBATCH -e myjob.%j.err # stderr; skip to combine stdout and stderr
#SBATCH -J jiawei # Job name
#SBATCH -o jiawei.%j.out # stdout; %j expands to jobid
#SBATCH -e jiawei.%j.err # stderr; skip to combine stdout and stderr
#SBATCH -p development # queue
#SBATCH -N 1 # Number of nodes, not cores (64 cores/node)
#SBATCH -n 8 # Total number of MPI tasks (if omitted, n=N)
Expand All @@ -17,4 +17,4 @@
module petsc # load any needed modules, these just examples
moduele load list

ibrun ./a.out
ibrun ./a.out
55 changes: 55 additions & 0 deletions Code/Parallel/openmp/pi_numeric_integration_parallel_opM1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
//#include <iostream>
#include <ctime>
#include <cstdio>

using namespace std;

static int long numSteps=100000;

int main(int argc, char **argv) {

int numP, procID;

double pi=0, time1, time2;

//clock_t start; //timer
time1 = omp_get_wtime();
//start = std::clock();
//cout<<start<<endl;
double stepSize=1.0/(float)numSteps;

#pragma omp parallel (+:pi) //A synchronization feature
{
int tid = omp_get_thread_num();
int numT = omp_get_num_threads();
cout<<numT<<endl;
double sum=0.;

//integration
double aveNumStep=numSteps/numT;
if (tid<numT-1) {
for (int aa=aveNumStep*(tid-1); aa<aveNumStep*tid; aa++) {
double x= (float)aa*stepSize;
sum+=4.0/(1.0+x*x)*stepSize;
}
pi=pi+sum; // pi is outside paralle process. Don't get it into the for-loop!

} else { //the last thread gets a little more
for (int aa=aveNumStep*(tid-1); aa<numSteps; aa++) {
double x= (float)aa*stepSize;
sum+=4.0/(1.0+x*x)*stepSize;
}
pi=pi+sum; // pi is outside paralle process. Don't get it into the for-loop!
}
}
//cout<<pi<<endl;

//timer
time2=omp_get_wtime();
//cout<<time2-time1<<endl;
printf("Synchronization: PI = %16.14f in %.4g sec\n",pi, time2-time1)
return 0;
}
Loading