Re: Simple math/programming challenge for the "REAL programmer" Feeb

Liste des GroupesRevenir à col advocacy 
Sujet : Re: Simple math/programming challenge for the "REAL programmer" Feeb
De : nospam (at) *nospam* dfs.com (DFS)
Groupes : comp.os.linux.advocacy
Date : 11. Mar 2024, 03:08:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <usllis$38f7t$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Betterbird (Windows)
On 3/10/2024 8:12 PM, Physfitfreak wrote:
On 3/10/2024 6:27 PM, Tyrone wrote:
Even though I have clearly explained it, YOU still don't get it. If you really
want to challenge someone, come up with a unique problem that has not been
solved already by millions of people over the last 40 years. REAL problem
solving happens when YOU have to actually code/test/verify that YOU have
solved the problem.
>
What's next?  "Challenge" people to print out Prime Numbers?
  I asked you to do the base conversion into e as challenge and you weaseled your way silently out.
 Why don't you do that and show your code here. Preferably in C, but even BASIC would do. Just don't use some funky language to smear it for me to run, and visually check your code.
Sandy,
wtf is it with you and Feeb insisting others do your challenges, but running away when you're asked to do them?
I asked you weeks ago to write a little C to do matrix multiplication using [i][j] addressing, and I've seen no response.  Why?
Don't be afraid you won't get it exactly right.  I'm not gonna laugh at it, or criticize it.  If I can suggest improvements I will.  If I see innovation I'll say so.  We're here to learn and be entertained, right?
The only code I savage is from that lying, blustering, nasty asshole Feeb.  He used to make lie-excuses that he was too busy, or the code would contain "subtleties" (meaning too difficult to get right).  Now the wimp just out and out ignores them.
---------------------------------------------------------------------------
matrix creation/fill/multiply/print using only [i][j] addressing
---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
double elapsedtime(clock_t start) {
return (clock() - (double)start)/CLOCKS_PER_SEC;
}
int main(void) {
clock_t start;

//2^11 = 1024 (~3 seconds)
//2^12 = 2048 (~30 seconds), after that code gets very slow
int max = 12;

srand(time(NULL));

//run for powers of 2
for (int i = 2; i < max; i++) {

//size of matrices
int N = pow(2,i);
//allocate memory for matrices A,B,C
int (*A) [N] = malloc(sizeof(int[N][N]));
int (*B) [N] = malloc(sizeof(int[N][N]));
int (*C) [N] = malloc(sizeof(int[N][N]));

//fill matrices A,B with random values
for (int i=0; i < N; i++) {
for (int j=0; j < N; j++) {
A[i][j] = rand() % N;
B[i][j] = rand() % N;
}
}

//print 4x4 or 8x8 random data
if (N==4) {
printf("\n         4x4 Random Data \n");
printf("     Matrix A       Matrix B\n");
printf("  -------------   -------------\n");
}

if (N==8) {
printf("\n                      8x8 Random Data \n");
printf("         Matrix A                         Matrix B\n");
printf("  ----------------------------- -----------------------------\n");
}
if (N==4 || N==8) {
for (int p=0; p < N; p++) {
for (int j=0; j < N; j++) {printf("%3d ",A[p][j]);}
for (int j=0; j < N; j++) {printf("%3d ",B[p][j]);}
printf("\n");
}
}
//standard matrix multiply using nested loops
start = clock();
for (int i=0; i < N; i++) {
   for (int j=0; j < N; j++) {
C[i][j] = 0;
for (int k=0; k < N; k++) {
   C[i][j] += A[i][k] * B[k][j];
}
   }
}
//print 4x4 or 8x8 data
if (N==4 || N==8) {
printf("\nMatrix C: multiply A * B\n------------------------\n");
for (int p=0; p < N; p++) {
for (int j=0; j < N; j++) {printf("%3d  ",C[p][j]);}
printf("\n");
}
printf("\n");
}
//timing results
printf("N=%4d: multiplication in %.4fs\n",N,elapsedtime(start));
//release memory
free(A);
free(B);
free(C);

}

return(0);
}
---------------------------------------------------------------------------
for max speed, compile it like this:
$ gcc -O3 codefile.c -o progname -lm
run it:
$ ./progname
Feeb posted a link
https://johnnysswlab.com/make-your-programs-run-faster-by-better-using-the-data-cache/
that showed a slightly different matrix multiplication technique they called 'loop interchange'.  It really does make a difference.
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
C[i][j] = 0;
}
for (int k = 0; k < N; k++) {
for (int j = 0; j < N; j++) {
C[i][j] += A[i][k] *  B[k][j];
}
}
}

Date Sujet#  Auteur
5 Oct 24 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal