Showing posts with label Mac Dev. Show all posts
Showing posts with label Mac Dev. Show all posts

Friday, November 26, 2010

Slowly abandoning Apple?

There was a time when I used to say most software I use was Cocoa. Consequently, I did not use cross-platform software (a part from CLI stuff). I preferred the OS X only, non portable solution to cross-platform solutions every time the OS X provided a niftier integration with the system.

I was rather shocked considering that it is no longer true. First: I mostly work with non Apple systems (that is to say Windows and Linux). This is not really an issue: I was aware that my job could be done without a Mac. Being mostly a developer, I just need the development tools: compilers, open source interpreters, Eclipse, WingIDE, IntelliJ. All this stuff is cross platform. I also use latex (which is also cross platform). Unfortunately I use Word and the wonderful MathType quite often. Well... once I was very skeptical about the pair, long time ago. I changed my mind, of course. Still don't like word, but MathType is wonderful. JEdit and gvim more than TextMate or BBEdit.

I still use OmniGraffle, and I find it wonderful. However, I think that it sucks not being able to use it on my netbook (my apple laptop has a broken hard drive and I haven't fixed it yet). I mostly dropped Papers for Mendeley (cross-platform and I think more useful). My synchronization needs have increased: I use gmail more often than Mail; Dropbox beats the crap out of MobileMe (which I'm not going to renew).

