From 9c3c4ad068c0322d5e7aff464ee732fd42af9c2a Mon Sep 17 00:00:00 2001 From: niklas Date: Wed, 22 Nov 2023 19:51:30 +0100 Subject: [PATCH] Initial --- uebung_01/exercise_1.py | 22 ++++++ uebung_01/exercise_2a.py | 24 +++++++ uebung_01/exercise_2b.py | 22 ++++++ uebung_01/exercise_3.py | 68 ++++++++++++++++++ uebung_02/main_matrix.c | 64 +++++++++++++++++ uebung_02/main_openmp.c | 19 +++++ uebung_02/matrix_mul | Bin 0 -> 16328 bytes uebung_02/openmp_hello | Bin 0 -> 16448 bytes uebung_04/exercise_01/exercise_01.c | 17 +++++ uebung_04/exercise_01/exercise_01.out | Bin 0 -> 16208 bytes uebung_04/exercise_01/exercise_01.script | 13 ++++ .../uebung_04__exercise_01.e662620 | 0 .../uebung_04__exercise_01.o662620 | 8 +++ uebung_04/exercise_03/exercise_03.c | 26 +++++++ uebung_04/exercise_03/exercise_03.out | Bin 0 -> 16320 bytes uebung_04/exercise_03/exercise_03.script | 13 ++++ uebung_04/exercise_05/exercise_05.c | 33 +++++++++ uebung_04/exercise_05/exercise_05.out | Bin 0 -> 16392 bytes 18 files changed, 329 insertions(+) create mode 100644 uebung_01/exercise_1.py create mode 100644 uebung_01/exercise_2a.py create mode 100644 uebung_01/exercise_2b.py create mode 100644 uebung_01/exercise_3.py create mode 100644 uebung_02/main_matrix.c create mode 100644 uebung_02/main_openmp.c create mode 100755 uebung_02/matrix_mul create mode 100755 uebung_02/openmp_hello create mode 100644 uebung_04/exercise_01/exercise_01.c create mode 100755 uebung_04/exercise_01/exercise_01.out create mode 100644 uebung_04/exercise_01/exercise_01.script create mode 100644 uebung_04/exercise_01/uebung_04__exercise_01.e662620 create mode 100644 uebung_04/exercise_01/uebung_04__exercise_01.o662620 create mode 100644 uebung_04/exercise_03/exercise_03.c create mode 100755 uebung_04/exercise_03/exercise_03.out create mode 100644 uebung_04/exercise_03/exercise_03.script create mode 100644 uebung_04/exercise_05/exercise_05.c create mode 100755 uebung_04/exercise_05/exercise_05.out diff --git a/uebung_01/exercise_1.py b/uebung_01/exercise_1.py new file mode 100644 index 0000000..5ee8612 --- /dev/null +++ b/uebung_01/exercise_1.py @@ -0,0 +1,22 @@ +import numpy as np + +for n in [3,5,10,100,1000]: + A = np.zeros((n,n)) + x = np.zeros((n,1)) + y_c = np.zeros((n,1)) + + for i in range(0,n): + x[i] = i+1 + y_c[i] = (i+1) * n; + + for j in range(0,n): + A[i,j] =(i+1) / (j+1) + + y = A@x + + if n == 3 or n == 5: + print(x) + print(A) + print(y) + + print("Fuer n =",n,":",np.linalg.norm(y - y_c)) diff --git a/uebung_01/exercise_2a.py b/uebung_01/exercise_2a.py new file mode 100644 index 0000000..a9d3653 --- /dev/null +++ b/uebung_01/exercise_2a.py @@ -0,0 +1,24 @@ +import numpy as np +import matplotlib.pyplot as plt + +# x = np.linspace(0, 2 * np.pi, 100) +x_1 = np.arange(0, 2 * np.pi, 1) +x_0_5 = np.arange(0, 2 * np.pi, 0.5) +x_0_1 = np.arange(0, 2 * np.pi, 0.1) + +y_s_1 = np.sin(x_1) +y_s_0_5 = np.sin(x_0_5) +y_s_0_1 = np.sin(x_0_1) +y_c = np.cos(x_1) + +plt.plot(x_1,y_s_1,"purple", label="sin(x) with stepsize 1") +plt.plot(x_0_5,y_s_0_5,"pink", label="sin(x) with stepsize 0.5") +plt.plot(x_0_1,y_s_0_1,"red", label="sin(x) with stepsize 0.1") +plt.plot(x_1,y_c,"green", label="cos(x)") + +plt.title("A2.a) Sine and Cosine") +plt.xlabel("x") +plt.ylabel("y") +plt.legend() + +plt.show() diff --git a/uebung_01/exercise_2b.py b/uebung_01/exercise_2b.py new file mode 100644 index 0000000..ed7c67c --- /dev/null +++ b/uebung_01/exercise_2b.py @@ -0,0 +1,22 @@ +import numpy as np +import matplotlib.pyplot as plt + +plt.rcParams['text.usetex'] = True + +# x = np.linspace(0, 2 * np.pi, 100) +x = np.arange(-2, 2, 0.1) + +f = np.exp(-x**2) +g = np.sin(x**2) +h = np.sin(1 / (x**3 + 9)) + +plt.plot(x, f, "purple", label=r"$f(x) = \exp(-x^2)$") +plt.plot(x, g, "red", label=r"$g(x) = \sin(x^2)$") +plt.plot(x, h, "green", label=r"$h(x) = \frac{1}{x^3 + 9}$") + +plt.title("A2.b)") +plt.xlabel("x") +plt.ylabel("y") +plt.legend() + +plt.show() diff --git a/uebung_01/exercise_3.py b/uebung_01/exercise_3.py new file mode 100644 index 0000000..da1d328 --- /dev/null +++ b/uebung_01/exercise_3.py @@ -0,0 +1,68 @@ +import numpy as np +import matplotlib.pyplot as plt + +def runge(x): + return 1 / (1 + 25 * x**2) + +def divided_differences(x, y): + n = len(y) + a = np.zeros((n,n)) + + a[:,0] = y + + for i in range(1,n): + for j in range(1,i+1): + a[i,j] = (a[i,j-1] - a[i-1,j-1]) / (x[i] - x[i-j]) # (links daneben - links darĂ¼ber) / (x[zeile] - x[zeile - spalte]) + + return a + +def newton_interpolation(a, data, x): + n = len(a) + + p = np.zeros(len(x)) + + for i in range(1,n+1): + p = a[n-i] + (x - data[n-i]) * p # Horner Schema; '-' and '*' are overloaded for numpy arrays: so at least one argument 'data' or 'x' has to be numpy array + + return p + +#################################################################################################################################################################### +n = 12 + +x = np.linspace(-1, 1, 200) +x_e = np.linspace(-1, 1, n) # equidistant grid points + +# Chebyshev grid points +x_c = np.zeros(n) +for i in range(0,n): + x_c[i] = np.cos((2 * i + 1) * np.pi / (2 * n)) + +f = runge(x) +y_e = runge(x_e) # values for grid points for interpolation with equidistant grid points +y_c = runge(x_c) # values for grid points for interpolation with Chebyshev grid points + +# Interpolation with equidistant grid points and evaluation of interpolated values at x +a_e = np.diag(divided_differences(x_e, y_e)) +p_e = newton_interpolation(a_e, x_e, x) + +# Interpolation with Chebyshev grid points and evaluation of interpolated values at x +a_c = np.diag(divided_differences(x_c, y_c)) +p_c = newton_interpolation(a_c, x_c, x) + + +# Plotting of Runge and the two interpolated polynomials +plt.rcParams['text.usetex'] = True + +plt.plot(x, f, label=r"$f(x) = \frac{1}{1 + 25 x^2}$") +plt.plot(x, p_e, label=r"$p_n(x)$ equidistant") +plt.plot(x, p_c, label=r"$p_n(x)$ Chebyshev") +plt.plot([], [], ' ', label="$n = {}$".format(n)) + +plt.title("A3)") +plt.xlabel("x") +plt.ylabel("y") +plt.legend() + +plt.show() + +# braendel@math.tu-freiberg.de diff --git a/uebung_02/main_matrix.c b/uebung_02/main_matrix.c new file mode 100644 index 0000000..9380c05 --- /dev/null +++ b/uebung_02/main_matrix.c @@ -0,0 +1,64 @@ +#include +#include + +int compute(int N) { + + int i_0, i_1; + // claim space + double **A = (double **)malloc(sizeof(double *) * N); + for (i_0 = 0; i_0 < N; i_0++) { + A[i_0] = (double *)malloc(sizeof(double) * N); + } + double *x = (double *)malloc(sizeof(double) * N); + double *y = (double *)malloc(sizeof(double) * N); + double *y_sol = (double *)malloc(sizeof(double) * N); + + // fill matrix and vector + for (i_0 = 0; i_0 < N; i_0++) { + x[i_0] = i_0 + 1; + y_sol[i_0] = (i_0 + 1) * N; + for (i_1 = 0; i_1 < N; i_1++) { + A[i_0][i_1] = (i_0 + 1.0) / (i_1 + 1.0); + } + } + + // for (i_0 = 0; i_0 < N; i_0++){ + // printf("[ "); + // for(i_1 = 0; i_1 < N; i_1++){ + // printf("%.3f ",A[i_0][i_1]); + // } + // printf("]"); + // printf("[ %.1f ] = [ %.1f ][ %.1f ]\n",x[i_0],y[i_0],y_sol[i_0]); + // } + + // compute matrix-vector product + for (i_0 = 0; i_0 < N; i_0++) { + y[i_0] = 0; + for (i_1 = 0; i_1 < N; i_1++) { + y[i_0] += A[i_0][i_1] * x[i_1]; + } + } + + // compare result to solution + double sum = 0.0; + for (i_0 = 0; i_0 < N; i_0++) { + sum += (y[i_0] - y_sol[i_0]) * (y[i_0] - y_sol[i_0]); + } + + return sum; +} + +int main(int argc, char *argv[]) { + + int N; + if (argc != 2) { + N = 1000; + } else { + N = atoi(argv[1]); // Convert the argument to an integer + } + + double err = compute(N); + printf("Error for N = %d: %.8f\n", N, err); + + return 0; +} diff --git a/uebung_02/main_openmp.c b/uebung_02/main_openmp.c new file mode 100644 index 0000000..92be7c1 --- /dev/null +++ b/uebung_02/main_openmp.c @@ -0,0 +1,19 @@ +#include // load Open-MP library +#include +#include + +int main() { + int N = 5; + int num; + +#pragma omp parallel for private(num) // start Open-MP section + // here the program (1 thread) is split into multiple threads + // each thread has its own copy of i (loop) and num (private) + // all threads share N (by default, because defined outside) + for (int i = 0; i < N; i++) { + num = omp_get_thread_num(); + printf("Thread %d does iteration %d\n", num, i); + } + + return 0; +} diff --git a/uebung_02/matrix_mul b/uebung_02/matrix_mul new file mode 100755 index 0000000000000000000000000000000000000000..f0a36d91830c9c674aceebc08977cca57d7e5e01 GIT binary patch literal 16328 zcmeHOeQZ+uLK72?YRwF3bY36Y_yi7FsMqDkBg zp9{qTF&XqqiJA70DZpx$)82`)itq}M$eW9m67usVELd_6Q6jHg8Nm)gVJT=F$eV-) z(w(xI`oWUzR(nAtLkY@HOKw63C@k$f?8?DfX%+{YC(2&ROFv2Gp^Ci2#5+tpmY1kK zmYh$_2_8)}4yUXG8y1#MUN7;Svel#sme>ZC&U1R~v$VH~cr`&8MmXhNCM;NTdtU(_ zom%qvWWlF-GqqRlJZz=>v!wKjWvOI$W5cpktTvTQ=Lc#Bni^{x8;_uGyTKZZ?<@x;g4xkVA8#(BM z1>^B0f;!gm+@X(|k4K?qVkl3=|ImlBTv-f;nI(+(0~RcSKVAlJ1iVz7`DJh%S1JGR zl!=eyyA6&Til+4pM72aR9Ze-4jtfoe&nDA)LhI>$K=egZsZ0-GaPoSzoF2{UT36yx4uvKKHf9KG#sMu3&ul)SA|SFC7@A)W=42uW?cxI#M+z!x$^S1#r<=vKNGZp+Ns$v=lG=)i8|x zQpbs7@xm!f#|dNc!YJ#&9+vD@A^D(39D1`uUuoCtFSZv>?NAGUQ-|KXw5cmnKT>}} z9d53MW{f$r!1IHI;$Qd;?3Dm~6(H*Hq~$19UD4;j&^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|rm*QW*A2uk}4uV4!{|5UI4GI7N literal 0 HcmV?d00001 diff --git a/uebung_02/openmp_hello b/uebung_02/openmp_hello new file mode 100755 index 0000000000000000000000000000000000000000..00099eb1a04e743d029b09271e9149f4722d6f6a GIT binary patch literal 16448 zcmeHOYiu0V6~4Q+!xF;UAqhB1OBQfwDD}opOqu{8yN>OwkwenNDJmsQ#{2ND*oV72 z3l31~%7C&BR$ZxTLshk+0zpM3sMMnLB}@}uLaj*YkAxQ0AdsBWrok;Ofs*ZaX3iN; zhFxf*{+ug~zk9y(xOdLn8Qkz3gIYh^@9(erv$)<-sbmd>e`jYA7jQs0Kd>u9p1|>+r*M_)mfl;c%C)fv6S# zGvGsRW5|6tYT4fj{?Z!uO6wooswI-eo>TnvpIh^@Nr$=WGgfrb~z(AJw%~Ca-5RcTi&^ z#Z2BvY4P-}5HP;t+;UFO7SK0No;V!#AS6kaf3G!p?G~ij$0BpiBPthaO2ma?k8h`YRcApOu$o&Q*x?I&;QSlAF{CmKSF-=hGAFJ(hp+jc;N2`c)$h zJQR68%5!OIp~X+~^H2CO<^vH+FTBV{H(5O08ywmsrX9TVewuOc*8ODppLFoj25H`P z@N^$ad4hS$r91;jchJGp{Viq6!JGe=Sn<4rr&v;6a_~s3SG){(8SpaTWx&gTmjN#W zXPtq+H(&f-Z2T{Q*#4$ttCfn~J7xH*FU7_W2M(Drt5@9tdbYaqPC)YtMfPdZ%pQNO zTCGl+GEKB*j~}sRnqbWyf7+I5LNt5)$F@upq1odPij3$vGkT9Q<3nEJlFxU^O)mL^ zF!gTE{~f2?`Pcr+ky~Pw*JI;voZLRx+d0+wLTqB=CUm>Hj`Zd87r(>0qv8PXLiaq^qL(KPV z?8s?jF#_Dn0Rq+Ol-W=5r~Hj=B(*AExhpolafqt1%A3Z5*#3N{Jk}A<%(ZO9i>2mI0G4ngPRi2r73=pjxt{i>fUmsMSsT_%J`2Ahi zRo;p=KmJGGi@sMky!GXk0~771FgdRr>#4jxP&x4wUCx6z)Xew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PiZov?Qh0q2ly+@1LXZ8O|cld*Nta;`En!kzhy+8QuOj zg8wJxqSAkvuM0~1Jgxmu|8@A&TwVNSJ}(%c|Cv@3s8E;1U*0DKr`S;1 z7k@c_+D}LR-E1fCCxY@mL;mFB_J0r@W6y(+CGl^MIlKv-BH^^hcgQ=Yo^IJN+N+vZP + +int main(int argc, char **argv) { + int rank, size, err, n; + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD, &size); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + printf("rank=%d size=%d\n", rank, size); + + MPI_Finalize(); + + return 0; +} diff --git a/uebung_04/exercise_01/exercise_01.out b/uebung_04/exercise_01/exercise_01.out new file mode 100755 index 0000000000000000000000000000000000000000..1421d5eb8be0fbfa0b98fb70aacc5149a628a7de GIT binary patch literal 16208 zcmeHOeQXrR6`woXaFh?96DR}{I3)p*QZHvP6sQ~y+h^954G!39E0HYcyS2UYedTVi z*r-h`(I6~i=}6nOQW`0=e}pJSqEaiR{i8LdrJ+(QNZW|2A9Aar+7fAu3z6FXSygFjPOZYiIq=MkSw7w#jxJR|pQAQ~M9} z;N_S=j>0JXBbLnmux%x^qyCWt-@Mhe`}|WsI$krFf3^4g(vHp-Q3uD3HmHLI{qZG7 z8S6{oKpiU{CxnPt+%n*<>Ay&wS^AlGp<1^50NDG=w4lFG8NL^|a{4&Va{3>yz_(TK z(_Mi-Ux9zN0{>zK{xt9p!{IK2K-7t~A{3z(KcS}er!r|RZ^m+_rU|XRyHiW(IlbS= zn|iLhvn82H>)o;5q;9p9ZRzZ4*IF{El$JM+>%x|DvGkyn+S7(9GO4Vg;Sop8W0_ns zAsgF_bS#N>nie05X?^n|%*i;7EEO}-pa8>+4{Gs&L9H)lBtQuWeIyUH|*Y{dH&V9aQ$V@tTypOm{ zIe7W}r-m5^kM|RoIS2m{CINY#pbxyyxSS(>{Mx~Lh|2{B&(8#Gd)>iX_pfC!;o#{j zOg6mX;5io9aMi&>puOTnz>9zv0WSh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0 HcmV?d00001 diff --git a/uebung_04/exercise_01/exercise_01.script b/uebung_04/exercise_01/exercise_01.script new file mode 100644 index 0000000..649503a --- /dev/null +++ b/uebung_04/exercise_01/exercise_01.script @@ -0,0 +1,13 @@ +#!/bin/bash + +## parameters +#PBS -N uebung_04__exercise_01 +#PBS -q entry_teachingq +#PBS -l select=1:ncpus=8:mpiprocs=8 +#PBS -l walltime=00:05:00 + +## environment +cd ~/pwr/uebung_04/exercise_01 + +## execute +mpiexec -n 8 exercise_01.out diff --git a/uebung_04/exercise_01/uebung_04__exercise_01.e662620 b/uebung_04/exercise_01/uebung_04__exercise_01.e662620 new file mode 100644 index 0000000..e69de29 diff --git a/uebung_04/exercise_01/uebung_04__exercise_01.o662620 b/uebung_04/exercise_01/uebung_04__exercise_01.o662620 new file mode 100644 index 0000000..89bfac5 --- /dev/null +++ b/uebung_04/exercise_01/uebung_04__exercise_01.o662620 @@ -0,0 +1,8 @@ +rank=2 size=8 +rank=4 size=8 +rank=5 size=8 +rank=6 size=8 +rank=7 size=8 +rank=0 size=8 +rank=1 size=8 +rank=3 size=8 diff --git a/uebung_04/exercise_03/exercise_03.c b/uebung_04/exercise_03/exercise_03.c new file mode 100644 index 0000000..2adcaf3 --- /dev/null +++ b/uebung_04/exercise_03/exercise_03.c @@ -0,0 +1,26 @@ +#include "mpi.h" +#include + +int main(int argc, char **argv) +{ + int rank, size, err, n; + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD,&size); + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + + printf("rank=%d size=%d\n", rank, size); + + err = MPI_Barrier(MPI_COMM_WORLD); + + n = (rank + 1) * 4711; + + err = MPI_Bcast(&n, 1, MPI_INT, 1, MPI_COMM_WORLD); + + printf("Received =%d\n", n); + + MPI_Finalize(); + + return 0; +} diff --git a/uebung_04/exercise_03/exercise_03.out b/uebung_04/exercise_03/exercise_03.out new file mode 100755 index 0000000000000000000000000000000000000000..dedb0d5375f17aadda8f0431c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y4Wh0xB3&=FbwJ6g4Bq%5{`a!{O#D#A7+>c7{5c z9r>Jxf07(nvOhP&I?IzD{xlg_W|>Hmc`RS@@I$noX8C8&gkc^x`wI`B*LN)WeU<&a z_s=WD=j$&N@+67R2Y2!EUjri!k@+=>?ai{mR-Ioj|My^V^Y2k?SC-E^OuNGKhvAD* zSqBH+gIM@IocEi0{aI&u88{ViFrVK;MryIO<@suB%R2Ml2LsMs=JR@=_YZSm@czTX zJid-U1PssL;nRD1b_aS3k(Iy8Kg?&j0?2N@2$64{Ex8|VfqAU20WxCTzY?-7mBcUi zTrkBpJHP9xe{y$l=5KcpyMklI;+8yjY>WLHq6V9(|62gYr7e%2pTGD%%VW2h_U{Ny bya7+++%Nm$?N*5Y2mHeZWs`^CQN_OiZA>Ev literal 0 HcmV?d00001 diff --git a/uebung_04/exercise_03/exercise_03.script b/uebung_04/exercise_03/exercise_03.script new file mode 100644 index 0000000..34e10b3 --- /dev/null +++ b/uebung_04/exercise_03/exercise_03.script @@ -0,0 +1,13 @@ +#!/bin/bash + +## parameters +#PBS -N uebung_04__exercise_03 +#PBS -q entry_teachingq +#PBS -l select=1:ncpus=8:mpiprocs=8 +#PBS -l walltime=00:05:00 + +## environment +cd ~/pwr/uebung_04/exercise_03 + +## execute +mpiexec -n 8 exercise_03.out diff --git a/uebung_04/exercise_05/exercise_05.c b/uebung_04/exercise_05/exercise_05.c new file mode 100644 index 0000000..c236687 --- /dev/null +++ b/uebung_04/exercise_05/exercise_05.c @@ -0,0 +1,33 @@ +#include "mpi.h" +#include + +int main(int argc, char **argv) { + int rank, size, err, n, sum; + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD, &size); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + printf("rank=%d size=%d\n", rank, size); + + n = rank + 1; + + sum = 4710; + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Reduce(&n, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + printf("Received in reduction=%d\n", sum); + + MPI_Barrier(MPI_COMM_WORLD); + + sum = 3710; + + MPI_Allreduce(&n, &sum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + printf("Received in allreduction =%d\n", sum); + + MPI_Finalize(); + + return 0; +} diff --git a/uebung_04/exercise_05/exercise_05.out b/uebung_04/exercise_05/exercise_05.out new file mode 100755 index 0000000000000000000000000000000000000000..24df63b1c1b98a1d02c4ba7aede2dba6bbf10a5c GIT binary patch literal 16392 zcmeHOeQX@n5r1dLiGd`(G;s+IO_q;Tp{X}^;<$mz&DqX5YibAM*rlIr&Ub5j#eJB) zJ+KL+t_&2*SPF>JRBA=|1BldCN>z|jq^geiMk;coibgFhP?gG7LkVs`p@>{(-kVvk zmpfXa{#EU>_U6rRKHlu?*IVzr@5Z}2Dk2fVtx|kNAa`JmLSiH^c2NgNOzaY?;CGYQ zD3$}iOkzqNQv{@{ovv6)s|l|JigxRmj=yO}Y_5+N5B?l*hXf>@Y9? zZR5k-OXHP04o4`TOzCinZE1U;xoKNERiC!Ah0*%aUCs5)O?p13Z- zkB4IhF-oJT7*{;|L)ki#qyEr_N1Fe9*YEf3Klt*&>DM3r^<#rupFUrx4E|0T{K+!-pUU8`0DdKG!Da%mM$`#y z4@u}kJIZ();dD?>G9Fus3)39Rq%jxTGPv^2$Ut%C_ zDOpKLcTcC;p37v+ynTlykn6Qlg`_2NnGxH>EjME33mGYDOE`{gIkGQ}oJ95($#rIJ zS9V&{X(!+yiSBRDIq8(t=&-YiG!EvCU}s&}ndE4~9Auek!qt_eeaj^5EGWQ^CT}s5 z!?&1&2|F!D9IzV{pa)UnW!KbzOcJ}zVsBSxTf4bk-_hiC7kk_FotVoATsM)xUnTI% zJX~p2igl62$HJ2jJPeoBGO>}cb+)|a*BnP8mx)4LUp*EHWl5P8Fgqm0{}4`0C`(6c_AA1x?8@55n-yr#ue7w=>A$d`ad z=PBZRFGT^L*NE33KEI@L3hU-MSeQ>R57BLw(ZQS>;{pCD z9iv_3e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