Adak's Profile User Rating: *****

Reputation: 245 Stalwart
Group:
Active Members
Active Posts:
805 (1.03 per day)
Joined:
01-April 11
Profile Views:
3,077
Last Active:
User is offline Mar 27 2013 03:13 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   Adak has not set their status

Posts I've Made

  1. In Topic: mpi_scatter parallel search

    Posted 25 Mar 2013

    You're search is not being benefited by the parallel execution, because your search is entirely too trivial. Every parallel program loses some efficiency because it has extra overhead to run it. That is what you're seeing here.

    What you should do is up the ante here - make the array one that is on the heap and large - you can malloc it or just make it a global array for this test. (local arrays can't be this big) - say 1,000,000 random integers.

    Now divide up the work so each parallel thread or process, sorts 200,000 of those integers. Do that test a few times with MPi and then repeat it with just a single process sorting the same random int's. (If you don't reseed the random seed generator, it will always give you the same random number sequence).

    That would be a much better test.
  2. In Topic: Super new to programming and have a C question...

    Posted 24 Mar 2013

    One good way to get to know what's going on with j, is to add a print statement to the inner loop. Something that will give you a chance to study just what is going on:

    And ALWAYS use [ code] tags around C code, on any forum - otherwise it becomes mangled by the forum software, and very hard to study.

    
    printf("i is %d and j is %d\nPress Enter when ready for the next loop\n",i,j); 
    getchar();
    
    


    Add those two lines right inside the inner for loop, and run the program. Watch the values of i and j, and how they are now coordinated.

    I promise you'll learn something good.

    And welcome to D.I.C!
  3. In Topic: Having trouble counting the occurrence of characters in an array

    Posted 24 Mar 2013

    This is C, rather than C++, but if you study it, you'll see how the logic uses the index, and some subtraction, to count up the frequency of each letter.


    You will need to save this with a dot c extension to compile it with the C compiler.

    #include <stdio.h>
    #include <string.h>
    
    int main(void) {
       int i,len;
       int frequency[26];  
       char text[]={"Out in the West Texas town of El Paso,\nI fell in love with a Mexican girl.\n"};
    
       printf("%s\n",text);
       //get the length of text string
       len=strlen(text);
       printf("len: %d\n\n",len);
       
       for(i=0;i<26;i++) {   //set all frequency array elements to 0
          frequency[i]=0;
       }
       printf("\n\n");
       //get frequency of letters
       for(i=0;i<len;i++) {
          if(text[i]>='a' && text[i]<='z') {        //count up lowercase letters
             frequency[text[i]-'a']++;
             printf("frequency of %c: %d\n",text[i], frequency[text[i]-'a']);
             
          }else if(text[i]>='A' && text[i]<='Z') {    //counts up uppercase letters
             frequency[text[i]-'A']++;
             printf("frequency of %c: %d\n",text[i], frequency[text[i]-'A']);
          }
          if(i%8==0) {
             printf("Hit enter to continue\n");
             getchar();
          }
    
       }
       printf("\n\n");
       for(i=0;i<26;i+=2) {                  //show the frequencies of each letter
          printf("%c: %3d   %c: %3d \n",i+'a',frequency[i],i+1+'a',frequency[i+1]);
       }
       printf("\n");
       return 0;
    }
    
    
  4. In Topic: program does not run properly when i key in alphabet. help =(

    Posted 24 Mar 2013

    Every time you enter some data, there is a newline generated as you hit Enter. With numbers, that's not a problem, because they're bigger. With a letter (char) however, that's a real problem, because a newline '\n' IS a char - AND it will drive scanf() crazy when it gets a char and a newline, instead of a number.

    So some tricks to stop it:

    1) With char entry using scanf() put a space before the % format specifier:
    scanf(" %c", &myCharVariable); //note the space before the %

    2) With char entry before a number entry, you can add this:

    getchar(); //eats up one newline, without stopping your program

    Put it right after the scanf() for the char.

    Use those two tricks and you should be fine - but there are more, and more industrial strength tools for doing this, as well (like deleting ALL the input from the input buffer), but this is probably all you'll need.
  5. In Topic: Animation and movement question for my game.

    Posted 23 Mar 2013

    Don't you think you got a LITTLE carried away with your development?

    Get one function's basics working correctly, before you get working on the next function. Testing each, as you go. You'll have to back up now, by REM'ing out /* */ sections of code to find this error. The good thing is it probably won't take as long as it seems, and you probably won't make this rookie move, anytime soon.

    No one knows your code as well as you do, and I don't think anyone can look at your code (cold), without running it, and clearly see the details here. Your time to practice debugging code, has arrived, imo. Borland has a good debugger, and remember, the bugs can maybe run, but they can't hide!

    Good luck, and remember not to develop your programs like this.

My Information

Member Title:
D.I.C Addict
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Interests:
Computer chess, learning Go!, distributed computing projects.
Years Programming:
17
Programming Languages:
C

Contact Information

E-mail:
Private

Comments

Page 1 of 1
  1. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:52
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  2. Photo

    raghav.naganathan Icon

    07 Dec 2012 - 01:42
    144...Congrats on the perfect square :)
  3. Photo

    snoopy11 Icon

    29 Nov 2011 - 12:42
    Wow nice job with the for - loops
    Adak...
    That was so elegant...
  4. Photo

    assert(C) Icon

    01 Aug 2011 - 05:25
    THANKS FOR THE HELP
Page 1 of 1