Etc etc etc. In fact the last bundles of Mac software are not interesting from my point of view. I bought some sw some time ago, and I did not use it. Not that the MacOS is not great, beware. Just I feel like I have to be able to leave the platform with no hassle should the need arise. My MacPro is going to last, so is my laptop. But not forever; and then? I even find some things are better outside the mac (e.g., key shortcuts of IDEs... they are not standardized like on the mac, of course, but the ides just don't work at 100% on the mac... perhaps the new versions are improving).

Just happy I bought 1Password for Windows. Now I just have to leave Yojimbo. Still, no time to export the notes... and the serial numbers. I don't even want to think how much I money I threw away. :(

Yeah... of course, if I had more time to play things would be different. I just love Logic (Express) and doing audio on the Mac. Though, I have not enough time.

Powered by ScribeFire.



, , , ,

Friday, November 12, 2010

Java and OS X (good news, afterall)

It looks like my concerns were unjustified. OS X and Oracle (well, mostly the open jdk community) are going to collaborate to provide future versions of Java for OS X.

Apple is basically gives its current Java machine to the OpenJDK project. Oracle (and OpenJDK guys) will provide future versions, as it is desirable. Perhaps we will not have JVM lagging behind anymore. Or perhaps we will, but the lag will be shorter.



, , , ,

Powered by ScribeFire.

Saturday, October 23, 2010

Mac App Store Review Guidelines

Lately, it seems to me that at Apple is doing everything they can to completely annoy developers and geeks. Which is, of course, a very bad premise for a post; as far as I have seen Apple proved to be right against all the odds most of the times. People continuously complain on Apple (and I have never seen a company with so many haters, with the possible exception of Microsoft), though sells grow and the products improve.

In fact Snow Leopard is the best OS they did (and perhaps the best I ever tried). The machines they build are sturdy and elegant at the same time. And the ipad is a wonderful tool .

There are many things that I don't like, though. Perhaps one day I will elaborate on this. At the present, however, I would like to point out the conditions to have an app accepted at the Apple store.

Some are worried that they will become the sole way to distribute software. I am confident it will not. First, the EU already questioned whether it was acceptable to do that on the iphone/ipad. I am sure that they will seriously avoid having Apple doing that on a PC. Moreover, Apple would lose developers and applications (thinking Adobe and Microsoft and many other commercial companies will comply with those lines is pure madness)... And I even think that it is good to create such an OS.

It means slowly going towards some Raskin's ideas (he also opposed the very idea of third party applications). Though, it would be an OS completely useless to me. If they do it and they do it right, perhaps it is a good thing. But they won't get my money. Windows 7 is a solid system and Ubuntu gets better with every release: I'm not even sure that they would catch up without Apple going so experimental (they just lack some software).

Back to the rules...

2.1Apps that crash will be rejected

2.2Apps that exhibit bugs will be rejected

Am I reading this for real? Every developer knows that every non trivial piece of software has bugs. We strive to put in fewer bugs and for having the severity of the bugs reduced. But no bugs? Madness. An uncaught exception means that the application is going to crash. As far as I can see, those rules are basically reducing the set of acceptable apps to applications so small that they can be manually proved correct (unfortunately, this basically excludes GUI and concurrent applications).

So I think that those rules are fakes. They don't mean a thing. If they do, I am going to buy some Apple software from the store and ask them to remove it from the store as soon as it manifests a bug. And it will... ah, it will! Apple software is far from perfect: it just has a very careful UI design... ;)

2.7Apps that duplicate apps already in the App Store may be rejected, particularly if there are many of them

Oh, really? So you've got to be fast! Perhaps if the developers publish a bunch of word processors (which, with Cocoa API is quite simple) then Microsoft Office will be rejected. I don't really believe this, but it would be funny. In fact, I'm not even sure that MS is going to put anything on the store.

2.8Apps that are not very useful or do not provide any lasting entertainment value may be rejected

 

What the fuck does it mean? Office does not provide any entertainment value: its a tool. I am not entertained when I work with Word or with Keynote. Dear sirs at Apple... there is people working with your bloody macintosh computers. We are not to be entertained: we don't want to have a funny dog advisor to make the software entertaining.

2.16Apps that download or install additional code or resources to add functionality or change their primary purpose will be rejected

 

At last, they rephrased the sentence on the ipad guidelines. The way it was before basically would rule out a web browser.

2.19Apps that require license keys or implement their own copy protection will be rejected

2.20Apps that present a license screen at launch will be rejected

 

I love those two. I hate developers spending effort on protections. If I like the app, I am going to pay for it. If I don't like it, I'm not gonna use it. There are developers who put on the protections before writing useful functionalities (and sometimes they do sell the betas as well... luckily, the MacStore will at least make this behavior unrealizable).

2.18Apps that install kexts will be rejected

2.23Apps that spawn processes that continue to run after a user has quit the app without user consent will be rejected

7.4Apps containing "rental" content or services that expire after a limited time will be rejected

Ok... here it is obvious other means for installation will remain

2.24Apps that use deprecated or optionally installed technologies (e.g., Java, Rosetta) will be rejected

No Eclipse on the Mac Store... It seems that Python apps will be ok, as Python ships with every mac. At least nowadays.

2.25Apps that do not run on the currently shipping OS will be rejected

 

Oh... so developers... you always have to keep up with the last Apple OS!

 

3.1Apps with metadata that mentions the name of any other computer platform will be rejected

 

Don't know... CommodorEmulator seems to violate the rule.

6.1Apps must comply with all terms and conditions explained in the Apple Macintosh Human

Interface Guidelines

6.4Apple and our customers place a high value on simple, refined, creative, well thought through interfaces. They take more work but are worth it. Apple sets a high bar. If your user interface is complex or less than very good it may be rejected

Ok. Reasonable. Perhaps even possible. A certification "(Good UI)" would be very good: a prohibition to sell is bad.

6.2Apps that look similar to Apple Products or apps bundled on the Mac, including the Finder, iChat, iTunes, and Dashboard, will be rejected

How is this called in english? Abuse of a dominant position? Yeah. If this mac store is ever going to be successful, then Apple will got into troubles. And rightly so.

 

7.6In general, the more expensive your app, the more thoroughly we will review it

LOL. ROTFL. Makes sense, though.

8.3Apps that are simply web clippings, content aggregators, or a collection of links, may be rejected

Actually, no wikipedia app.

9.1Apps that encourage users to use an Apple product in a way that may cause damage to the

device will be rejected

 

LOL.

9.2Apps that rapidly drain a products battery or generate excessive heat will be rejected

So, no scientific computation tools allowed.

11.1Apps portraying realistic images of people or animals being killed or maimed, shot, stabbed, tortured or injured will be rejected

11.3"Enemies" within the context of a game cannot solely target a specific race, culture, a real government or corporation, or any other real entity

Looks like some games will be rejected. E.g., in 2nd war games, it seems you will have to be able to play both sides.

Technorati Tags: , , ,

Friday, October 22, 2010

No more Java for OS X?

As of the release of Java for Mac OS X 10.6 Update 3, the version of Java that is ported by Apple, and that ships with Mac OS X, is deprecated.

This means that the Apple-produced runtime will not be maintained at the same level, and may be removed from future versions of Mac OS X. The Java runtime shipping in Mac OS X 10.6 Snow Leopard, and Mac OS X 10.5 Leopard, will continue to be supported and maintained through the standard support cycles of those products.

Link

Don't really know how to interpret this one.

Screenshot 2010-10-22 01h 47m 54s.png

At the moment Oracle does not offer an OS X Java implementation. What is going to happen?


Technorati Tags:
, ,



Powered by ScribeFire.

Monday, September 29, 2008

CoreData and RAD tools under OS X

I've never been a RAD tool enthusiast. However, I recognize they have their utility. Especially when the "rapid" part comes from a well done library and not from drag and drop mumbo jumbo. Besides, I'm a big fan of drag and drop: I just don't think software should be built with drag and drop. About the "rapid" as in library part, I love Django. I was quite fond of Rails as well, but since Django reached the metaphorical age of consent I just dropped the whole Ruby thing.

Back to Cocoa... I'm mostly an OS X user and I'm quite into OS X development as well. Not that I often write desktop software, but when I do, it's often Cocoa stuff (possibly with Python bindings). And when I received Hillegass book (Cocoa(R) Programming for Mac(R) OS X (3rd Edition) ) I knew it was time to tackle Core Data.

Core Data is a nice technology. There is plenty of examples when you create not-completely-trivial applications only with drag and drop. Which looks good (though I never understood what kind of programming language/framework benchmark is writing a hello world program as most software is not constituted of hello world applications -- and you don't get paid to write hello worlds). Well... the drag and drop thing works as expected: even if you don't know about programming more than what I know about Votic literature, you may surprise your suspenders wearing hacker friends (at least until they ask you how the damn thing works).

Unfortunately enough, everything that is not that trivial (which accounts for most software projects, indeed) needs a bit more attention. The first thing you learn is that you must know the underlying technologies. This seems reasonable enough (after all if you want to work in the IT world you must learn a lot of things -- votic excluded). And when we talk about "learning", we are talking about long term investments. You learn Core Data, KV-coding and Cocoa Bindings and you use them for good. Or at least until Apple screws the whole thing up.

Even though when things become complicated you need to write real code, there is a lot of drag and drop/checkbox checking development done in Interface Builder. Of course you could write that code programmatically, but then you don't qualify for the RAD buzzword thing. The point is that bugs in code are usually signaled with tests, code lints or lawyer dispatches about that blown up nuclear plant you wrote the software for. If you don't write a function, the compiler or the interpreter will complain. If you forget to write part of a function, the software will crash (or the tests will fail, if you are a savvy programmer).

Unfortunately, it is dramatically easy to forget to check checkbox (how many checkboxes would a woodchuck check?) or to fill some textbox in Interface Builder, especially if you have a rather complicated UI with lots of elements (and this accounts for most software you want to sell). Error messages are as cryptic as the Delphi oracle (with no known reference to a nice RAD tool and to the most popular commercial DBMS in the world). Cryptic means that most of the time you have no way to understand which UI element wasn't properly connected and generated the error message, you have to browse the bindings of all the widgets. You probably have to set some debugging option (if so I missed the paragraph where this was explained).

Key Value Validation transcends my understanding. As far as I can see it's dramatically easy to do things wrong and put the system in an inconsistent state. Probably I just did not get the rationale behind it. But... Django seems far easier. Sigh.

Wednesday, March 21, 2007

Emacs and emacsclient (Ruby script to call them both)

I usually call one single emacs server (I've got (server-start) at the very beginning of my .emacs), then connect to it with some emacsclient.

Unfortunately enough emacsclient just quits if there is no active emacs server.

I need a process that tries to run emacsclient: if there is no active server, it runs emacs.Moreover, emacsclient has a -n switch that makes it return ASAP, so the terminal is available for more commands.emacs has not such a switch, but that behaviour is the one I want.

So I decided to write a small ruby script that does just this:
  1. Tries to run emacsclient with the -n option.
  2. If it succeeds, we are done. Otherwise we run Emacs doing some standard posix process manipulation in order to return to the shell as soon as possible.

This is the script:

#!/usr/bin/env ruby

fork do
    exec('emacsclient', '-n', *$*)
end

Process.wait
    if $?.exitstatus != 0
        fork do
        Process.setsid
        Signal.trap('HUP', 'SIG_IGN')
        exec('emacs', *$*) if fork.nil?
        exit!(0)
    end
    
    Process.wait
end

Wednesday, May 17, 2006

Open in iTerm from Finder

Since I've been asked to do it, I wrote the "Open in iTerm" app, that does the very same thing than "Open in Terminal" (except that it uses iTerm instead of Terminal.app)

Actually there could be bugs, but at least on my system I suppose it's not my fault, but rather it is iTerm that crashes a lot (maybe the AppleScript part has not been tested extensively on intel macs).

If you experience problems, let me know.

The script part that accesses iTerm is

tell application "iTerm"

        activate

        set myTerm to (make new terminal)

        tell myTerm

                set mySession to (make new session at the end of sessions)

                tell mySession

                        exec command "/bin/bash"

                        write text "cd \""& myPath &"\""

                end tell

        end tell

end tell

I bundled both apps in the very same package, and you can download it here.

I upgraded this script too with Marco's help.

on run

        tell application "Finder" to try

                set myPath to quoted form of ¬

                        POSIX path of ((target of window 1) as string)

        on error

                set myPath to "~"

        end try

        

        tell application "iTerm"

                activate

                set myTerm to (make new terminal)

                tell myTerm

                        set mySession to (make new session at the end of sessions)

                        tell mySession

                                exec command "/bin/bash"

                                write text "cd "& myPath

                        end tell

                end tell

        end tell

end run

Definitive?

After some discussion on icm and the help of tv and Marco (thank you guys) we came to this

on run

tell app "Finder"

try

set myPath to quoted form of ¬

POSIX path of ((target of window 1) as string)

on error

set myPath to "~"

end

set esiste to ((count (get ¬

name of every application process ¬

whose creator type is "ITRM")) is not 0)

end

tell app "iTerm"

activate

if esiste then

set myTerm to (make new terminal)

else

set myTerm to the first terminal

end if

tell myTerm

make new session at the end of sessions

tell the last session

exec command "/bin/bash"

write text "cd "& myPath

end

end

end

end

Open in Terminal from Finder

This is a trivial AppleScript
tell application "Finder"
        set targ to target of Finder window 1
        set myPath to POSIX path of (targ as string)
end tell
tell application "Terminal" to do script "cd \""& myPath &"\""
Here you can see a couple of screenshots.
If you want to download the application (with pretty icon) that uses it, you can download it from here.
Edit: Thanks to Marco Balestra for showing me his own script (that does the same thing, but is much cleaner). Now I included his script instead of mine.
on run
        tell application "Finder" to try
                set myPath to quoted form of ¬
                        POSIX path of ((target of window 1) as string)
        on error
                set myPath to "~"
        end try
       
        tell application "Terminal"
                do script "cd "& myPath
                activate
        end tell
end run

Monday, May 1, 2006

Open with BBEdit

This is a tiny Automator Workflow that opens the current Safari document with BBEdit.
Previously I wrote an AppleScript that did the very same job, however the new document was marked as "new", thus when one tried to close it, BBEdit would complain and ask if we wanted to save
tell application "Safari"
        set cur to document 1
        set mySource to source of cur
        set myName to name of cur
end tell
tell application "BBEdit"
        set x to make new text document with properties ¬
                {contents:mySource, name:myName}
        activate
end tell
However if we use the automator action "New BBEdit Document", it offers the possibility to "Set unmodified" (that is to say the new document won't ask if it has to be saved before closing).
I created a two step Automator workflow. The first step is a slightly modified version of the first part of the script. It is a "Run AppleScript action" containing
on run {input, parameters}
        tell application "Safari"
                set cur to document 1
                set mySource to source of cur
                set myName to name of cur
        end tell
        return mySource
end run
The second step is the "New BBEdit Document" action.
You can download the workflow here. I sugest to put it in the script menu.

Saturday, April 8, 2006

Autoconf automake & libtool on MacOS X

I have just finished my first autotools project on the MacOS. Until today I deployed software only in Python or Java. I already worked on C and C++ projects that used libtool and automake and autoconf, but I had not to write the configure scripts myself or I developed them on GNU/Linux.

In fact I'm afraid most of the problems I encountered was MacOS X fault + my ignorance. That is to say libtoolize does not exist: it is called glibtoolize. So if I do not rename it, autoreconf simply does not work.

Probably I just had to set the LIBTOOLIZE environment variable to glibtoolize. However my solution works. The error I got was

Can't exec "libtoolize": No such file or directory at /opt/local/share/autoconf/Autom4te/FileUtils.pm line 288, <GEN3> line 3.

autoreconf: failed to run libtoolize: No such file or directory

Well... I've to fine tune it. I go.

Wednesday, April 5, 2006

Multitasking on MacIntel

I noticed changing the subject also changes the link. So I repost this to redirect you to the new article.

I also have a more recent test that quite leads to other conclusions

Investigated iMac Troubles: not a faulty scheduler but something related to memory

Some time ago I stated multitasking of Mac OS X Intel was bugged. Under some conditions (which at the time I hadn't discovered) the GUI hung (something I never saw on tre MacOS before) and all the system slowed down terribly.

Computations

I anticipate here: the problem I found is real. MacIntel seem to have problems when large quantities of RAM are allocated. It is not a problem with the scheduler. In fact the system simply slows down as a whole.
The fist thing I did was to write a simple program trat stressed CPU and made a lot of I/O and at tre same time allocated and deallocated small quantities of memory in a quite inefficient way. However tre system was not slowed in any perceptible manner.

this is tre post where I spoke about trat program.

Here I add some benchmarking. Now I have to describe tre machines involved. Of course tris not a PPC vs. Intel bench. Unfortunately tre most powerful PPC machine is a notebook, and we can't expect to compete with the iMac. What I want to show are tre relative values between them.

Machines


Model

CPU

Clock

RAM

Bus

Hard Disk

PowerBook G4

G4 (Single Core)

1.5 GHz

512 MB

167 MHz

5400 rpm

iMac CoreDuo

Intel CoreDuo

2.0 GHz

1.5 GB

667 MHz

7200 rpm


big_matrix

This the test I described here
I compiled the test with no optimizations. This is probably a mistake.
The full test on the iMac took more than twenty minutes (matrix 500x500). The Mac was usable and had no slowdowns:
time ./big_matrix  
real    20m39.110s 
user    12m10.943s 
sys     7m46.112s 

Reducing the matrix size to 100x100 with no optimization the result is
time ./big_matrix 
real    0m9.683s 
user    0m5.805s 
sys     0m3.688s 

Compiling with the -fast option did not change things much, nor did -O3 or -Os (as I said the code was intended to be quite inefficient, I'm not surprised compilers weren't really able to optimize). However explicitly activating -mmmx-msse-msse2-msse3 gave a little improvement (about 5%, that could even be a statistical variation).

As I said before the most important thing is however achieved: the mac remains perfectly usable.

For those who are interested in this sort of things, the powerbook took about an hour and an half. However optimizations improved speed by a full 10% (which is quite acceptable, indeed). However I'm sad it performed so badly. I should investigate why altivec did not work properly (If it did, I suppose it should do something more that 4 times and more slower than the Intel).

Keep in mind that my software wasn't designed to work on multiple threads (This could be an interesting addition, thought). However the system kept on swapping it between the two cores, avoiding many possible optimizations.

Wonderings...

Now only very large allocations remained to do. So I wrote this small (idiotic) software.

Basically it takes a filename as a command line argument, finds out the dimension of the file with a stat syscall, allocates enough space to hold it and then fills the buffer. If the file is big enough this (a part from being terribly inefficient) allocates a lot of RAM.
I called it on a 985 MB file (that means the software allocated 900 MB of real memory, since it is not only allocated, but filled too).

$ ls -lh ../../Desktop/Ubuntu_510.vpc7.sit  
-rw-r--r--   1 riko  staff        985M 12 Feb 03:13 ../../Desktop/Ubuntu_510.vpc7.sit 

The file is loaded correctly and this is the time bench.

$ time ./load_file ../../Desktop/Ubuntu_510.vpc7.sit  
real    3m31.010s 
user    0m0.001s 
sys     0m4.062s 

This value is really variable. Another time it took only 1m42s.
And... the Mac slowed down. I know that such a program is idiotic. However it was one of the quickest way to understand how behaves the iMac when someone needs a lot of RAM (this could be a memory leak, for example).
In fact in some cases the mac remains slowed down for a while, until RAM is truly released and other processes are paged in.

#include  
#include  
#include  
#include  
#include  
#include  
#define BUFFER 2<<22 

int main(int argc, char *argv[]){ 
    char *mem; 
    int fd; 
    size_t pos = 0, res=0; 
    off_t sz; 
    struct stat st; 
    stat(argv[1], &st); 
    sz = st.st_size; 
    
    mem = (char*)malloc(sz); 
    fd = open(argv[1], O_RDONLY, 0); 
    
    while( (res = read(fd, mem + pos, BUFFER) ) != 0){ 
        pos+=res; 
    } 
    
    close(fd); 
    free(mem); 
    return 0; 
} 

As you may notice, this makes no check on sanity of the buffer allocated by malloc. Don't use it on a 4 GB file, it will probably crash.
When I run this very test on the Powerbook I was prepared that the results would have been terrible. In fact the powerbook does not have 1 GB free ram. It does not even have 1 GB RAM. It has only 512 MB. That means that allocating and filling 1 GB relies heavily on paging (and makes a lot of disk accesses to swap in and out pages of memory).Keeping this in mind, the results have been quite good (and more stable, in fact sometimes the iMac performs worse than the pb, that has 1/3 the RAM.). I would like that someone with 1.5 GB or 2 of RAM would try this.

$ time ./load_file ../aks_old/nr.bkp  
real    3m31.526s 
user    0m0.002s 
sys     0m7.728s 

Moreover the file used was slightly bigger. So it took about the double of the time (keeping the best iMac performance) or quite the same time (keeping the worst), but with a very big hardware handicap. Astonishing. This can also be interpreted saying that something slowed down the iMac considerably.
I didn't mention it before. Although slightly slowed, the PowerBook was quite responsive and usable during the test, while the iMac was not.
I/O Only
I rewrote the software above to read the file in a smaller buffer of memory instead of keeping it all in memory. This is the source code:

#include  
#include  
#include  
#include  
#include  
#include  
#define BUFFER 2<<22 
int main(int argc, char *argv[]){ 
        char *mem; 
        int fd; 
        size_t pos = 0, res=0; 
        off_t sz; 
        struct stat st; 
        stat(argv[1], &st); 
        sz = st.st_size; 
        mem = (char*)malloc(BUFFER); 
        fd = open(argv[1], O_RDONLY, 0); 
        while( (res = read(fd, mem, BUFFER) ) != 0); 
        close(fd); 
        free(mem); 
        return 0; 
} 

The speedup is amazing.

$ time ./read_file ../../Desktop/Ubuntu_510.vpc7.sit  
real    0m28.007s 
user    0m0.001s 
sys     0m1.472s 

Some other times I got about 17s. I should investigate this variance. However, the system did not slow down at all and remained perfectly usable. That makes me thing the problem does not concern I/O, but memory.
The powerbook performed like this:

$ time ./read_file ../aks_old/nr.bkp  
real    0m47.194s 
user    0m0.002s 
sys     0m3.833s 

Memory only...

The last step is writing a stupid software that only allocates large chunks of memory. I made it allocate (and release) progressively larger chunks. First of all this demonstrates the issue does not regard memory leaks only.
Applications that allocate big quantities of RAM in large chunks are slowed. You can also see that the mac slows down (and the allocation time increases) the more the block gets bigger.

#include  
#include  
#include  
int main (int argc, const char * argv[]) { 
    unsigned long size = 2; 
    unsigned long i; 
    int *mem; 
    
    while(size * sizeof(int) 0){ 
        mem = (int*) malloc(size * sizeof(int)); 
        if (mem==NULL) break; 
        printf("Allocated %u bytes\n", size * sizeof(int)); 
        for(i=0; i < size; ++i) {
            mem[i]=i; 
        } 
        free(mem); 
        mem=NULL; 
        printf("Deallocated %u bytes\n", size * sizeof(int)); 
        size*=2; 
    } 
    return 0; 
} 
I also wrote a version that only cycles through variables without allocating. It took less than half second to run, so it's not cycling that affects performance in the software. The first time I run it with not so large chunks. The computer remained quite responsive. Then I run it with full chunks. And it was a hell. In the 1 GB allocation the computer was plainly unusable, not to speak about the 2 GB. However the machine was much more usable than in the I/O + memory test.
time ./memory_allocator  
Allocated 2 bytes 
Deallocated 2 bytes 
[SNIP] 
Allocated 536870912 bytes 
Deallocated 536870912 bytes 
real    0m43.940s 
user    0m9.196s 
sys     0m9.137s 
time ./memory_allocator  
Allocated 8 bytes 
Deallocated 8 bytes 
[SNIP] 
Allocated 1073741824 bytes 
Deallocated 1073741824 bytes 
Allocated 2147483648 bytes 
Deallocated 2147483648 bytes 
real    0m36.538s 
user    0m9.181s 
sys     0m8.851s 

Small allocations

At this point I wrote a program that did smaller allocations. You can see that what matters is the quantity of ram allocated. The very same task, when the process has allocated more than 1 GB is significantly slower.
[Starting software] 
utime: 566              stime: 4198 
[Allocated first chunk] 
utime: 20               stime: 30 
[Populated first chunk] 
utime: 117010           stime: 558634 
[Allocated second chunk] 
utime: 27               stime: 50 
[Populated second chunk] 
utime: 132365           stime: 12 
[Allocated third chunk] 
utime: 38               stime: 487 
[Populated third chunk] 
utime: 229719           stime: 10 
[Allocated fourth chunk] 
utime: 22               stime: 41 
[Populated fourth chunk] 
utime: 228182           stime: 880172 
* Freed first chunk. 
* Freed second chunk. 
* Freed third chunk. 
* Freed fourth chunk. 
 
utime: 79               stime: 2 
and the software was:
#include  
#include  
#include  
#include  
#include  
#include  
void puts_rusage(){ 
        struct rusage ru; 
        static struct timeval slast = {0, 0}; 
        struct timeval scurrent; 
        static struct timeval ulast = {0, 0}; 
        struct timeval ucurrent; 
        getrusage(RUSAGE_SELF, &ru); 
        ucurrent = ru.ru_utime; 
        scurrent = ru.ru_stime; 
        printf("utime: %ld\t\tstime: %ld\n",  
                        ucurrent.tv_sec - ulast.tv_sec,  
                        scurrent.tv_sec - slast.tv_sec 
                        ); 
        ulast = ucurrent; 
        slast = scurrent; 
} 
int main (int argc, const char * argv[]) { 
unsigned long size = 2<<26; 
unsigned long i; 
int *mem1; 
int *mem2; 
        int *mem3; 
        int *mem4; 
        puts("[Starting software]"); 
        puts_rusage(); 
mem1 = (int*) malloc(size*sizeof(int)); 
        puts("\n[Allocated first chunk]"); 
        puts_rusage(); 
for(i=0; i 
mem1[i]=i; 
} 
        puts("\n[Populated first chunk]"); 
        puts_rusage(); 
        mem2 = (int*) malloc(size*sizeof(int)); 
        puts("\n[Allocated second chunk]"); 
        puts_rusage(); 
for(i=0; i 
mem2[i]=i; 
} 
        puts("\n[Populated second chunk]"); 
        puts_rusage(); 
mem3 = (int*) malloc(size*sizeof(int)); 
        puts("\n[Allocated third chunk]"); 
        puts_rusage(); 
for(i=0; i 
mem3[i]=i; 
} 
        puts("\n[Populated third chunk]"); 
        puts_rusage(); 
mem4 = (int*) malloc(size*sizeof(int)); 
        puts("\n[Allocated fourth chunk]"); 
        puts_rusage(); 
for(i=0; i 
mem4[i]=i; 
} 
        puts("\n[Populated fourth chunk]"); 
        puts_rusage(); 
free(mem1); 
        puts("\n\n* Freed first chunk."); 
free(mem2); 
        puts("* Freed second chunk."); 
free(mem3); 
        puts("* Freed third chunk."); 
free(mem4); 
        puts("* Freed fourth chunk."); 
        puts_rusage(); 
return 0; 
} 
The last test should be throwing different processes that allocate a quite large chunk of memory and see how they slow the system (if they do -- I suppose if you don't keep them doing something, they will be paged out).

Conclusion

Definitely I think there is something is not in order with the memory management. The scheduler seems ok. The same tests left the PowerBook usable, while the iMac wasn't (however it took significantly less time in almost every task).

Friday, March 31, 2006

Some good news too... (YASP)

Those who do not like seeing high their CPU usage stats when doing things like networking, should consider buying a Mac Intel. However I think this is due to the tremendous raw power of these machines than to changes in how MacOS X deals with networking.
I've always said that to me it is OK if CPU monitoring tools tell that the CPU is doing heavy work even if the system is only downloading something from the net. In fact although CPU values are high, the system is fast as ever, so I wasn't concerned.
Well, on MacIntel you don't even see high CPU usage stats.

Thursday, March 30, 2006

Multitasking on MacIntel fails in presence of bugs

Right at the moment (as you may have learnt from some of my previous posts) I'm working on numerical libraries. I'm developing a (hopefully) efficient version of the aks algorithm to test primality.

I'm not here to describe AKS, nor to describe multitasking or any particular algorithm. It is sufficient to say that they are programs that make extensive use of the CPU.

On my old Powerbook G4 when I run a CPU expensive task the GUI keeps responding. Of course the task uses a lot of CPU: opening a new application takes more time, and so other tasks do. However applications respond as usual. The computer is noy "hung".

This is one of the things I love more of MacOS. The system remains usable even if under heavy stress. This is no longer true. My brand new iMac Core Duo simply becomes unusable. Applications do not respond (they reaction time can be counted in tens of seconds). This is plainly unacceptable. Of course this does not happen normally: it happens only with some software (and buggy software). However the very same program does not create problems on my Powerbook (the machine slows but remains usable).

This makes me think there is something in the scheduler that just does not work as expected and is fooled by some bugs in the software.

I want to make clear that well written software has't this problem. I can run heavy compilations and have the CPU (both cores) 100% and the system is responsive as usual. It gets stuck when something goes wrong.

The software that hung the mac had bugs (it's iper-alpha and I'm still working on it). But while the old MacOS X PPC responded to me relatively quickly (allowing me for example to kill the bugged software), the new MacOS X Intel seems to prefer letting the bugged software finish. The point is that those bug should not slow the system to that point (and in fact the PowerBook wasn't slowed): they were just a couple of memory leaks.

Now I'm trying to develop a software that has the similar behaviour to the one I'm writing (that is to say uses lots of memory, lots of computation and lots of logging -> I/O), to see what of the three things that stresses more the system. Appearently it is memory.

edit: I just wrote a heavy computation/loging software. This has no troubles at all. You can read what does it do here
Anyway sorry for being allarmistic. I'm trying to figure out what the problem is.

Sunday, March 26, 2006

gmp 4.2 on MacIntel

Good news. With gmp 4.2 assembly optimization works. That means that you can get decent performances. For values of decent that are *below* those of an old Prescott and just a bit better than those of a plain Pentium M with the same clock.

The problem is that (for example) you can't run make check. This makes me thing something is broken. However, I can't understand what. However I've been told that "MacIntels" are not supported by gmp-4.2 . So consider twice before buying a MacIntel if you need to work with gmp.

And you can't use c++ too. For some reason there is an error with the generation of an assembly optimization. The answer from the developers has been "gmp-4.2 is not supported on MacIntels" (however I am not really able to consider this a solution to the problem, but unfortunately I'm not skilled enought to fix things by myself).

In fact the second core is not used at all, so this result is quite predictable. Moreover I used shared libraries instead of static ones (for the very good reasons that the guys at apple don't ship the gcc with the static version of libgcc and of crt0.o, so there is no easy way to do it).

In the end I assume MacOS X on Intel is young and probably not as optimized as a FreeBSD (just to name one). These are the results:

iMac 2 GHz 2 GB

***** GMPbench version 0.1 ***** 
Using default CFLAGS = "-O3 -fomit-frame-pointer -I../gmp-4.2" 
Using default CC = "gcc" 
Using default LIBS = "-lgmp -L../gmp-4.2/.libs" 
Using compilation command: gcc -O3 -fomit-frame-pointer -I../gmp-4.2 foo.c -o foo -lgmp -L../gmp-4.2/.libs 
You may want to override CC, CFLAGS, and LIBS 
Using gmp version: 4.2 
Compiling benchmarks 
Running benchmarks 
Category base 
Program multiply 
multiply 128 128 
GMPbench.base.multiply.128,128 result: 9530908 
multiply 512 512 
GMPbench.base.multiply.512,512 result: 1150785 
multiply 8192 8192 
GMPbench.base.multiply.8192,8192 result: 12500 
multiply 131072 131072 
GMPbench.base.multiply.131072,131072 result: 228 
multiply 2097152 2097152 
GMPbench.base.multiply.2097152,2097152 result: 9.62 
GMPbench.base.multiply result: 12463 
Program divide 
divide 8192 32 
GMPbench.base.divide.8192,32 result: 306090 
divide 8192 64 
GMPbench.base.divide.8192,64 result: 104119 
divide 8192 128 
GMPbench.base.divide.8192,128 result: 66800 
divide 8192 4096 
GMPbench.base.divide.8192,4096 result: 20668 
divide 8192 8064 
GMPbench.base.divide.8192,8064 result: 268859 
divide 131072 8192 
GMPbench.base.divide.131072,8192 result: 435 
divide 131072 65536 
GMPbench.base.divide.131072,65536 result: 242 
divide 8388608 4194304 
GMPbench.base.divide.8388608,4194304 result: 0.796 
GMPbench.base.divide result: 5617.3 
GMPbench.base result: 8367.1 
Category app 
Program rsa 
rsa 512 
GMPbench.app.rsa.512 result: 2755 
rsa 1024 
GMPbench.app.rsa.1024 result: 478 
rsa 2048 
GMPbench.app.rsa.2048 result: 72.6 
GMPbench.app.rsa result: 457.26 
GMPbench.app result: 457.26 
GMPbench result: 1956 

gmp on MacIntel and on G4

My iMac should be "twice as fast" as the iMac G5. Ok, that good.
This is true if you use apple software (i suppose they did the test correctly) and if you benchmark with SPEC suites. That's good.And the iMac is fast. I have never used a faster mac (however, I never used a G5 too). Applications open with no need to wait and so on. I can even play 3d games with rosetta.

However right at the moment I have to use gmp. And gmp says that my brand new iMac is not even twice as fast as my "old" PB G4 1.5 GHz. That is a desktop. I know, gmp on Mac Intel uses no assembly code. And the iMac is 1.5 x slower.

But I don't care how much my CPU is fast if the software I have to run is not optimized for it. Today they released gmp 4.2. I'm gonna try it and see if now the assembly issue is fixed.

iMac 2 GHz 2 GB
***** GMPbench version 0.1 ***** 
Using default CFLAGS = "-O3 -fomit-frame-pointer -I/opt/local/include" 
Using default CC = "gcc" 
Using default LIBS = "-lgmp -L/opt/local/lib" 
Using compilation command: gcc -O3 -fomit-frame-pointer -I/opt/local/include foo.c -o foo -lgmp -L/opt/local/lib 
You may want to override CC, CFLAGS, and LIBS 
Using gmp version: 4.1.4 
Compiling benchmarks 
Running benchmarks 
Category base 
Program multiply 
multiply 128 128 
GMPbench.base.multiply.128,128 result: 3388942 
multiply 512 512 
GMPbench.base.multiply.512,512 result: 283065 
multiply 8192 8192 
GMPbench.base.multiply.8192,8192 result: 2753 
multiply 131072 131072 
GMPbench.base.multiply.131072,131072 result: 43.6 
multiply 2097152 2097152 
GMPbench.base.multiply.2097152,2097152 result: 1.73 
GMPbench.base.multiply result: 2883.1 
Program divide 
divide 8192 32 
GMPbench.base.divide.8192,32 result: 116928 
divide 8192 64 
GMPbench.base.divide.8192,64 result: 72789 
divide 8192 128 
GMPbench.base.divide.8192,128 result: 36886 
divide 8192 4096 
GMPbench.base.divide.8192,4096 result: 5076 
divide 8192 8064 
GMPbench.base.divide.8192,8064 result: 66084 
divide 131072 8192 
GMPbench.base.divide.131072,8192 result: 107 
divide 131072 65536 
GMPbench.base.divide.131072,65536 result: 54.0 
divide 8388608 4194304 
GMPbench.base.divide.8388608,4194304 result: 0.159 
GMPbench.base.divide result: 1770.9 
GMPbench.base result: 2259.6 
Category app 
Program rsa 
rsa 512 
GMPbench.app.rsa.512 result: 870 
rsa 1024 
GMPbench.app.rsa.1024 result: 129 
rsa 2048 
GMPbench.app.rsa.2048 result: 18.0 
GMPbench.app.rsa result: 126.41 
GMPbench.app result: 126.41 
GMPbench result: 534.46 

PowerBook G4 1.5 GHz 512 MB
... broken post ...

MacIntel not advised for scientific researchers.

I had problems with almost all scientific libraries I tried.
gmp builds only if you use --host=none-apple-darwin. That means you are disabling assembly optimizations (and you probably wouldn't want to . And that option was correctly set for plain gmp, but not for gmp-cxx-wrappers (Gregory Wrigh has no access to a Mac intel, now he should have fixed it).

cln is plainly broken. That means you can't use GiNaC too. I think someone should buy cln's developers a MacMini Intel.

If you want to use OCaml, you have to use a cvs special version, since the stable does not yet compile. The solution is here.

In fact I had lots of problems. The guys at darwin ports have been really nice (using dp is just the quickest way to install this kind of software), but there are *lots* of troubles. The same installation on my powerbook G4 went just fine (of course the took a lot to finish, but they did finish).

Portfile for ntl on MacIntel was broken too (now it's fixed).

Thursday, March 23, 2006

Install gmp with c++ with Dynamic Libraries.

I have to admit I'm a libtool noob. However I know gcc and g++ 4.0.1 available with MacOS Tiger are able to compile c++ dynamic libraries. In fact this is done with flag -dynamiclib
However, gmp if configured with --enable-cxx and without disabling dyamic libraries fails. In fact it passes g++ the -shared option (that works for linux). If you compile plain gmp with no C++ support, the problem does not exist. I'm afraid it's a bug with gmp libtool (I suppose you could fix it with autoreconf, but I did not try it).
Unfortunately I need c++ support since I have to work with ppl. The solution is to modify all occurrences of "-shared" in the configure file with "-dynamiclib". And appears not to work.
The same hack worked with readline (but I'm afraid that's because readline was written in C and somehow support for C dynamic libraries seems better on mac os x: I'd say "older", so it's more likely developers made it work.
However darwin ports is able to build it the correct way. You only have to specify somewhere that gmp-cxx-wrappers should build with --host=none-apple-darwin