Skip to content
Snippets Groups Projects
Commit 76ff56c7 authored by LIU Xiaodong's avatar LIU Xiaodong
Browse files

update main.cpp and README for formation ED 2024

parent 4cadd07a
Branches main
No related tags found
No related merge requests found
# A small collaboration project to practice git
This is simple pcg solver in c++ generated by chatgpt and modified after. This is simple pcg solver in c++ generated by chatgpt and modified after.
The objectif of this TP is not to understand the c++, but to practice git. The objective of this TP is not to understand c++ code, but to practice git.
In fact, in the program, serveral lines were commented. What you need to do is to remove "//" before those lines to let the program output informations. In fact, in the program, lots of sections are commented in main.cpp. What you need to do is to remove "/*" before the section and "*/" after each section to let the program output information.
As there are several files, you can work in groupe (2 personnes) to achieve the efficiency. As there are several files, you can work in groupe (2 personnes) to achieve the efficiency.
## 1. Fork the project
You do not have write permission on this project, you will hence need to fork it. Of course, since ***Dev.A*** and ***Dev.B*** will be collaborating to the same project, only one of them should create the fork for the group.
1. One of the teammate forks this repository to his own git private repository. ***Dev.B***: Fork the project by clicking on the fork button in the upper right corner of the project page.
2. This teammate invite the other teammate as a team member to work with him is this project. Now ***Dev.B*** has his own copy of the project. In order to give ***Dev.A*** write permissions to the project,
***Dev.B*** needs to add ***Dev.A*** to the project’s list of collaborators: *Settings -> Collaborators*.
3. After that, each teammate will do a "git clone" to get the private repository to his local repository after done a "git init" in his local repository. ## 2. Clone the repository
Both ***Dev.A*** and ***Dev.B*** clone it and then go to the local repository
```
cd GitTP
```
Both open gitk to visualize the workflow
```
gitk --all &
```
gitk should be updated after each git command to check the changes.
## 3. Commit and push
In this part, ***Dev.B*** does the same thing as ***Dev.A***, but in *Step 2*
1. ***Dev.A*** delete "/*" and "*/" in *Step 1* in file *main.cpp*, check the change with
```
git statut
```
2. ***Dev.A*** stage the modifications (check gitk)
```
git add main.cpp
```
3. ***Dev.A*** commit this modifications
```
git commit -m "uncomment Step 1"
```
check gitk
4. Dev A removes the comments in pcg.cpp file to enable print ("//" before the "cout"); Dev B removes the comments in cg.cpp to enable print. 4. ***Dev.A*** push this commit
```
git push
```
> One of the teammate will find that it is not possible to push the modifications. Try to figure it out.
5. Each Dev commits their modifications. > Tips: The teammate push after the first need to do ```git pull``` before the ```git push```
6. Publish the new code to remote repository. 5. Try to get the same output for gitk when finished.
7. Update the local repository. ## 4. Branch and merge
In this part, ***Dev.B*** does the same thing as ***Dev.A***, but in *Step 4*
1. ***Dev.A*** creates a branch "uncommentStep3" ("uncommentStep4" for ***Dev.B***)
2. Checkout to the new branch, and check it to make sure
```
git branch
```
3. ***Dev.A*** deletes comments of *Step 3*
4. Commit the modifications and merge it to main branch
```
git checkout main
git merge uncommentStep3
```
5. push it to remote and try to get the same workflow one gitk
8. Dev A tests the output of pcg by adding the "//" in main before the cg solver, Dev B does the same thing but disable pcg solver. ## 5. Manage conflicts
1. ***Dev.B*** creates a new branch "PCG".
2. ***Dev.B*** uncomments *Step 6.1* and **delete** *Step 6.2*.
3. ***Dev.B*** commits this modification and merge it main.
4. ***Dev.B*** publishes it to remote.
5. ***Dev.A*** creates a new branch "CG".
6. ***Dev.A*** uncomments *Step 6.2* and **delete** *Step 6.1*.
7. ***Dev.A*** commits this modification.
8. ***Dev.A*** checkout to main.
9. ***Dev.A*** does a git pull to update his local main branch
10. ***Dev.A*** merge branch "CG" to main.
11. ***Dev.A*** publishes it to remote.
9. Publish the new code to remote. > Here ***Dev.A*** has to handle the conflicts when merge "CG" to main. You can choose either PCG or CG.
If you like :
To compile to code, you need gcc compile
g++ *cpp -o a.out
To execute
./a.out
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
int main() int main()
{ {
/*******Step 1 ********/
/*
// stiffness matrix // stiffness matrix
vector<vector<double>> A = vector<vector<double>> A =
{ {
...@@ -14,23 +15,43 @@ int main() ...@@ -14,23 +15,43 @@ int main()
{ 0, -1, 0, -1, 5, -1 }, { 0, -1, 0, -1, 5, -1 },
{ 0, 0, -1, 0, -1, 6 } { 0, 0, -1, 0, -1, 6 }
}; };
// right hand vector */
/*******Step 2 ********/
/*
// right hand vector
vector<double> b = { 1, 0, 0, 0, 0, 0 }; vector<double> b = { 1, 0, 0, 0, 0, 0 };
// max iteration */
/*******Step 3 ********/
/*
// max iteration
int maxiter = 1000; int maxiter = 1000;
*/
/*******Step 4 ********/
/*
// convergence tolerence // convergence tolerence
double tol = 1e-1; double tol = 1e-1;
*/
/*******Step 5 ********/
/*
// Define the initial guess // Define the initial guess
vector<double> x0 = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 }; vector<double> x0 = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };
*/
/*******Step 6.1 ********/
/*
// Call the PCG solver function with a maximum of 1000 iterations and a tolerance of 1e-6 // Call the PCG solver function with a maximum of 1000 iterations and a tolerance of 1e-6
vector<double> x = PCG(A, b, x0, maxiter, tol); vector<double> x = PCG(A, b, x0, maxiter, tol);
*/
/*******Step 6.2 ********/
/*
// Call the CG solver function with a maximum of 1000 iterations and a tolerance of 1e-6 // Call the CG solver function with a maximum of 1000 iterations and a tolerance of 1e-6
vector<double> x = conjugateGradient(A,b,x0,maxiter, tol); vector<double> x = conjugateGradient(A,b,x0,maxiter, tol);
*/
/*******Step 7 ********/
/*
// output in the solution in screen // output in the solution in screen
for (int i = 0; i < x.size(); ++i) { for (int i = 0; i < x.size(); ++i) {
cout << "x[" << i << "] = " << x[i] << endl; cout << "x[" << i << "] = " << x[i] << endl;
} }
return 0; return 0;
*/
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment