From d22d52d50558e2f6d062a744eee2e5c18e111ca6 Mon Sep 17 00:00:00 2001 From: JiaweiChenKodomo <41921333+JiaweiChenKodomo@users.noreply.github.com> Date: Tue, 31 Jul 2018 12:50:25 -0700 Subject: [PATCH 1/6] pi_integration sequential program. --- pi_numeric_integration.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pi_numeric_integration.cpp diff --git a/pi_numeric_integration.cpp b/pi_numeric_integration.cpp new file mode 100644 index 0000000..49959f4 --- /dev/null +++ b/pi_numeric_integration.cpp @@ -0,0 +1,29 @@ + +#include +#include +#include +#include +#include + +using namespace std; + + +static int long numSteps=100000; +int main() { + double pi=0, time=0; + + clock_t start; //timer + start = std::clock(); + //cout< Date: Tue, 31 Jul 2018 15:52:05 -0700 Subject: [PATCH 2/6] pi_numeric_integration_parallel_opM.cpp initial import --- .../pi_numeric_integration_parallel_opM.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp diff --git a/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp b/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp new file mode 100644 index 0000000..eee0d8f --- /dev/null +++ b/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include + +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 + time = omp_get_wtime(); + //start = std::clock(); + //cout< Date: Tue, 31 Jul 2018 16:08:26 -0700 Subject: [PATCH 3/6] pi_numeric_integration_parallel_opM.cpp initial import --- Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp b/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp index eee0d8f..1bfb42a 100644 --- a/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp +++ b/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp @@ -27,7 +27,7 @@ int main(int argc, char **argv) { //integration - aveNumStep=numSteps/numT; + double aveNumStep=numSteps/numT; if (tid Date: Tue, 31 Jul 2018 16:20:36 -0700 Subject: [PATCH 4/6] pi_numeric_integration_parallel_opM.cpp initial import --- .../openmp/pi_numeric_integration_parallel_opM.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp b/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp index 1bfb42a..2e4400d 100644 --- a/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp +++ b/Code/Parallel/openmp/pi_numeric_integration_parallel_opM.cpp @@ -13,10 +13,10 @@ int main(int argc, char **argv) { int numP, procID; - double pi=0, time=0; + double pi=0, time1, time2; //clock_t start; //timer - time = omp_get_wtime(); + time1 = omp_get_wtime(); //start = std::clock(); //cout< Date: Wed, 1 Aug 2018 13:09:27 -0700 Subject: [PATCH 5/6] wed noon --- Code/C/fem/constraint.c | 17 +++++ Code/C/fem/constraint.h | 17 +++++ Code/C/fem/domain.c | 44 +++++++++++- Code/C/fem/domain.h | 8 +++ Code/C/fem/main.c | 11 +++ .../mpi/pi_numeric_integration_parallel.cpp | 43 ++++++++++++ Code/Parallel/mpi/submit.sh | 8 +-- ... pi_numeric_integration_parallel_opM1.cpp} | 25 ++++--- .../pi_numeric_integration_parallel_opM2.c | 67 +++++++++++++++++++ Code/Parallel/openmp/submit.sh | 4 +- 10 files changed, 227 insertions(+), 17 deletions(-) create mode 100644 Code/C/fem/constraint.c create mode 100644 Code/C/fem/constraint.h create mode 100644 Code/Parallel/mpi/pi_numeric_integration_parallel.cpp rename Code/Parallel/openmp/{pi_numeric_integration_parallel_opM.cpp => pi_numeric_integration_parallel_opM1.cpp} (55%) create mode 100644 Code/Parallel/openmp/pi_numeric_integration_parallel_opM2.c diff --git a/Code/C/fem/constraint.c b/Code/C/fem/constraint.c new file mode 100644 index 0000000..8316f56 --- /dev/null +++ b/Code/C/fem/constraint.c @@ -0,0 +1,17 @@ +#include +#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; +} diff --git a/Code/C/fem/constraint.h b/Code/C/fem/constraint.h new file mode 100644 index 0000000..c5258ba --- /dev/null +++ b/Code/C/fem/constraint.h @@ -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 + +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 diff --git a/Code/C/fem/domain.c b/Code/C/fem/domain.c index b213ea8..bc2f75a 100644 --- a/Code/C/fem/domain.c +++ b/Code/C/fem/domain.c @@ -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) { @@ -13,8 +14,12 @@ void domainAddNode(Domain *theDomain, int tag, double crd1, double crd2) { nodeSetup(theNextNode, tag, crd1, crd2); if (theDomain->theNodes != NULL) { - theNextNode->next = theDomain->theNodes; + theNextNode->next = theDomain->theNodes; + + } else { + theNextNode->next = NULL; } + theDomain->theNodes = theNextNode; } @@ -30,10 +35,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; +} diff --git a/Code/C/fem/domain.h b/Code/C/fem/domain.h index 29151ec..1d70de7 100644 --- a/Code/C/fem/domain.h +++ b/Code/C/fem/domain.h @@ -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); + diff --git a/Code/C/fem/main.c b/Code/C/fem/main.c index c34a224..ab0664d 100644 --- a/Code/C/fem/main.c +++ b/Code/C/fem/main.c @@ -1,17 +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); } diff --git a/Code/Parallel/mpi/pi_numeric_integration_parallel.cpp b/Code/Parallel/mpi/pi_numeric_integration_parallel.cpp new file mode 100644 index 0000000..a78040d --- /dev/null +++ b/Code/Parallel/mpi/pi_numeric_integration_parallel.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#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< #include #include -#include +//#include #include #include @@ -19,30 +19,37 @@ int main(int argc, char **argv) { time1 = omp_get_wtime(); //start = std::clock(); //cout< +#include +//#include +//#include +//#include +#include +//#include + +//using namespace std; + +static int long numSteps=1000000000; + +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< Date: Thu, 2 Aug 2018 21:00:55 -0700 Subject: [PATCH 6/6] Obj_based_c_Thur --- Code/C/fem/domain1.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ Code/C/fem/domain1.h | 19 +++++++++++ Code/C/fem/main1.c | 28 ++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 Code/C/fem/domain1.c create mode 100644 Code/C/fem/domain1.h create mode 100644 Code/C/fem/main1.c diff --git a/Code/C/fem/domain1.c b/Code/C/fem/domain1.c new file mode 100644 index 0000000..bc2f75a --- /dev/null +++ b/Code/C/fem/domain1.c @@ -0,0 +1,79 @@ +#include +#include +#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; +} diff --git a/Code/C/fem/domain1.h b/Code/C/fem/domain1.h new file mode 100644 index 0000000..1d70de7 --- /dev/null +++ b/Code/C/fem/domain1.h @@ -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); + diff --git a/Code/C/fem/main1.c b/Code/C/fem/main1.c new file mode 100644 index 0000000..ab0664d --- /dev/null +++ b/Code/C/fem/main1.c @@ -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); +}